public IHttpActionResult CreateCustomer(CustomerDtos customerDtos) { var customer = Mapper.Map <CustomerDtos, Customer>(customerDtos); _context.Customers.Add(customer); _context.SaveChanges(); customerDtos.Id = customer.Id; return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customerDtos)); }
private CustomerDtos FindAllCommand(IRepositoryLocator locator) { var result = new CustomerDtos { Customers = new List <CustomerDto>() }; locator.FindAll <Customer>().ToList() .ForEach(c => result.Customers.Add(Customer_to_Dto(c))); return(result); }
public IHttpActionResult CreateCustomer(CustomerDtos customerDto) { if (!ModelState.IsValid) { return(BadRequest()); } var customer = Mapper.Map <CustomerDtos, Customer>(customerDto); _context.Customers.Add(customer); _context.SaveChanges(); customerDto.Id = customer.Id; return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customerDto)); }
private CustomerDtos FindAllCommand(IRepositoryLocator locator) { var result = new CustomerDtos { Customers = new List <CustomerDto>() }; result.Customers = Mapper.Map <IQueryable <Customer>, List <CustomerDto> >(locator.FindAll <Customer>()); if (result.Customers.Count() == 0) { BusinessNotifier.AddWarning(BusinessWarningEnum.Default, "No customer instances were found"); } return(result); }
public CustomerDtos FindAll() { var customers = Repository.FindAll <Customer>(); var result = new CustomerDtos { Customers = new List <CustomerDto>() }; if (customers.Count() == 0) { return(result); } customers.ToList().ForEach(c => result.Customers.Add(Customer_to_Dto(c))); return(result); }
private CustomerDtos FindAllCommand(IRepositoryLocator locator) { var result = new CustomerDtos { Customers = new List <CustomerDto>() }; locator.FindAll <Customer>().ToList() .ForEach(c => result.Customers.Add(Customer_to_Dto(c))); if (result.Customers.Count() == 0) { Container.RequestContext.Notifier.AddWarning( BusinessWarningEnum.Default, "No customer instances were found"); } return(result); }
public void UpdateCustomer(int id, CustomerDtos customerDtos) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var customerInDb = _context.Customers.FirstOrDefault(c => c.Id == id); if (customerInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(customerDtos, customerInDb); _context.SaveChanges(); }
public void UpdateCustomer(int id, CustomerDtos customerDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadGateway); } var customerInDb = _context.Customers.SingleOrDefault(m => m.ID == id); if (customerInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(customerDto, customerInDb); _context.SaveChanges(); }
public IHttpActionResult UpdateCustomer(int id, CustomerDtos customerDtos) { if (!ModelState.IsValid) { return(BadRequest()); } var customerInDb = _context.Customers.SingleOrDefault(c => c.Id == id); if (customerInDb == null) { return(NotFound()); } Mapper.Map(customerDtos, customerInDb); _context.SaveChanges(); return(Ok()); }
public void UpdateCustomer(int id, CustomerDtos customerDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var customerInDb = _context.Customers.SingleOrDefault(m => m.Id == id); if (customerInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var c = Mapper.Map(customerDto, customerInDb); //we can use a tool like automapper though //customerInDb.Name = customer.Name; //customerInDb.Birthdate = customer.Birthdate; //customerInDb.IsSubscribedToNewsletter = customer.IsSubscribedToNewsletter; //customerInDb.MembershipTypeId = customer.MembershipTypeId; _context.SaveChanges(); }
public IHttpActionResult UpdateCustomer(int id, CustomerDtos customerDtos) { 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(customerDtos, customerInDb); //customerInDb.BalanceInAccount = customerDtos.BalanceInAccount; //customerInDb.Name = customerDtos.Name; //customerInDb.IsSubscribedToNewsLetter = customerDtos.IsSubscribedToNewsLetter; //customerInDb.MembershipTypeId = customerDtos.MembershipTypeId; _Context.SaveChanges(); return(Ok()); }