public static bool Insert(int LocationX, int LocationY, DateTime Date) { try { using (RoundTheCornerEntities rc = new RoundTheCornerEntities()) { PL.TblVendorLocation newRow = new TblVendorLocation() { VendorID = rc.TblVendorLocations.Any() ? rc.TblVendorLocations.Max(v => v.VendorID) + 1 : 1, LocationX = LocationX, LocationY = LocationY, Datetime = Date }; rc.TblVendorLocations.Add(newRow); rc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static bool Update(VendorLocationModel vendorLocation) { try { if (vendorLocation.VendorID != 0) { using (RoundTheCornerEntities rc = new RoundTheCornerEntities()) { TblVendorLocation tblVendorLocation = rc.TblVendorLocations.FirstOrDefault(v => v.VendorID == vendorLocation.VendorID); if (tblVendorLocation != null) { tblVendorLocation.VendorID = vendorLocation.VendorID; tblVendorLocation.LocationX = vendorLocation.LocationX; tblVendorLocation.LocationY = vendorLocation.LocationY; tblVendorLocation.Datetime = vendorLocation.Date; rc.SaveChanges(); return(true); } else { throw new Exception("Vendor was not found"); } } } else { throw new Exception("Must have a valid id"); } } catch (Exception ex) { throw ex; } }