Exemple #1
0
        public async Task <IActionResult> Create()
        {
            int tastingId = await _userAccessService.GetTastingId();

            int tasterId = await GetTasterId();

            ViewBag.tastingName = await _context.Tastings.Where(a => a.TastingId == tastingId).Select(b => b.TastingName).FirstAsync();

            ViewBag.productCount = _context.TastingHistory.Where(a => a.TastingId == tastingId).Count() + 1;

            List <int> assignedTasterIds = await _context.TasterToTastings.Where(c => c.TastingId == tastingId).Select(d => d.TasterId).ToListAsync();

            bool tasterIsAsiggned = false;

            if (assignedTasterIds.Count > 0)
            {
                for (int i = 0; i < assignedTasterIds.Count; i++)
                {
                    if (assignedTasterIds[i] == tasterId)
                    {
                        tasterIsAsiggned = true;
                        break;
                    }
                }
            }

            if (!tasterIsAsiggned)
            {
                return(RedirectToAction("ErrorPage", "Home", new { message = "Something going wrong. You are not assigned for tasting!" }));
            }

            return(View());
        }
        // GET: ProductsToTastings
        public async Task <IActionResult> Index()
        {
            int activeTasting = await _userAccessService.GetTastingId();

            var applicationDbContext = _context.ProductToTastings.Include(p => p.Product).Include(p => p.Tasting).Where(a => a.TastingId == activeTasting);

            return(View(await applicationDbContext.ToListAsync()));
        }