public IHttpActionResult CreateCustomer(CustomerDTto customerDto) { if (!ModelState.IsValid) { return(BadRequest()); } //throw new HttpResponseException(HttpStatusCode.BadRequest); var customer = Mapper.Map <CustomerDTto, Customer>(customerDto); _context.Customer.Add(customer); _context.SaveChanges(); customerDto.Id = customer.Id; return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customerDto)); //return customerDto; }
public void UpdateCustomer(int id, CustomerDTto customerDTto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var customerInDb = _context.Customer.SingleOrDefault(c => c.Id == id); if (customerInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(customerDTto, customerInDb); /* * customerInDb.Name = customer.Name; * customerInDb.Birthdate = customer.Birthdate; * customerInDb.MembershipTypeId = customer.MembershipTypeId; * customerInDb.IsSubscribedToNews = customer.IsSubscribedToNews; */ _context.SaveChanges(); }