private List <SelectListItem> PopulateApplications(string userName) { AssignApplication assignApplication = new AssignApplication(); assignApplication.UserName = userName; List <SelectListItem> items = new List <SelectListItem>(); assignApplicationService = new AssignApplicationService(); var applications = assignApplicationService.GetUserApplicationIds(assignApplication); if (applications.AssignedApplications == null) { applications.AssignedApplications = "0"; } string[] values = applications.AssignedApplications.ToString().Split(','); for (int i = 0; i < values.Length; i++) { values[i] = values[i].Trim(); } foreach (var item in values) { items.Add(new SelectListItem { Value = item }); } return(items); }
public IActionResult AssignApplication(PopulateApplicationsView populateApplicationsView) { AssignApplication assignApplication = new AssignApplication(); string name = (string)TempData["User"]; populateApplicationsView.SelectedApplicationList = GetAllApplications(); if (populateApplicationsView.SelectedApplicationId != null && name != "") { var selectedItems = populateApplicationsView.SelectedApplicationList.Where(p => populateApplicationsView.SelectedApplicationId.Contains(int.Parse(p.Value))).ToList(); string applist = ""; ViewBag.Message = "Selected Apps:"; foreach (var selectedItem in selectedItems) { applist += selectedItem.Value + ","; ViewBag.Message += "\\n" + selectedItem.Text; } applist = applist.TrimEnd(','); assignApplication.AssignedApplications = applist; assignApplication.UserName = name; } else if (populateApplicationsView.SelectedApplicationId == null && name != "") { assignApplication.AssignedApplications = null; assignApplication.UserName = name; } assignApplicationService = new AssignApplicationService(); var result = assignApplicationService.AssignApplicationToUser(assignApplication); return(RedirectToAction("list", "User")); //return View(); }