Exemplo n.º 1
0
        // POST api/values
        public object Post(CustomerViewModel value)
        {
            //Validate something about your input
            if (value == null)
            {
                throw new ArgumentException();
            }

            using (var crmContext = new CrmContext())
            {
                //Find the record in the DB
                Customer customer = crmContext.Customers.Find(value.CustomerId);

                if (customer != null)
                {
                    //Update the record
                    value.ApplyToCustomer(customer);

                    //Save the crmContext back
                    crmContext.SaveChanges();

                    return(new
                    {
                        Success = true,
                        ViewModel = new CustomerViewModel(customer)
                    });
                }
            }

            return(new
            {
                Success = false
            });
        }