Beispiel #1
0
 public Customer VDeleteObject(Customer customer, IItemService _itemService, IMaintenanceService _maintenanceService)
 {
     VHasMaintenance(customer, _maintenanceService);
     if (customer.Errors.Any()) { return customer; }
     VHasItem(customer, _itemService);
     return customer;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 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;
 }
Beispiel #6
0
 public Customer UpdateObject(Customer customer)
 {
     return (customer = _validator.ValidUpdateObject(customer, this) ? _repository.UpdateObject(customer) : customer);
 }
Beispiel #7
0
 public Customer SoftDeleteObject(Customer customer, IItemService _itemService, IMaintenanceService _maintenanceService)
 {
     return (customer = _validator.ValidDeleteObject(customer, _itemService, _maintenanceService) ? _repository.SoftDeleteObject(customer) : customer);
 }
Beispiel #8
0
 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);
 }
Beispiel #9
0
 public Customer CreateObject(Customer customer)
 {
     customer.Errors = new Dictionary<String, String>();
     return (_validator.ValidCreateObject(customer, this) ? _repository.CreateObject(customer) : customer);
 }
Beispiel #10
0
 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;
 }
Beispiel #11
0
 public Customer VCreateObject(Customer customer, ICustomerService _customerService)
 {
     VName(customer, _customerService);
     return customer;
 }
Beispiel #12
0
 public bool ValidUpdateObject(Customer customer, ICustomerService _customerService)
 {
     customer.Errors.Clear();
     VUpdateObject(customer, _customerService);
     return isValid(customer);
 }
Beispiel #13
0
 public bool ValidDeleteObject(Customer customer, IItemService _itemService, IMaintenanceService _maintenanceService)
 {
     customer.Errors.Clear();
     VDeleteObject(customer, _itemService, _maintenanceService);
     return isValid(customer);
 }
Beispiel #14
0
 public bool ValidCreateObject(Customer customer, ICustomerService _customerService)
 {
     VCreateObject(customer, _customerService);
     return isValid(customer);
 }
Beispiel #15
0
 public bool isValid(Customer obj)
 {
     bool isValid = !obj.Errors.Any();
     return isValid;
 }
Beispiel #16
0
        /*
        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;
        }