public static Customer CastToDbo(Customer_Dto customer) { return(new Customer { CustomerId = customer.CustomerId, FirstName = customer.FirstName, IsActive = customer.IsActive, LastName = customer.LastName, MiddleName = customer.MiddleName }); }
public IHttpActionResult CreateCustomer(Customer_Dto customerDto) { if (!ModelState.IsValid) { return(BadRequest()); } var customer = Mapper.Map <Customer_Dto, Customer>(customerDto); _context.Customers.Add(customer); _context.SaveChanges(); customerDto.Id = customer.Id; return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customerDto)); }
public void UpdateCustomer(int id, Customer_Dto customerDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var CustomerInDb = _context.Customers.SingleOrDefault(c => c.Id == id); if (CustomerInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(customerDto, CustomerInDb); _context.SaveChanges(); }