public async Task <IActionResult> Edit(int id, AppUserOnObjectCreateEditViewModel vm)
        {
            if (id != vm.AppUserOnObject.Id)
            {
                return(NotFound());
            }

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

            if (ModelState.IsValid)
            {
                _bll.AppUsersOnObjects.Update(vm.AppUserOnObject);
                await _bll.SaveChangesAsync();

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

            vm.WorkObjectSelectList = new SelectList(
                await _bll.WorkObjects.AllForUserAsync(User.GetUserId()),
                nameof(BLL.App.DTO.WorkObject.Id),
                nameof(BLL.App.DTO.WorkObject.Id));

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

            return(View(vm));
        }
        // GET: AppUsersOnObjects/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var appUserOnObject = await _bll.AppUsersOnObjects.FindAsync(id.Value);

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

            var vm = new AppUserOnObjectCreateEditViewModel();

            vm.AppUserOnObject = appUserOnObject;

            vm.WorkObjectSelectList = new SelectList(
                await _bll.WorkObjects.AllForUserAsync(User.GetUserId()),
                nameof(BLL.App.DTO.WorkObject.Id),
                nameof(BLL.App.DTO.WorkObject.Id));

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

            return(View(vm));
        }
        // GET: AppUsersOnObjects/Create
        public async Task <IActionResult> Create()
        {
            var vm = new AppUserOnObjectCreateEditViewModel();

            vm.WorkObjectSelectList = new SelectList(
                await _bll.WorkObjects.AllForUserAsync(User.GetUserId()),
                nameof(BLL.App.DTO.WorkObject.Id),
                nameof(BLL.App.DTO.WorkObject.Id));

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

            return(View(vm));
        }
        public async Task <IActionResult> Create(AppUserOnObjectCreateEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                _bll.AppUsersOnObjects.Add(vm.AppUserOnObject);
                await _bll.SaveChangesAsync();

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

            vm.WorkObjectSelectList = new SelectList(
                await _bll.WorkObjects.AllForUserAsync(User.GetUserId()),
                nameof(BLL.App.DTO.WorkObject.Id),
                nameof(BLL.App.DTO.WorkObject.Id));

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

            return(View(vm));
        }