public void UpdateCustomer(CustomerDto customerDto) { repository.ExecuteInDataContext(() => { var customer = repository.GetById(customerDto.CustomerID); mapper.To(customerDto, ref customer); repository.Update(customer); } ); }
public void SaveCustomer(CustomerDto customerDto) { repository.ExecuteInDataContext(() => { var customer = new Customer {CustomerID = customerDto.CustomerID}; mapper.To(customerDto, ref customer); repository.Save(customer); } ); }
public void To(CustomerDto dto, ref Customer customer) { customer.CompanyName = dto.CompanyName; customer.ContactName = dto.ContactName; customer.ContactTitle = dto.ContactTitle; customer.Address = dto.Address; customer.City = dto.City; customer.Region = dto.Region; customer.PostalCode = dto.PostalCode; customer.Country = dto.Country; customer.Phone = dto.Phone; customer.Fax = dto.Fax; }
public ActionResult Create(CustomerDto customerDto) { try { customerDto.Validate(ModelState); if (ModelState.IsValid) { service.SaveCustomer(customerDto); return RedirectToAction("Index"); } return View(customerDto); } catch (Exception e) { ModelState.AddModelError("", e.Message); return View(customerDto); } }
public ActionResult Edit(string id, CustomerDto customerDto) { try { if (id != customerDto.CustomerID) { throw new InvalidOperationException(); } customerDto.Validate(ModelState); if (ModelState.IsValid) { service.UpdateCustomer(customerDto); return RedirectToAction("Index"); } return View(customerDto); } catch (Exception e) { ModelState.AddModelError("", e.Message); return View(customerDto); } }