public int? CreateUpdateCustomer(CustomerViewModel customerViewModel) { Customer customer = null; if (customerViewModel.CustomerId > 0) { customer = _repository.Find<Customer>(x => x.CustomerId == customerViewModel.CustomerId); if (customer == null) return null; customer.Name = customerViewModel.Name; customer.Email = customerViewModel.Email; customer.Address = customerViewModel.Address; customer.ContactNo = customerViewModel.ContactNo; customer.Zip = customerViewModel.Zip; customer.HourlyRate = customerViewModel.HourlyRate; customer.Comments = customerViewModel.Comments; customer.ModifiedBy = customerViewModel.ModifiedBy; customer.ModifiedDate = DateTime.Now; _repository.Modify<Customer>(customer); return customer.CustomerId; } Mapper.CreateMap<CustomerViewModel, Customer>(); customer = Mapper.Map<CustomerViewModel, Customer>(customerViewModel); customer.CreatedDate = DateTime.Now; customer.CreatedBy = customerViewModel.CreatedBy; customer.Active = true; customer.IsDeleted = false; _repository.Insert<Customer>(customer); return customer.CustomerId; }
public ActionResult CreateUpdateCustomer(CustomerViewModel customerViewModel) { ActiveUser activeUser = new JavaScriptSerializer().Deserialize<ActiveUser>(System.Web.HttpContext.Current.User.Identity.Name); customerViewModel.CreatedBy = activeUser.UserId; customerViewModel.ModifiedBy = activeUser.UserId; var result = _customerComponent.CreateUpdateCustomer(customerViewModel); return Json(result, JsonRequestBehavior.AllowGet); }
public ActionResult CreateUpdateCustomerPopup(int id) { var customer = _customerComponent.GetCustomer(id); if (customer == null) customer = new CustomerViewModel(); return PartialView("/Views/Shared/Partials/_Customer.cshtml", customer); }