public Customer VDeleteObject(Customer customer, IItemService _itemService, IMaintenanceService _maintenanceService) { VHasMaintenance(customer, _maintenanceService); if (customer.Errors.Any()) { return customer; } VHasItem(customer, _itemService); return customer; }
public Customer VHasMaintenance(Customer customer, IMaintenanceService _maintenanceService) { IList<Maintenance> list = _maintenanceService.GetObjectsByCustomerId(customer.Id); if (list.Any()) { customer.Errors.Add("Maintenance", "Tidak boleh ada yang terasosiakan dengan customer"); } return customer; }
public Customer VHasItem(Customer customer, IItemService _itemService) { IList<Item> list = _itemService.GetObjectsByCustomerId(customer.Id); if (list.Any()) { customer.Errors.Add("Item", "Tidak boleh ada yang terasosiakan dengan customer"); } return customer; }
public Customer CreateObject(string Name, string Address, string PIC, string Contact, string Email) { Customer customer = new Customer { Name = Name, Address = Address, PIC = PIC, Contact = Contact, Email = Email }; return this.CreateObject(customer); }
public string PrintError(Customer obj) { string erroroutput = ""; KeyValuePair<string, string> first = obj.Errors.ElementAt(0); erroroutput += first.Key + "," + first.Value; foreach (KeyValuePair<string, string> pair in obj.Errors.Skip(1)) { erroroutput += Environment.NewLine; erroroutput += pair.Key + "," + pair.Value; } return erroroutput; }
public Customer UpdateObject(Customer customer) { return (customer = _validator.ValidUpdateObject(customer, this) ? _repository.UpdateObject(customer) : customer); }
public Customer SoftDeleteObject(Customer customer, IItemService _itemService, IMaintenanceService _maintenanceService) { return (customer = _validator.ValidDeleteObject(customer, _itemService, _maintenanceService) ? _repository.SoftDeleteObject(customer) : customer); }
public bool IsNameDuplicated(Customer customer) { IQueryable<Customer> customers = _repository.FindAll(x => x.Name == customer.Name && !x.IsDeleted && x.Id != customer.Id); return (customers.Count() > 0 ? true : false); }
public Customer CreateObject(Customer customer) { customer.Errors = new Dictionary<String, String>(); return (_validator.ValidCreateObject(customer, this) ? _repository.CreateObject(customer) : customer); }
public Customer VName(Customer customer, ICustomerService _customerService) { if (String.IsNullOrEmpty(customer.Name) || customer.Name.Trim() == "") { customer.Errors.Add("Name", "Tidak boleh kosong"); } if (_customerService.IsNameDuplicated(customer)) { customer.Errors.Add("Name", "Tidak boleh ada duplikasi"); } return customer; }
public Customer VCreateObject(Customer customer, ICustomerService _customerService) { VName(customer, _customerService); return customer; }
public bool ValidUpdateObject(Customer customer, ICustomerService _customerService) { customer.Errors.Clear(); VUpdateObject(customer, _customerService); return isValid(customer); }
public bool ValidDeleteObject(Customer customer, IItemService _itemService, IMaintenanceService _maintenanceService) { customer.Errors.Clear(); VDeleteObject(customer, _itemService, _maintenanceService); return isValid(customer); }
public bool ValidCreateObject(Customer customer, ICustomerService _customerService) { VCreateObject(customer, _customerService); return isValid(customer); }
public bool isValid(Customer obj) { bool isValid = !obj.Errors.Any(); return isValid; }
/* public static void SaveData(Dictionary<string, string> isi) { Customer Customer = new Customer(); Customer.Name = isi["TxtName"]; Customer.Description = isi["TxtDescription"]; ExtNetModel p = new ExtNetModel(); Customer CustomerNew = p.customerService.CreateObject(Customer); } */ internal static String SaveData(FormCollection isi) { Customer Customer = new Customer(); Customer.Name = isi["TxtName"]; Customer.Address = isi["TxtAddress"]; Customer.PIC = isi["TxtPic"]; Customer.Contact= isi["TxtContact"]; Customer.Email = isi["TxtEmail"]; CustomerModel p = new CustomerModel(); Customer CustomerNew = p.customerService.CreateObject(Customer); String err = (CustomerNew.Errors.Any()) ? p.customerService.GetValidator().PrintError(CustomerNew) : ""; return err; }