Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 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);
     }
 }