Пример #1
0
 public static int AddUpdateCustomer(Customer ob)
 {
     int customerid = 0;
     using (ABBEntities db = new ABBEntities())
     {
         if (ob.CustomerID>0)
         {
             Customer checkifexist = db.Customers.Where(u => u.CustomerID == ob.CustomerID).FirstOrDefault();
             if (checkifexist != null)
             {
                 checkifexist.CustomerID = ob.CustomerID;
                 checkifexist.CustomerFirstName = ob.CustomerFirstName;
                 checkifexist.CustomerLastName = ob.CustomerLastName;                      
                 checkifexist.PhoneNumber = ob.PhoneNumber;
                 checkifexist.Address = ob.Address;
                 checkifexist.City = ob.City;
                 checkifexist.St = ob.St;
                 checkifexist.Zip = ob.Zip;
                 checkifexist.Country = ob.Country;
              }
         }
         else
         {
             db.Customers.Add(ob);
         }
         int saved = db.SaveChanges();
         if(saved > 0)
         {
             customerid = ob.CustomerID;
         }
     }
     return customerid;
 }
Пример #2
0
 public static int AddUpDateItem(Item ob)
 {
     int itemid = 0;
     using (ABBEntities db = new ABBEntities())
     {
         if (ob.ItemId > 0)
         {
             Item ExistingItem = db.Items.Where(u => u.ItemId == ob.ItemId).FirstOrDefault();
             if (ExistingItem != null)
             {
                 ExistingItem.CategoryId = ob.CategoryId;
                 ExistingItem.ItemName = ob.ItemName;
                 ExistingItem.ItemId = ob.ItemId;
             }
         }
         else
         {
             db.Items.Add(ob);
         }
         int saved = db.SaveChanges();
         if (saved > 0)
         {
             itemid = ob.ItemId;
         }
         return itemid;
     }
 }