public BuildingSupplierENT SelectSingle(int Id) { NbkDbEntities dbcontext = new NbkDbEntities(); BuildingSupplierTemplate Obj = dbcontext.BuildingSupplierTemplate.Where(x => x.Id == Id).FirstOrDefault(); BuildingSupplierENT Data = new BuildingSupplierENT() { Id = Obj.Id, Title = Obj.Title }; return(Data); }
public BuildingSupplierENT CreateSingle(BuildingSupplierENT Obj) { NbkDbEntities dbcontext = new NbkDbEntities(); BuildingSupplierTemplate Data = new BuildingSupplierTemplate() { Title = Obj.Title }; dbcontext.BuildingSupplierTemplate.Add(Data); dbcontext.SaveChanges(); Obj.Id = Data.Id; return(Obj); }
public BuildingSupplierENT UpdateSelectSingle(BuildingSupplierENT Obj) { NbkDbEntities dbcontext = new NbkDbEntities(); BuildingSupplierTemplate Data = new BuildingSupplierTemplate() { Id = Obj.Id, Title = Obj.Title }; dbcontext.BuildingSupplierTemplate.Attach(Data); var update = dbcontext.Entry(Data); update.Property(x => x.Title).IsModified = true; dbcontext.SaveChanges(); return(Obj); }
public List <ProjectAsociatedWithBuildingSup> DeleteSingle(int Id) { List <ProjectAsociatedWithBuildingSup> Projects = new List <ProjectAsociatedWithBuildingSup>(); NbkDbEntities dbcontext = new NbkDbEntities(); #region Check if it is used in any project already Projects.AddRange(dbcontext.Project.Where(x => x.BuildingSupplierId == Id).Select(x => new ProjectAsociatedWithBuildingSup { Id = x.Id, Title = x.Title }).ToList()); if (Projects != null) { if (Projects.Count > 0) { return(Projects); } } #endregion dbcontext = new NbkDbEntities(); BuildingSupplierTemplate Obj = dbcontext.BuildingSupplierTemplate.Where(x => x.Id == Id).FirstOrDefault(); dbcontext.BuildingSupplierTemplate.Remove(Obj); dbcontext.SaveChanges(); return(Projects); }