// GET: Households/UnAssign/5 public ActionResult UnAssign(int householdId, string userId) { //var household = db.Households.Find(householdId); //var user = db.Users.Find(userId); //HouseholdUsersHelper helper = new HouseholdUsersHelper(db); var model = new AssignUsersViewModel(); ViewBag.HouseholdId = householdId; ViewBag.UserId = userId; return(View(model)); }
public IActionResult AssignUsers(int boardId) { try { ViewBag.boardId = boardId; // send the boardid via viewbag since we cannot retrieve the boardid via the list given to the model. var board = _boardRepository.GetById(boardId); if (board == null || board.IsDeleted == true) { Response.StatusCode = 404; return(View("BoardNotFound", boardId)); } var model = new List <AssignUsersViewModel>(); var userList = _companyRepository.GetAllCompanyUsers(board.CompanyId).ToList(); foreach (var user in userList) { // check if exists and is true == IsSelected moet ingevuld var IsAssigned = _boardRepository.FindBoardUser(boardId, user.Id); if (IsAssigned != null) { var AssignUserModel = new AssignUsersViewModel() { UserId = user.Id, UserName = user.UserName, IsSelected = !IsAssigned.IsDeleted }; model.Add(AssignUserModel); } else { var Usermodel = new AssignUsersViewModel() { UserId = user.Id, UserName = user.UserName, IsSelected = false }; model.Add(Usermodel); } } return(View(model)); } catch (Exception ex) { _logger.LogError(ex, $"When getting the users for assignment to board."); throw; } }
public ActionResult Assign(int id) { var project = db.Projects.Find(id); AssignHelper helper = new AssignHelper(db); var model = new AssignUsersViewModel(); model.Project = project; model.SelectedUsers = helper.ListAssignedUsers(id).Select(u => u.Id).ToArray(); model.Users = new MultiSelectList(db.Users.Where(u => (u.DisplayName != "N/A" && u.DisplayName != "(Remove Assigned User)")).OrderBy(u => u.FirstName), "Id", "DisplayName", model.SelectedUsers); return(View(model)); }
public ActionResult UnAssign(AssignUsersViewModel model, int householdId, string userId) { if (ModelState.IsValid) { var household = db.Households.Find(householdId); var user = db.Users.Find(userId); HouseholdUsersHelper helper = new HouseholdUsersHelper(db); helper.RemoveUserFromHousehold(household.Id, user.Id); return(RedirectToAction("Assign", "Households", new { id = household.Id })); } return(View(model)); }
// GET: Households/Assign/5 public ActionResult Assign(int id) { var household = db.Households.Find(id); HouseholdUsersHelper helper = new HouseholdUsersHelper(db); var model = new AssignUsersViewModel(); model.Household = household; model.SelectedUsers = helper.ListAssignedUsers(id).ToArray(); model.Users = new MultiSelectList(model.SelectedUsers.Where(u => (u.DisplayName != "N/A" && u.DisplayName != "(Remove Assigned User)")).OrderBy(u => u.FirstName), "Id", "DisplayName", model.SelectedUsers); //model.Users = new MultiSelectList(db.Users.Where(u => (u.DisplayName != "N/A" && u.DisplayName != "(Remove Assigned User)")).OrderBy(u => u.FirstName), "Id", "DisplayName", model.SelectedUsers); return(View(model)); }
public ActionResult Assign(AssignUsersViewModel model) { var project = db.Projects.Find(model.Project.Id); AssignHelper helper = new AssignHelper(db); foreach (var user in db.Users.Select(r => r.Id).ToList()) { helper.RemoveProjectFromUser(project.Id, user); } if (model.SelectedUsers != null) { foreach (var user in model.SelectedUsers) { helper.AddProjectToUser(project.Id, user); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Assign(AssignUsersViewModel model) { var household = db.Households.Find(model.Household.Id); HouseholdUsersHelper helper = new HouseholdUsersHelper(db); foreach (var user in db.Users.Select(r => r.Id).ToList()) { if (model.SelectedUsers != null) { foreach (var item in model.SelectedUsers) { helper.RemoveUserFromHousehold(household.Id, item.Id); } } return(RedirectToAction("Index", "Home")); } return(View(model)); }
public async Task <IEnumerable <dynamic> > SaveAssignUser(AssignUsersViewModel auvm) { string sql = "dbo.EAppSaveAssignUser"; using (var conn = util.MasterCon()) { try { var returnValue = await(conn.QueryAsync <dynamic>(sql, new { auvm.Type, auvm.Id, auvm.DataCollectionMode, auvm.DataCollectorId, auvm.AnalystId, auvm.ReviewerId }, commandType: CommandType.StoredProcedure)); if (auvm.DataCollectionMode == 0) { /** Notify EMail to Data Collector */ try { await Task.Factory.StartNew(async() => { String evmStr = await emailService.GetEmailNotificationTemplate("Notify_DataCollector", 0, 1, (int)auvm.Id, auvm.UserId); EmailViewModel evm = JsonConvert.DeserializeObject <EmailViewModel>(evmStr); await notificationServiceHelper.PrepareCalendarNotification(evm); }); } catch (Exception ex) { // Notification exception. var e = ex; } } return(returnValue); } catch (Exception ex) { throw new CustomException("Unable to Load Data, Please Contact Support!!!", "Error", true, ex); } } }