コード例 #1
0
        public virtual IHttpActionResult PostContact(Guid userId, [FromBody] Contact contact)
        {
            Logger.LogPost("PostContact", Request, new [] { userId.ToString() });

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var customerContact = CustomerContact.CreateInstance();

                CustomerMappings.CreateContact(customerContact, userId, contact);

                contact = customerContact.ConvertToContact();
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }

            return(Ok(contact));
        }
コード例 #2
0
        public virtual IHttpActionResult PutCustomer(Guid contactId, [FromBody] Contact contact)
        {
            Logger.LogPut("PutCustomer", Request, new [] { contactId.ToString() });

            var existingContact = CustomerContext.Current.GetContactById(contactId);

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

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

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

                existingContact.SaveChanges();

                // default address
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }

            return(Ok());
        }