Пример #1
0
 internal void DeleteItems(int reference, InfoBoxItemType type, ApplicationDbContext context)
 {
     context.InfoBoxItems
     .Where(x => x.Reference == reference && x.Type == type)
     .Select(x => x)
     .ToList()
     .ForEach(x => context.InfoBoxItems.Remove(x));
 }
Пример #2
0
        internal object UpdateInfoBox(string boxName, int reference, int partition, InfoBoxItemType type, int position)
        {
            using (var context = ApplicationDbContext.Create())
            {
                var item = context.InfoBoxItems
                           .Where(x => x.BoxName == boxName)
                           .Where(x => x.Reference == reference)
                           .Where(x => x.Type == type)
                           .Where(x => x.Partition == partition)
                           .FirstOrDefault();

                var result = InitInfoBoxItemModelForBox(boxName);

                result.Reference = reference;
                result.Type      = type;
                result.Partition = partition;
                result.BoxName   = boxName;

                if (item == null)
                {
                    item = new InfoBoxItem
                    {
                        Reference = reference,
                        Type      = type,
                        Partition = partition,
                        BoxName   = boxName
                    };
                    context.InfoBoxItems.Add(item);

                    var existingItem = context.InfoBoxItems
                                       .Where(x => x.BoxName == boxName)
                                       .Where(x => x.Position == position)
                                       .Where(x => x.Partition == partition)
                                       .FirstOrDefault();
                    if (existingItem != null)
                    {
                        context.InfoBoxItems.Remove(existingItem);
                    }
                }

                // This is the only value we are getting.
                result.Position = position;
                item.Position   = position;

                context.SaveChanges();
                return(result);
            }
        }
Пример #3
0
        private InfoBoxItemModel GetInfoBoxInternl(string boxName, int reference, int partition, InfoBoxItemType type, ApplicationDbContext context)
        {
            var item = context.InfoBoxItems
                       .Where(x => x.BoxName == boxName)
                       .Where(x => x.Reference == reference)
                       .Where(x => x.Type == type)
                       .Where(x => x.Partition == partition)
                       .FirstOrDefault();

            var result = InitInfoBoxItemModelForBox(boxName);

            result.Reference = reference;
            result.Type      = type;
            result.Partition = partition;
            result.BoxName   = boxName;

            if (item == null)
            {
                return(result);
            }

            // This is the only value we are getting.
            result.Position = item.Position;

            return(result);
        }
Пример #4
0
 public InfoBoxItemModel GetInfoBox(string boxName, int reference, int partition, InfoBoxItemType type)
 {
     using (var context = ApplicationDbContext.Create())
     {
         return(GetInfoBoxInternl(boxName, reference, partition, type, context));
     }
 }
Пример #5
0
 public TopInfoBoxItemModel(object item, InfoBoxItemType type)
 {
     Item = item;
     Type = type;
 }