public int editByLocation(string id, string name, string no) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Location local = new Location() { LocationId = int.Parse(id), Code = no, Name = name, UpdateBy=1, UpdateDatetime=DateTime.Now }; DbEntityEntry<Location> entry = entities.Entry<Location>(local); entry.State = System.Data.EntityState.Unchanged; entry.Property("Code").IsModified = true; entry.Property("Name").IsModified = true; entry.Property("UpdateBy").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; try { flag=entities.SaveChanges(); } catch (Exception ex) { ex.ToString(); } } return flag; }
public int addLocation(string name, string no) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Location local = new Location() { Code = no, Name = name, CreateDatetime=DateTime.Now, CreateBy=1, Deleted=0, Status=0 }; entities.Location.Add(local); try { flag = entities.SaveChanges(); } catch (Exception ex) { ex.ToString(); } } return flag; }
public int delByLocation(string id) { int flag = 0; using (ChooseDishesEntities entities = new ChooseDishesEntities()) { Location local = new Location() { LocationId = int.Parse(id), Deleted=1, UpdateBy = 1, UpdateDatetime = DateTime.Now }; DbEntityEntry<Location> entry = entities.Entry<Location>(local); entry.State = System.Data.EntityState.Unchanged; entry.Property("Deleted").IsModified = true; entry.Property("UpdateBy").IsModified = true; entry.Property("UpdateDatetime").IsModified = true; try { entities.Configuration.ValidateOnSaveEnabled = false; flag = entities.SaveChanges(); entities.Configuration.ValidateOnSaveEnabled = true; } catch (Exception ex) { ex.ToString(); } } return flag; }