Ejemplo n.º 1
0
        public static async Task <Guid> CopyEntityAttribute(this CRMWebAPI api, Guid fromEntityID, Guid toEntityID, Guid fromAttributeID, string attributeType, string logicalName)
        {
            var ec = "EntityDefinitions(" + fromEntityID.ToString() + ")/Attributes(" + fromAttributeID + ")";

            if (attributeType == "Boolean")
            {
                ec += "/Microsoft.Dynamics.CRM.BooleanAttributeMetadata?$expand=OptionSet";
            }
            if (attributeType == "Picklist")
            {
                ec += "/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$expand=OptionSet,GlobalOptionSet";
            }

            dynamic fromAttrib = await api.Get(ec, Guid.Empty);

            IDictionary <string, object> fromAttribValues = (IDictionary <string, object>)fromAttrib;

            fromAttribValues.Remove("MetadataId");
            fromAttribValues.Remove("EntityLogicalName");
            if (attributeType == "Boolean")
            {
                fromAttribValues["@odata.type"] = "Microsoft.Dynamics.CRM.BooleanAttributeMetadata";
                fromAttribValues.Remove("*****@*****.**");
                if (fromAttrib.OptionSet != null)
                {
                    IDictionary <string, object> fromOptionSetValues = (IDictionary <string, object>)fromAttrib.OptionSet;
                    fromOptionSetValues.Remove("Name");
                    fromOptionSetValues.Remove("MetadataId");
                    fromOptionSetValues.Remove("MetadataId");
                    fromOptionSetValues["IsCustomOptionSet"] = true;
                }
            }
            if (attributeType == "Picklist")
            {
                fromAttribValues["@odata.type"] = "Microsoft.Dynamics.CRM.PicklistAttributeMetadata";


                if (fromAttrib.OptionSet != null)
                {
                    IDictionary <string, object> fromOptionSetValues = (IDictionary <string, object>)fromAttrib.OptionSet;
                    fromOptionSetValues.Remove("Name");
                    fromOptionSetValues.Remove("MetadataId");
                    fromOptionSetValues.Remove("MetadataId");
                    fromOptionSetValues["IsCustomOptionSet"] = true;
                }
                else
                {
                    fromAttribValues.Remove("OptionSet");
                    fromAttribValues["*****@*****.**"] = "/GlobalOptionSetDefinitions(" + fromAttrib.GlobalOptionSet.MetadataId + ")";
                    fromAttribValues.Remove("*****@*****.**");
                    fromAttribValues.Remove("GlobalOptionSet");
                }
            }
            fromAttrib.LogicalName = logicalName;
            fromAttrib.SchemaName  = logicalName;


            return(await api.Create("EntityDefinitions(" + toEntityID.ToString() + ")/Attributes", fromAttrib));
        }
Ejemplo n.º 2
0
        public static void CreateNewLead(CRMWebAPI api, LeadRegisterForm result)
        {
            Task.Run(async() =>
            {
                dynamic data     = new ExpandoObject();
                data.subject     = $"New Lead Registration Request by {result.Name}";
                data.firstname   = result.Name;
                data.description = $@"New Lead registration request summary:
                                    {Environment.NewLine}Product Requested : {result.Product},
                                    {Environment.NewLine}Accounts Interested In: {result.Accounts},
                                    {Environment.NewLine}Requester's Gender: {result.Gender},
                                    {Environment.NewLine}Customer Name: {result.Name},
                                    {Environment.NewLine}Total Registrations: {result.TotalAttendees},
                                    {Environment.NewLine}Complementary Drink: {result.ComplementoryDrink}";

                var leadGuid = await api.Create("leads", data);
            }).Wait();
        }
Ejemplo n.º 3
0
        public static void CreateTestDrive(TestDriveDetail testDrive, CRMWebAPI api)
        {
            Task.Run(async() =>
            {
                dynamic data     = new ExpandoObject();
                data.subject     = $"Test Drive Request by {testDrive.CustomerName}";
                data.firstname   = testDrive.CustomerName;
                data.description = $@"Test drive request summary:
                                    {Environment.NewLine}Car Make: {testDrive.CarMake},
                                    {Environment.NewLine}Car Model: {testDrive.CarModel},
                                    {Environment.NewLine}Requested Time: {testDrive.RequestedTime},
                                    {Environment.NewLine}Customer Name: {testDrive.CustomerName},
                                    {Environment.NewLine}Phone Number: {testDrive.PhoneNumber}";


                var leadGuid = await api.Create("leads", data);
            });
        }
Ejemplo n.º 4
0
        public void SaveOrders(IEnumerable <Order> orders)
        {
            var accountrepo     = new AccountRepo();
            var convertedOrders = orders.Select <Order, object>((o) =>
            {
                var accountid       = accountrepo.GetAccountIdByExternalIdAsync(o.UserId).Result;
                dynamic order       = new ExpandoObject();
                order.name          = "web order";
                order.order_details = o.OrderRows.Select((row) =>
                {
                    return(new
                    {
                        productdescription = row.ProductName,
                        quantity = row.Count,
                        priceperunit = row.PricePerUnit,
                        extendedamount = row.Count * row.PricePerUnit
                    });
                });

                if (accountid != Guid.Empty)
                {
                    var orderIndexer = order as IDictionary <string, Object>;
                    orderIndexer["*****@*****.**"] = "/accounts(" + accountid + ")";
                }
                else
                {
                    order.customerid_account = new
                    {
                        name           = o.UserFullName,
                        emailaddress1  = o.UserEmail,
                        stq_externalid = o.UserId
                    };
                }

                return(order);
            });

            foreach (var order in convertedOrders)
            {
                var orderid = _api.Create("salesorders", order).Result;
            }
        }