Ejemplo n.º 1
0
        // Get Categories of a List by ListId
        public static List <CategoryDisplay> GetCategoriesByListId(PackdContext aContext, int aListId = 1)
        {
            List <ListContentDataRaw> ListData = GetListContentDataRaw(aContext, aListId);

            List <CategoryDisplay> Categories =
                ListData.Where(content => content.ListId == aListId)
                .Select(category => new CategoryDisplay
            {
                CategoryId   = category.CategoryId,
                CategoryName = category.CategoryName,
                Items        = ListData.Where(content => content.CategoryName == category.CategoryName)
                               .Select(item => new ItemDisplay
                {
                    ItemId        = item.ItemId,
                    ItemName      = item.ItemName,
                    IsPacked      = item.IsPacked,
                    ListContentId = item.ListContentId
                }).Distinct().ToList()
            })
                .GroupBy(distinct => distinct.CategoryName)
                .Select(category => category.First())
                .ToList();

            return(Categories);
        }
Ejemplo n.º 2
0
        // Get the raw content data of a list (defaults to DefaultList)
        public static List <ListContentDataRaw> GetListContentDataRaw(PackdContext aContext, int aListId = 1)
        {
            IQueryable <Lists>       Lists       = aContext.Lists;
            IQueryable <Category>    Categories  = aContext.Category;
            IQueryable <Items>       Items       = aContext.Items;
            IQueryable <ListContent> ListContent = aContext.ListContent;

            var DefaultListContentData = (from lc in ListContent
                                          join c in Categories on lc.CategoryId equals c.Id
                                          join i in Items on lc.ItemId equals i.Id
                                          join l in Lists on lc.ListId equals l.Id

                                          where lc.ListId == aListId
                                          select new ListContentDataRaw
            {
                ListContentId = lc.Id,
                ListId = lc.ListId,
                ListName = l.Name,
                CategoryId = c.Id,
                CategoryName = c.Name,
                ItemId = i.Id,
                ItemName = i.Name,
                IsPacked = lc.IsPacked == 1 ? true : false
            }).ToList();

            return(DefaultListContentData);
        }
Ejemplo n.º 3
0
        // Get List Content Data by ListId
        public static ListContentData GetListContentData(PackdContext aContext, int aListId = 1)
        {
            IQueryable <Lists> Lists = aContext.Lists;

            return(new ListContentData
            {
                ListId = aListId,
                ListName = Lists.Where(list => list.Id == aListId).FirstOrDefault().Name,
                Categories = GetCategoriesByListId(aContext, aListId)
            });
        }
Ejemplo n.º 4
0
 public ListController(ILogger <HomeController> logger, PackdContext context)
 {
     _logger  = logger;
     _context = context;
 }
Ejemplo n.º 5
0
 // Get ListId by ListName
 public static int GetListId(PackdContext aContext, string ListName)
 {
     return(aContext.Lists.Where(item => item.Name == ListName).Select(item => item.Id).FirstOrDefault());
 }
Ejemplo n.º 6
0
 // Checks if an Item exists (is associated to) in a Category
 public static bool ItemExistsInCategory(PackdContext aContext, string ItemName, int CategoryId)
 {
     return(aContext.Items.Any(item => item.Name == ItemName && item.CategoryId == CategoryId));
 }
Ejemplo n.º 7
0
 // Get CategoryId by CategoryName
 public static int GetCategoryId(PackdContext aContext, string CategoryName)
 {
     return(aContext.Category.Where(item => item.Name == CategoryName).Select(category => category.Id).FirstOrDefault());
 }
Ejemplo n.º 8
0
 // Checks if a Category exists in the Database
 public static bool CategoryExists(PackdContext aContext, string CategoryName)
 {
     return(aContext.Category.Any(item => item.Name == CategoryName));
 }
Ejemplo n.º 9
0
 // Get ItemId by ItemName
 public static int GetItemId(PackdContext aContext, int CategoryId, string ItemName)
 {
     return(aContext.Items.Where(item => item.CategoryId == CategoryId && item.Name == ItemName).Select(item => item.Id).FirstOrDefault());
 }