예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Position position)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "Positions"));
            }
            if (id != position.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(position);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PositionExists(position.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(position));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,LastName,FirstName,MiddleName,BirthDate,Gender,Address,Phone,PassportData,Discount")] Client client)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "Clients"));
            }
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,LastName,FirstName,MiddleName,BirthDate,PositionId")] Employee employee)
        {
            if (!User.IsInRole(Areas.Identity.Roles.Admin))
            {
                return(RedirectToAction("Index", "Employees"));
            }
            if (id != employee.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();

                    _caching.Clean();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PositionId"] = new SelectList(_context.Positions, "Id", "Id", employee.PositionId);
            return(View(employee));
        }