public ActionResult UpdateCustomer(int customerId = 0) { _logger.DebugFormat("Entering UpdateCustomer with customerId: {0}", customerId); var model = new CustomerViewModel(); model.IsPostBack = false; if (customerId > 0) { _logger.InfoFormat("Existing customer with customerId: {0}", customerId); var existingCustomer = _customerService.GetCustomer(customerId); if (existingCustomer == null) { throw new ArgumentNullException("existingCustomer"); } model.BirthDay = existingCustomer.BirthDay.GetValueOrDefault().ToString("dd.MM.yyyy"); model.Customer = existingCustomer; return View(model); } model.Customer = _customerFactory.BuildNewCustomer(); return View(model); }
public ActionResult UpdateCustomer(CustomerViewModel model) { _logger.DebugFormat("UpdateCustomer POST called"); model.IsPostBack = true; DateTime birthdate; var dateParesed = DateTime.TryParse(model.BirthDay, out birthdate); model.Customer.BirthDay = null; if (dateParesed) { model.Customer.BirthDay = DateTime.Parse(model.BirthDay); } if (model.Customer.CustomerId == 0) { model.Customer.CreatedDate = DateTime.Now; } model.UpdateCustomerSuccess = _customerService.UpdateCustomer(model.Customer); return View(model); }