Exemple #1
0
        public async Task RemoveProjectToUser(AddProjectToUserViewModel model)
        {
            var removeCombo = await dbContext.UserProjects.FirstOrDefaultAsync(up => up.ProjectId == model.ProjectId && up.UserId == model.UserId);

            if (removeCombo == null)
            {
                throw new NullReferenceException($" Not found.");
            }
            dbContext.UserProjects.Remove(removeCombo);
            await dbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> RemoveProjectToUser(AddProjectToUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = await service.FindUserIdByName(model.UserId);

                model.UserId = userId.Id;
                await service.RemoveProjectToUser(model);

                return(RedirectToAction("DisplayAllProjects"));
            }
            return(View());
        }
Exemple #3
0
        public async Task AddProjectToUser(AddProjectToUserViewModel model)
        {
            if (model.ProjectId == null)
            {
                throw new NullReferenceException();
            }
            var newCombo = new UserProject();

            newCombo.ProjectId = model.ProjectId;
            newCombo.UserId    = model.UserId;

            await dbContext.AddAsync(newCombo);

            await dbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> RemoveProjectToUser(string id)
        {
            var findProject = await service.FindProject(id);

            if (findProject == null)
            {
                return(NotFound());
            }
            var newCombo = new AddProjectToUserViewModel
            {
                ProjectId = id
            };

            IEnumerable <User> userIdToSelect = service.UsersToSelect();

            ViewBag.UserId = new SelectList(userIdToSelect, "UserName", "UserName", newCombo.UserId);

            return(View(newCombo));
        }