public virtual IHttpActionResult PostContact(Guid id, [FromBody] ContactModelExtended model)
        {
            var customerContact = CustomerContact.CreateInstance();

            CustomerMappings.CreateContact(customerContact, id, model);
            CreateUserIfNotExists(customerContact);
            model = customerContact.ConvertToContactModel();

            return(CreatedAtRoute("GetContact", new { contactId = model.PrimaryKeyId }, model));
        }
        public virtual IHttpActionResult PutContact(Guid id, [FromBody] ContactModelExtended model)
        {
            var existingContact = CustomerContext.Current.GetContactById(id);

            if (existingContact == null)
            {
                return(NotFound());
            }

            if (CreateUserIfNotExists(existingContact))
            {
                existingContact.UserId =
                    "String:" + model
                    .Email;     // The UserId needs to be set in the format "String:{email}". Else a duplicate CustomerContact will be created later on.
            }
            existingContact.FirstName = model.FirstName;
            existingContact.LastName  = model.LastName;
            existingContact.Email     = model.Email;

            existingContact.RegistrationSource = model.RegistrationSource;

            if (model.Addresses != null)
            {
                foreach (var address in model.Addresses)
                {
                    CustomerMappings.CreateOrUpdateCustomerAddress(existingContact, address);
                }
            }

            existingContact.UpdateMetaFields(model,
                                             new List <string> {
                "FirstName", "LastName", "Email", "RegistrationSource"
            });
            existingContact.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }