Exemplo n.º 1
0
        public async Task <IActionResult> Edit(Guid id, VoucherCategory voucherCategory)
        {
            if (id != voucherCategory.Id)
            {
                return(NotFound());
            }
            var exist = _context.VoucherCategories.Any(x => x.Ranking == voucherCategory.Ranking);

            if (exist)
            {
                ModelState.AddModelError(string.Empty, "Positie al in gebruik.");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(voucherCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VoucherCategoryExists(voucherCategory.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(voucherCategory));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(VoucherCategory voucherCategory)
        {
            var user = await _userManager.GetUserAsync(User);

            var exist = _context.VoucherCategories.Any(x => x.Merchant == user && x.Ranking == voucherCategory.Ranking);

            if (exist)
            {
                ModelState.AddModelError(string.Empty, "Positie al in gebruik.");
            }
            if (ModelState.IsValid)
            {
                voucherCategory.Id       = Guid.NewGuid();
                voucherCategory.Merchant = await _userManager.GetUserAsync(User);

                _context.Add(voucherCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(voucherCategory));
        }