Example #1
0
 public bool SaveChangesProduct(int proId, string name, string catid, string price,
     string importdate, string remain, string descript, CRUDOPTION option = CRUDOPTION.CREATE)
 {
     Product p = null;
     try
     {
         switch (option)
         {
             case CRUDOPTION.CREATE:
                 {
                     p = new Product();
                     p.Name = name;
                     p.Descript = descript;
                     int rm;
                     int pr;
                     int cid;
                     int.TryParse(remain, out rm);
                     int.TryParse(price, out pr);
                     int.TryParse(catid, out cid);
                     p.Price = pr;
                     p.RemainingAmount = rm;
                     p.CatID = cid;
                     DateTime ipd = DateTime.Parse(importdate);
                     p.ImportDate = ipd;
                     this.UnileverEntities.Products.Add(p);
                     break;
                 }
             case CRUDOPTION.UPDATE:
                 {
                     p = this.UnileverEntities.Products.Where(p1 => p1.ID == proId).FirstOrDefault();
                     p.Name = name;
                     p.Descript = descript;
                     int rm;
                     int pr;
                     int cid;
                     int.TryParse(remain, out rm);
                     int.TryParse(price, out pr);
                     int.TryParse(catid, out cid);
                     p.Price = pr;
                     p.RemainingAmount = rm;
                     p.CatID = cid;
                     break;
                 }
             case CRUDOPTION.DELETE:
                 {
                     p = this.UnileverEntities.Products.Where(p1 => p1.ID == proId).FirstOrDefault();
                     this.UnileverEntities.Products.Remove(p);
                     break;
                 }
             default: break;
         }
         this.UnileverEntities.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return true;
 }
Example #2
0
 public bool SaveChangesDistributor(int distribId, string name, string email, string phone, string addr, CRUDOPTION option)
 {
     Distributor dt = null;
     try
     {
         switch (option)
         {
             case CRUDOPTION.CREATE:
                 {
                     dt = new Distributor
                     {
                         Name = name,
                         Email = email,
                         Addr = addr,
                         Phone = phone
                     };
                     this.UnileverEntities.Distributors.Add(dt);
                     break;
                 }
             case CRUDOPTION.UPDATE:
                 {
                     dt = GetDistributorById(distribId);
                     dt.Name = name;
                     dt.Email = email;
                     dt.Addr = addr;
                     dt.Phone = phone;
                     break;
                 }
             case CRUDOPTION.DELETE:
                 {
                     dt = GetDistributorById(distribId);
                     this.UnileverEntities.Distributors.Remove(dt);
                     break;
                 }
             default: break;
         }
         this.UnileverEntities.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
     return true;
 }