public void Update(Customer cust) { Customer exist = CustomerRepository.GetById(cust.id); if (exist.Email != cust.Email) FailIfExistEmail(cust); if(exist.KTPNo != cust.KTPNo) FailIfExistKTPNo(cust); Customer custUpdated = new Customer { id = exist.id, BranchId = exist.BranchId, Address = cust.Address, City = cust.City, Email = cust.Email, Name = cust.Name, Outstanding = exist.Outstanding, Phone = cust.Phone, Status = exist.Status, Region = cust.Region, KTPNo = cust.KTPNo, KTPDate = cust.KTPDate, KTPPublisher = cust.KTPPublisher, Job = cust.Job, Gender = cust.Gender, Birthday = cust.Birthday }; ReportingRepository.Update<Customer>(custUpdated, new { id = custUpdated.id }); }
public JsonResult Customer(Customer cust) { try { CompanyProfile cp = new CompanyProfile(this.HttpContext); cust.id = Guid.NewGuid(); cust.BranchId = cp.BranchId; CustomerService.Create(cust); return Json(new { error = false, data = cust }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return Json(new { error = true, message = ex.Message }, JsonRequestBehavior.AllowGet); } }
public JsonResult UpdateCustomer(Customer cust) { try { CompanyProfile cp = new CompanyProfile(this.HttpContext); CustomerService.Update(cust); return Json(new { error = false, data = cust }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return Json(new { error = true, message = ex.Message }, JsonRequestBehavior.AllowGet); } }
private void FailIfExistKTPNo(Customer cust) { if (CustomerRepository.GetByKTPNo(cust.KTPNo, cust.BranchId) != null) throw new Exception(string.Format("Pelanggan dengan Nomor KTP {0} telah terdaftar di perusahaan anda", cust.KTPNo)); }
private void FailIfExistEmail(Customer cust) { if (cust.Email != null && CustomerRepository.GetByEmail(cust.Email, cust.BranchId) != null) throw new Exception(string.Format("Email {0} telah terdaftar di perusahaan anda", cust.Email)); }
public void Create(Customer cust) { FailIfExistEmail(cust); FailIfExistKTPNo(cust); ReportingRepository.Save<Customer>(cust); }
private Customer SaveCustomer(Customer cust) { Customer c = CustomerRepository.GetByKTPNo(cust.KTPNo, cust.BranchId); if (c == null) { CustomerService.Create(cust); return cust; } return c; }