public List <CommodityChapters> Search(int?rootId = null, string code = null, string name = null) { using (var context = new Guest19DataContext()) { var query = from chapter in context.CommodityChapters .Where(i => i.Active) select new CommodityChapters(chapter); return(query.ToList()); } }
public CommodityRoots GetById(int?id = null) { using (var context = new Guest19DataContext()) { var query = from root in context.CommodityRoots .Where(i => (id.HasValue ? i.Id == id : true) && (i.Active)) select new CommodityRoots(root); return(query.FirstOrDefault()); } }
public List <CommodityRoots> GetByIdParent(int?rootId = null) { using (var context = new Guest19DataContext()) { var query = from root in context.CommodityRoots .Where(i => (rootId.HasValue ? i.CommodityChapterId == rootId : true) && (i.Active)) select new CommodityRoots(root); return(query.ToList()); } }
public bool Save() { bool saved; try { using (var context = new Guest19DataContext()) { var dbItem = context.CommodityRoots.SingleOrDefault(i => i.Id == this.Id); //update if (dbItem != null) { dbItem.Active = this.Active; dbItem.Code = this.Code; dbItem.CommodityChapterId = this.CommodityChapterId; dbItem.Description = this.Description; dbItem.Name = this.Name; context.SubmitChanges();//update il db saved = true; } //new else { var newDbItem = new Guest19.Database.CommodityRoots(); newDbItem.Active = this.Active; newDbItem.Code = this.Code; newDbItem.CommodityChapterId = this.CommodityChapterId; newDbItem.Description = this.Description; newDbItem.Name = this.Name; context.CommodityRoots.InsertOnSubmit(newDbItem);//insert new records in db context.SubmitChanges(); saved = true; } } } catch (Exception ex) { saved = false; } return(saved); }