public IItemModel GetItem(int itemId, int moduleId) { IItemModel itembyId = null; using (ItemEntities context = ItemEntities.Instance()) { itembyId = context.Items .Where(x => x.ItemId == itemId) .FirstOrDefault(); } return(itembyId); }
public void CreateItem(IItemModel t) { try { using (ItemEntities context = ItemEntities.Instance()) { context.AddToItems((Item)t); context.SaveChanges(); DataCache.RemoveCache(itemCacheKey(t.ModuleId)); } } catch (Exception ex) { Exceptions.LogException(ex); } }
public void DeleteItem(int itemId, int moduleId) { try { using (ItemEntities context = ItemEntities.Instance()) { var delItem = GetItem(itemId, false, context); context.DeleteObject(delItem); context.SaveChanges(); DataCache.RemoveCache(itemCacheKey(moduleId)); } } catch (Exception ex) { Exceptions.LogException(ex); } }
public Item GetItem(int itemId, bool detach, ItemEntities context) { if (context == null) { context = ItemEntities.Instance(); } Item itembyId = null; itembyId = context.Items .Where(x => x.ItemId == itemId) .FirstOrDefault(); if (detach) { context.Detach(itembyId); } return(itembyId); }
public IEnumerable <IItemModel> GetItems(int moduleId) { List <IItemModel> items = null; try { items = (List <IItemModel>)DataCache.GetCache(itemCacheKey(moduleId)); if (items == null || items.Count == 0) { using (ItemEntities context = ItemEntities.Instance()) { var itemData = (from x in context.Items where x.ModuleId == moduleId select x).ToList(); items = new List <IItemModel>(itemData.Cast <IItemModel>()); } DataCache.SetCache(itemCacheKey(moduleId), items); } } catch (Exception ex) { Exceptions.LogException(ex); } return(items); }
public void UpdateItem(IItemModel t) { try { using (ItemEntities context = ItemEntities.Instance()) { System.Data.EntityKey pKey = ((Item)t).EntityKey; if (pKey != null) { object pObject; if (context.TryGetObjectByKey(pKey, out pObject)) { context.ApplyPropertyChanges(pKey.EntitySetName, (Item)t); } } context.SaveChanges(); } DataCache.RemoveCache(itemCacheKey(t.ModuleId)); } catch (Exception ex) { Exceptions.LogException(ex); } }