public static webModel.Contact ToWebModel(this coreModel.Contact contact)
        {
            var retVal = new webModel.Contact();
            retVal.InjectFrom(contact);

            if (contact.Phones != null)
                retVal.Phones = contact.Phones;
            if (contact.Emails != null)
                retVal.Emails = contact.Emails;
			if (contact.DynamicProperties != null)
				retVal.DynamicProperties = contact.DynamicProperties;
            if (contact.Notes != null)
                retVal.Notes = contact.Notes.Select(x => x.ToWebModel()).ToList();
            if (contact.Addresses != null)
                retVal.Addresses = contact.Addresses.Select(x => x.ToWebModel()).ToList();

            retVal.Organizations = contact.Organizations;

            return retVal;
        }
Example #2
0
        public void CreateNewContact()
        {
            var controller = GetContactController();
            var contact    = new webModel.Contact
            {
                Id            = "testContact1",
                FullName      = "Vasa2",
                BirthDate     = DateTime.UtcNow,
                Organizations = new[] { "org1" },
                Addresses     = new webModel.Address[]
                {
                    new webModel.Address {
                        Name         = "some name",
                        AddressType  = coreModel.AddressType.Shipping,
                        City         = "london",
                        Phone        = "+68787687",
                        PostalCode   = "22222",
                        CountryCode  = "ENG",
                        CountryName  = "England",
                        Email        = "*****@*****.**",
                        FirstName    = "first name",
                        LastName     = "last name",
                        Line1        = "line 1",
                        Organization = "org1"
                    }
                }.ToList(),
                Notes = new webModel.Note[] { new webModel.Note {
                                                  Title = "1111", Body = "dfsdfs sdf sdf sdf sd"
                                              } },
                Emails = new[] { "*****@*****.**", "*****@*****.**" },
                Phones = new[] { "2322232", "32323232" },
                //DynamicPropertyValues = new[] { new DynamicPropertyObjectValue { Property = new DynamicProperty { Name = "testProp", ValueType = DynamicPropertyValueType.ShortText }, Values = new object[] { "sss" } } }.ToList(),
                DefaultLanguage = "ru"
            };
            var result = controller.CreateContact(contact) as OkNegotiatedContentResult <webModel.Contact>;

            Assert.IsNotNull(result.Content);
        }
        public IHttpActionResult CreateContact(webModel.Contact contact)
        {
            var retVal = _contactService.Create(contact.ToCoreModel());

            return(Ok(retVal.ToWebModel()));
        }
 public IHttpActionResult UpdateContact(webModel.Contact contact)
 {
     _contactService.Update(new coreModel.Contact[] { contact.ToCoreModel() });
     return(StatusCode(HttpStatusCode.NoContent));
 }
		public void CreateNewContact()
		{
			var controller = GetContactController();
			var contact = new webModel.Contact
			{
				 Id = "testContact1",
				 FullName = "Vasa2",
				 BirthDate = DateTime.UtcNow,
				 Organizations = new string[] { "org1" }, 
				 Addresses = new webModel.Address[]
				{
					new webModel.Address {	
					Name = "some name",	 
					AddressType = coreModel.AddressType.Shipping, 
					City = "london",
					Phone = "+68787687",
					PostalCode = "22222",
					CountryCode = "ENG",
					CountryName = "England",
					Email = "*****@*****.**",
					FirstName = "first name",
					LastName = "last name",
					Line1 = "line 1",
					Organization = "org1"
					}
				}.ToList(),
				 Notes = new webModel.Note[] { new webModel.Note { Title = "1111", Body = "dfsdfs sdf sdf sdf sd" } },
				 Emails = new string[] {  "*****@*****.**", "*****@*****.**" },
				 Phones = new string[] {  "2322232", "32323232" },
				 Properties = new webModel.Property[] { new webModel.Property { Name = "testProp", Value = "sss", ValueType = coreModel.PropertyValueType.ShortText } }.ToList(),
				 DefaultLanguage = "ru"
			};
			var result = controller.CreateContact(contact) as OkNegotiatedContentResult<webModel.Contact>;
			Assert.IsNotNull(result.Content);
		}
		public void PartialUpdateContact()
		{
			var controller = GetContactController();
			var contact = new webModel.Contact
			{
				Id = "testContact",
				FullName = "ET"
			};
			
			controller.UpdateContact(contact);

			var result = controller.GetContactById("testContact") as OkNegotiatedContentResult<webModel.Contact>;

			contact = result.Content;
		}