Пример #1
0
        //[ActionName("byid")]
        //[ResponseType(typeof(CustmerViewModel))]
        //public IHttpActionResult GetCustomer(int id)
        //{
        //    var model = GetCustomerModel(id);
        //    if (model == null)
        //        return NotFound();
        //    return Ok(model);
        //    //return Ok(model);
        //}
        // PUT api/Customer/5
        public IHttpActionResult PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != customer.ID)
            {
                return BadRequest();
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public IHttpActionResult PostCustomer(CustmerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var c = model.Customer;
            Customer customer = new Customer
            {
                FirstName = c.FirstName,
                LastName = c.LastName,
                Email = c.Email,
                PhoneNo = c.PhoneNo,
                City = c.City,

            };
            db.Customers.Add(customer);
            foreach (var detail in model.Detail)
            {
                CustomerDetail d = new CustomerDetail
                {
                    Customer = customer,
                    MetaColumnID = detail.FieldID,
                    FieldValue = detail.FieldValue
                };
                db.CustomerDetails.Add(d);
            }
            db.SaveChanges();
            return CreatedAtRoute("DefaultApi", new { id = model.Customer.ID }, model);
        }