Esempio n. 1
0
        public async Task <IActionResult> Assign(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var complain = await _context.Complains.FindAsync(id);

            if (complain == null)
            {
                return(NotFound());
            }

            if (HttpContext.Session.GetString("UserAdmin") != null)
            {
                ViewData["WorkerId"] = new SelectList(_context.Users.Where(t => t.UserType == "Worker"), "ID", "Name");
                var workerComplain = new WorkerComplain();
                workerComplain.ComplainId = id;

                return(View(workerComplain));
            }
            else
            {
                return(RedirectToAction("Admin", "Account"));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Assign([Bind("UserId,ComplainId")] WorkerComplain workerComplain)
        {
            if (workerComplain.ComplainId == null)
            {
                return(NotFound());
            }

            var complain = await _context.Complains.FindAsync(workerComplain.ComplainId);

            if (complain == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Add(workerComplain);
                await _context.SaveChangesAsync();

                try
                {
                    complain.Status = "Working";

                    _context.Update(complain);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }

                return(RedirectToAction(nameof(Complains)));
            }
            ViewData["WorkerId"] = new SelectList(_context.Users.Where(t => t.UserType == "Worker"), "ID", "Name");
            return(View(workerComplain));
        }