public IEnumerable <TECategoryModel> Get() { List <TECategory> list = db.TECategories.Where(x => x.IsDeleted == false).ToList(); List <TECategoryModel> result = new List <TECategoryModel>(); foreach (var item in list) { TECategoryModel model = new TECategoryModel(); TETransformEntityNModel translator = new TETransformEntityNModel(); model = translator.TransformAtoB(item, model); if (item.Parent.Value > 0) { TECategory cat = db.TECategories.Find(item.Parent.Value); model.ParentCategory = cat; } if (model.ParentCategory == null) { model.ParentCategory = new TECategory(); } result.Add(model); } return(result); }
public TECategoryModel Get(int id) { TECategory item = db.TECategories.Find(id); TECategoryModel model = new TECategoryModel(); TETransformEntityNModel translator = new TETransformEntityNModel(); model = translator.TransformAtoB(item, model); if (item.Parent.Value > 0) { TECategory cat = db.TECategories.Find(item.Parent.Value); model.ParentCategory = cat; } return(model); }
public IEnumerable <TECategory> GetAllParentByCategoryId(int id) { TECategory cat = db.TECategories.Find(id); List <TECategory> lsitOfparent = new List <TECategory>(); lsitOfparent.Add(cat); for (int i = 0; i < lsitOfparent.Count; i++) { TECategory immdiateParent = db.TECategories.Find(lsitOfparent[i].Parent); if (lsitOfparent.Count > 100 || immdiateParent == null) { break; } lsitOfparent.Add(immdiateParent); } return(lsitOfparent); }
public TECategory Post(TECategory value) { TECategory result = value; if (!(value.Uniqueid + "".Length > 0)) { result.CreatedOn = System.DateTime.Now; result.LastModifiedOn = System.DateTime.Now; result = db.TECategories.Add(value); } else { db = new TEHRIS_DevEntities(); db.TECategories.Attach(value); foreach (System.Reflection.PropertyInfo item in result.GetType().GetProperties()) { string propname = item.Name; if (propname.ToLower() == "createdon") { continue; } object propValue = item.GetValue(value); if (propValue != null || Convert.ToString(propValue).Length != 0) { db.Entry(value).Property(propname).IsModified = true; } } value.LastModifiedOn = System.DateTime.Now; db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true; } db.SaveChanges(); return(db.TECategories.Find(value.Uniqueid)); }