// POST: api/customers public IHttpActionResult PostCustomer(CustomerDTO.WithRelations customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } customer = _customerService.Create(customer); return(CreatedAtRoute("DefaultApi", new { id = customer.Id }, customer)); }
public CustomerDTO.WithRelations Create(CustomerDTO.WithRelations customer) { var dbCustomer = new Domain.Customer.Customer(customer); customer.Phones.ForEach(cp => dbCustomer.Phones.Add(new CustomerPhone(cp))); customer.Emails.ForEach(ce => dbCustomer.Emails.Add(new CustomerEmail(ce))); _customerRepository.Add(dbCustomer); _unitOfWork.Commit(); return(_mapper.Map <CustomerDTO.WithRelations>(dbCustomer)); }
public void Update(CustomerDTO.WithRelations customer) { var dbCustomer = _customerRepository.GetById(customer.Id); if (dbCustomer == null) { throw new UpdateEntityException("Customer"); } dbCustomer.SetFields(customer); _customerRepository.Update(dbCustomer); _unitOfWork.Commit(); }
// PUT: api/customers/5 public IHttpActionResult PutCustomer(int id, CustomerDTO.WithRelations customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.Id) { return(BadRequest()); } _customerService.Update(customer); return(StatusCode(HttpStatusCode.NoContent)); }