Skip to content

Instantly share code, notes, and snippets.

class Program
{
internal static void ChangeValue(SampleClass instance, string value)
{
instance.Value = value;
}
internal static void ChangeValue(ref SampleClass instance, string value)
{
instance.Value = value;
@gashupl
gashupl / SampleClass.cs
Created January 8, 2019 07:46
Sample class...
public class SampleClass
{
public SampleClass(string value)
{
this.Value = value;
}
public string Value { get; set; }
}
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
//Default OData version is 4.0
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
config.Count().Filter().OrderBy().Expand().Select().MaxTop(500);
modelBuilder.EntitySet("items");
config.MapODataServiceRoute("items", "odata", modelBuilder.GetEdmModel());
}
public class ItemsController : ODataController
{
private readonly IItemsRepository itemsRepository;</code>
public ItemsController(IItemsRepository itemsRepository)
{
this.itemsRepository = itemsRepository;
}
[EnableQuery]
public static Guid ToGuid(int value)
{
byte[] bytes = new byte[16];
BitConverter.GetBytes(value).CopyTo(bytes, 0);
return new Guid(bytes);
}
public void RunImport()
{
List<Subject> subjects = this.unitOfWork.SubjectsRepository.GetAll(); //Getting data from the document db
ImportSubjects(subjects, null); //Import data to Dynamics 365 instance
}
public void ImportSubjects(List<Subject> subjects, Guid? parentSubject)
{
var subjectsToBeImported = subjects.Where<Subject>(s => s.ParentSubject?.Id == parentSubject).ToList<Subject>();
subjectsToBeImported.ForEach(s =>
{
"_id" : LUUID("4d6c1fce-d035-11e7-a82a-000d3a2a3caf"),
"LogicalName" : "subject",
"Attributes" : [
{
"k" : "modifiedby",
"v" : {
"_t" : "EntityReference",
"_id" : LUUID("45bf6873-9e6a-ac4e-af72-dda713ccf2a5"),
"LogicalName" : "systemuser",
public class SubjectsRepository : DocumentDbRepositoryBase, IDocDbSubjectsRepository
{
readonly IMongoCollection<Subject> dataCollection;
public SubjectsRepository(IMongoDatabase documentDb) : base(documentDb)
{
this.dataCollection = documentDb.GetCollection<Subject>("Subject");
}
public List<Subject> GetAll()
{
@gashupl
gashupl / Account.ts
Last active September 19, 2025 17:56
Account.ts
/// <reference path="../XRM/Form/account/Main/Information.d.ts" />
/// <reference path="../common/DataServices.ts" />
module Foo.Dyn365.Account {
export class EventHandlers {
static onLoad(): void {
console.log("onLoad invoked from Account");
let dataService = new Foo.Dyn365.DataServices.OpportunityDataService();
let form = new Form(dataService);
@gashupl
gashupl / Common.ts
Created September 26, 2017 07:24
Common.ts
/// <reference path="../Xrm/Form/account/Main/Information.d.ts" />
module Foo.Dyn365.Common {
declare var Xrm;
export class Form {
constructor() {
}