Ejemplo n.º 1
0
 public IActionResult Get(ItemFilterVM filter)
 {
     try
     {
         return(Ok(_itemService.GetAll(filter)));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 2
0
        public GetItemVM GetAll(ItemFilterVM filter)
        {
            GetItemVM vm = new GetItemVM();

            vm.Items = _context.Item.
                       Where(a => (a.BrandCategoryID == filter.BrandCategoryID || filter.BrandCategoryID == 0) &&
                             (a.GenderSubCategory.GenderCategoryID == filter.GenderCategoryID || filter.GenderCategoryID == 0) &&
                             (a.GenderSubCategory.SubCategoryID == filter.SubCategoryID || filter.SubCategoryID == 0) &&
                             (a.GenderSubCategory.SubCategory.CategoryID == filter.CategoryID || filter.CategoryID == 0))
                       .Select(a => new GetItemVM.Rows
            {
                ID             = a.ID,
                SerialNumber   = a.SerialNumber,
                Name           = a.Name,
                Description    = a.Description,
                Price          = a.Price,
                BrandCategory  = _context.BrandCategory.Where(b => b.ID == a.BrandCategoryID).FirstOrDefault().Name,
                GenderCategory = _context.GenderSubCategory.Where(c => c.ID == a.GenderSubCategoryID).FirstOrDefault().GenderCategory.Name,
                SubCategory    = _context.GenderSubCategory.Where(d => d.ID == a.GenderSubCategoryID).FirstOrDefault().SubCategory.Name,
                Image          = _context.ItemImage.Where(f => f.ItemID == a.ID).FirstOrDefault().Image,
                BranchID       = filter.BranchID
            }).ToList();
            return(vm);
        }