public void UpdateBaselineProjection(CustomBaselineProjection bp)
        {
            using (var ctx = new XrmServiceContext("Xrm"))
            {
                var bps = (from s in ctx.new_baselineprojectionsSet
                            where s.Id == bp.Id
                            select s).FirstOrDefault();
                bps.new_name = bp.Name;

                bps.new_Year = bp.Year;
                bps.new_CA_Q1Actual = (int)bp.CA_Q1_A;
                bps.new_Q1_ca = (decimal)bp.CA_Q1_P;
                bps.new_CA_Q2Actual = (int)bp.CA_Q2_A;
                bps.new_Q2_ca = (decimal)bp.CA_Q2_P;
                bps.new_CA_Q3Actual = (int)bp.CA_Q3_A;
                bps.new_Q3_ca = (decimal)bp.CA_Q3_P;
                bps.new_CA_Q4Actual = (int)bp.CA_Q4_A;
                bps.new_Q4_ca = (decimal)bp.CA_Q4_P;

                bps.new_DB_Q1Actual = (int)bp.DB_Q1_A;
                bps.new_Q1_db = (decimal)bp.DB_Q1_P;
                bps.new_DB_Q2Actual = (int)bp.DB_Q2_A;
                bps.new_Q2_db = (decimal)bp.DB_Q2_P;
                bps.new_DB_Q3Actual = (int)bp.DB_Q3_A;
                bps.new_Q3_db = (decimal)bp.DB_Q3_P;
                bps.new_DB_Q4Actual = (int)bp.DB_Q4_A;
                bps.new_Q4_db = (decimal)bp.DB_Q4_P;

                ctx.UpdateObject(bps);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 2
0
		static void Main(string[] args)
		{
			var xrm = new XrmServiceContext("Xrm");
			
			WriteExampleContacts(xrm);

			//create a new contact called Allison Brown
			var allisonBrown = new Xrm.Contact
			{
				FirstName = "Allison",
				LastName = "Brown",
				Address1_Line1 = "23 Market St.",
				Address1_City = "Sammamish",
				Address1_StateOrProvince = "MT",
				Address1_PostalCode = "99999",
				Telephone1 = "12345678",
				EMailAddress1 = "*****@*****.**"
			};

			xrm.AddObject(allisonBrown);
			xrm.SaveChanges();

			WriteExampleContacts(xrm);

			Console.WriteLine("Press any key to exit.");
			Console.ReadKey();
		}
        public void When_calling_context_add_and_save_changes_entity_is_added_to_the_faked_context()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            using(var ctx = new XrmServiceContext(service))
            {
                ctx.AddObject(new Account() { Name = "Test account" });
                ctx.SaveChanges();

                var account = ctx.CreateQuery<Account>()
                            .ToList()
                            .FirstOrDefault();

                Assert.Equal("Test account", account.Name);
            }
        }
Ejemplo n.º 4
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            XrmServiceContext xrm;

            xrm = new XrmServiceContext("Xrm");

            foreach (MyLead objLead in Leads)
            {
                //xrm.AddObject(objLead);
                Guid objLeadGuid = xrm.Create(objLead);//Using this method as opposed to xrm.AddObject results in getting the GUID required to add a note to the lead.
                                                        //This method also adds the Lead Object to the Db.
                objLead.Note.ObjectId = new Microsoft.Xrm.Client.CrmEntityReference("lead", objLeadGuid); //Creates the xref between the Annotation object (the note) and the lead
                xrm.AddObject(objLead.Note); //adds the note to the CRM Database..
            }

            xrm.SaveChanges();//this saves all the notes to the database.  The leads are automatically saved by calling the Create() method...
        }
        public void When_calling_context_add_addrelated_and_save_changes_entities_are_added_to_the_faked_context()
        {
            var context = new XrmFakedContext();

            var relationship = new XrmFakedRelationship()
            {
                IntersectEntity = "accountleads",
                Entity1Attribute = "accountid",
                Entity2Attribute = "leadid",
                Entity1LogicalName = "account",
                Entity2LogicalName = "lead"
            };
            context.AddRelationship("accountleads", relationship);

            var service = context.GetFakedOrganizationService();

            using (var ctx = new XrmServiceContext(service))
            {
                var account = new Account() { Name = "Test account" };
                ctx.AddObject(account);

                var contact = new Lead() { FirstName = "Jane", LastName = "Doe" };
                ctx.AddRelatedObject(account, new Relationship("accountleads"), contact);
                var result = ctx.SaveChanges();

                var resultaccount = ctx.CreateQuery<Account>()
                                       .ToList()
                                       .FirstOrDefault();

                Assert.NotNull(resultaccount);
                Assert.Equal("Test account", resultaccount.Name);

                var reaultlead = ctx.CreateQuery<Lead>()
                                    .ToList()
                                    .FirstOrDefault();

                Assert.NotNull(reaultlead);
                Assert.Equal("Jane", reaultlead.FirstName);
                Assert.Equal("Doe", reaultlead.LastName);

                var relationshipRecords = ctx.CreateQuery("accountleads")
                                             .ToList();
                Assert.NotEmpty(relationshipRecords);
            }
        }
Ejemplo n.º 6
0
 public void AddSubscribers(string ListId, List <Entities.Subscriber> subscribers)
 {
     try
     {
         foreach (Entities.Subscriber subscriber in subscribers)
         {
             Contact contact  = (Contact)context.ContactSet.Where(x => x.EMailAddress1.Equals(subscriber.E_mail)).FirstOrDefault();
             Guid    listGuid = new Guid(ListId);
             if (contact == null)
             {
                 Guid contactGuid = context.Create(new Contact()
                 {
                     EMailAddress1 = subscriber.E_mail, FirstName = subscriber.Name
                 });
                 var member = new AddMemberListRequest()
                 {
                     EntityId = contactGuid, ListId = listGuid
                 };
                 context.Execute(member);
             }
             else
             {
                 var member = new AddMemberListRequest()
                 {
                     EntityId = contact.Id, ListId = listGuid
                 };
                 context.Execute(member);
             }
         }
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw new Exception("Get subscribers CRM (" + e.Message.ToString() + ")");
     }
 }
        public Account UpdateStudentDetails(string studentId, DetailsViewModel model)
        {
            try
            {
                //Check if studentId is null
                if (string.IsNullOrWhiteSpace(studentId))
                {
                    _log.Error($"Trying to execute update student details for non existing student id");
                    return(null);
                }

                using (var context = new XrmServiceContext(_service))
                {
                    _log.Info($"Executing update student details for student with id {studentId}");
                    var studentObject = (from student in context.AccountSet
                                         where student.New_UserID.Equals(studentId)
                                         select student)
                                        .FirstOrDefault();

                    if (studentObject == null)
                    {
                        _log.Info($"No student found with id {studentId}");
                        return(null);
                    }

                    if (studentObject.New_FirstName != model.FirstName || studentObject.New_FamilyName != model.LastName ||
                        studentObject.New_StudentStatus.Value != (int)model.StudentStatus)
                    {
                        if (studentObject.New_FirstName != model.FirstName)
                        {
                            string oldFirstName = studentObject.New_FirstName;
                            studentObject.New_FirstName = model.FirstName;
                            _log.Info($"Updated the first name for student with ID {studentId} from {oldFirstName} to {model.FirstName}");
                        }

                        if (studentObject.New_FamilyName != model.LastName)
                        {
                            string oldLastName = studentObject.New_FamilyName;
                            studentObject.New_FamilyName = model.LastName;
                            _log.Info($"Updated the last name for student with ID {studentId} from {oldLastName} to {model.LastName} ");
                        }

                        if (studentObject.New_StudentStatus.Value != (int)model.StudentStatus)
                        {
                            int oldStudentStatus = studentObject.New_StudentStatus.Value;
                            studentObject.New_StudentStatus = new OptionSetValue((int)model.StudentStatus);
                            _log.Info($"Updated the student status for student with ID {studentId} from {(StudentStatus)oldStudentStatus} to {model.StudentStatus} ");
                        }

                        context.UpdateObject(studentObject);
                        context.SaveChanges();
                    }
                    else
                    {
                        _log.Info($"The new entered values are equal to the old ones");
                    }

                    return(studentObject);
                }
            }
            catch (Exception ex)
            {
                _log.Error($"Exception caught while trying to update Student Details for Student with ID {studentId} - {ex.Message}");
                return(null);
            }
        }
        public void When_calling_context_add_and_save_changes_returns_correct_result()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            using (var ctx = new XrmServiceContext(service))
            {
                ctx.AddObject(new Account() { Name = "Test account" });
                var result = ctx.SaveChanges();

                Assert.NotNull(result);
                Assert.NotEmpty(result);
                Assert.Equal("Create", result.First().Response.ResponseName);
                Assert.IsType<CreateResponse>(result.First().Response);
                Assert.NotEqual(Guid.Empty, ((CreateResponse)result.First().Response).id);
            }
        }
Ejemplo n.º 9
0
        static private void addContact()
        {
            var xrm = new XrmServiceContext("Xrm");

            listContacts(xrm);
            //Create a new contact called Allison Brown.
            var allisonBrown = new Xrm.Contact
            {
                FirstName = "Allison",
                LastName = "Brown 2",
                Address1_Line1 = "23 Market St.",
                Address1_City = "Sammamish",
                Address1_StateOrProvince = "MT",
                Address1_PostalCode = "99999",
                Telephone1 = "12345678",
                EMailAddress1 = "*****@*****.**"
            };

            xrm.AddObject(allisonBrown);
            xrm.SaveChanges();

            listContacts(xrm);

        }