public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var appUserInPosition = await _bll.AppUsersInPositions.FindAsync(id.Value);

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

            var vm = new WebApp.Areas.Admin.ViewModels.AppUserInPositionCreateEditViewModel();

            vm.AppUserInPosition = appUserInPosition;

            vm.AppUserSelectList = new SelectList(
                await _bll.AppUsers.AllAsync(),
                nameof(BLL.App.DTO.Identity.AppUser.Id),
                nameof(BLL.App.DTO.Identity.AppUser.FirstLastName));

            vm.AppUserPositionSelectList = new SelectList(
                await _bll.AppUsersPositions.AllAsync(),
                nameof(BLL.App.DTO.AppUserPosition.Id),
                nameof(BLL.App.DTO.AppUserPosition.AppUserPositionValue));

            return(View(vm));
        }
        public async Task <IActionResult> Edit(int id, WebApp.Areas.Admin.ViewModels.AppUserInPositionCreateEditViewModel vm)
        {
            if (id != vm.AppUserInPosition.Id)
            {
                return(NotFound());
            }

            if (!await _bll.AppUsersInPositions.BelongsToUserAsync(id, User.GetUserId()))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _bll.AppUsersInPositions.Update(vm.AppUserInPosition);
                await _bll.SaveChangesAsync();


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

            vm.AppUserSelectList = new SelectList(
                await _bll.AppUsers.AllAsync(),
                nameof(BLL.App.DTO.Identity.AppUser.Id),
                nameof(BLL.App.DTO.Identity.AppUser.FirstLastName));

            vm.AppUserPositionSelectList = new SelectList(
                await _bll.AppUsersPositions.AllAsync(),
                nameof(BLL.App.DTO.AppUserPosition.Id),
                nameof(BLL.App.DTO.AppUserPosition.AppUserPositionValue));

            return(View(vm));
        }
        public async Task <IActionResult> AddForAppUser(int appUserId)
        {
            var vm = new WebApp.Areas.Admin.ViewModels.AppUserInPositionCreateEditViewModel();

            vm.AppUser = await _bll.AppUsers.FindAsync(appUserId);

            vm.AppUserPositionSelectList = new SelectList(
                await _bll.AppUsersPositions.AllAsync(),
                nameof(BLL.App.DTO.AppUserPosition.Id),
                nameof(BLL.App.DTO.AppUserPosition.AppUserPositionValue));

            return(View(vm));
        }
        public async Task <IActionResult> Create()
        {
            var vm = new WebApp.Areas.Admin.ViewModels.AppUserInPositionCreateEditViewModel();

            vm.AppUserSelectList = new SelectList(
                await _bll.AppUsers.AllAsync(),
                nameof(BLL.App.DTO.Identity.AppUser.Id),
                nameof(BLL.App.DTO.Identity.AppUser.FirstLastName));

            vm.AppUserPositionSelectList = new SelectList(
                await _bll.AppUsersPositions.AllAsync(),
                nameof(BLL.App.DTO.AppUserPosition.Id),
                nameof(BLL.App.DTO.AppUserPosition.AppUserPositionValue));

            return(View(vm));
        }
        public async Task <IActionResult> AddForAppUser(int appUserId,
                                                        WebApp.Areas.Admin.ViewModels.AppUserInPositionCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                _bll.AppUsersInPositions.Add(vm.AppUserInPosition);
                await _bll.SaveChangesAsync();

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

            vm.AppUser = await _bll.AppUsers.FindAsync(appUserId);

            vm.AppUserPositionSelectList = new SelectList(
                await _bll.AppUsersPositions.AllAsync(),
                nameof(BLL.App.DTO.AppUserPosition.Id),
                nameof(BLL.App.DTO.AppUserPosition.AppUserPositionValue));

            return(View(vm));
        }