public ActionResult Create() { var listSelectListItems = new List<SelectListItem>(); var roles = _repository.Fetch<MenuItem>().DistinctBy(p=> p.ParentName).Select(p=> p.ParentName); foreach (var n in roles) { var selectList = new SelectListItem() { Text = n, Value = n }; listSelectListItems.Add(selectList); } var registerMenus = new RegisterMenus(); registerMenus.RoleTypes = listSelectListItems; return View(registerMenus); }
public ActionResult Create(RegisterMenus registerMenus, FormCollection formCollection) { var group = _repository.Find<Group>(Guid.Parse(TempData["Id"].ToString())); try { string[] roleValue1 = formCollection["CurrentAvailableList"].Split(','); var cnt = 0; var givBackText = ""; foreach (var n in roleValue1) { if ( !_repository.Search<MenuMap>( p => p.GroupId == Guid.Parse(TempData["Id"].ToString()) && p.MenuItems.MenuTitle == n).Any()) { var getMainMenu = _repository.Fetch<MenuItem>().FirstOrDefault(p => p.MenuTitle == n); var model = new MenuMap(); model.Id = Guid.NewGuid(); model.Maker = User.Identity.GetUserName(); model.OsysDateTime = DateTime.Now; model.EditDateTime = DateTime.Now; model.GroupId = Guid.Parse(TempData["Id"].ToString()); model.MenuItemId = getMainMenu.Id; model.ParentName = getMainMenu.ParentName; model.Status = MyEnums.StatusOptions.Added; _repository.SaveNew(model); _sharedCls.LogAudit(User.Identity.GetUserName(), "Created", Request.UserHostName, "Created Menu Mapping" + group.Name + " Added menu: " + model.MenuItems.MenuTitle + " for Group: " + model.Group.Name, "ISA", "Groups"); cnt++; givBackText += "Added Successfully :- " + n + Environment.NewLine; } if (cnt == 0) { givBackText += "Already Exist :- " + n + " For Group: " + _repository.Find<Group>(Guid.Parse(TempData["Id"].ToString())).Name + Environment.NewLine; } } ModelState.AddModelError("Success", givBackText); return RedirectToAction("Index", new { id = TempData["Id"] }); } catch (Exception ex) { ModelState.AddModelError("", "Experienced Error Contact Admin!"); return RedirectToAction("Index", new { id = TempData["Id"] }); } }