/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ #region CRUD //---------------------------------------------------------------------------------------------------------------------------------- // CRUD //---------------------------------------------------------------------------------------------------------------------------------- public questStatus Read(UserEditorViewModel viewModel, out UserGroupsViewModel userGroupsViewModel) { UserGroupsViewModel _userGroupsViewModel = new UserGroupsViewModel(this.UserSession, viewModel); _userGroupsViewModel.Id = viewModel.Id; return(Read(_userGroupsViewModel, out userGroupsViewModel)); }
public UserGroupsView() { InitializeComponent(); DataContext = _viewModel = new UserGroupsViewModel(); Loaded += OnUserGroupsViewLoaded; Unloaded += UserGroupsView_Unloaded; }
public async Task <IHttpActionResult> Post(UserGroup userGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.UserGroups.Add(userGroup); await db.SaveChangesAsync(); return(Ok(UserGroupsViewModel.MapFrom(userGroup))); }
public async Task <IHttpActionResult> Delete(long id) { UserGroup userGroup = await db.UserGroups.FindAsync(id); if (userGroup == null) { return(NotFound()); } else { db.UserGroups.Remove(userGroup); await db.SaveChangesAsync(); return(Ok(UserGroupsViewModel.MapFrom(userGroup))); } }
public IViewComponentResult Invoke(ModelExpression aspFor) { var metadata = aspFor.ModelExplorer.Metadata.ValidatorMetadata; for (var i = 0; i < metadata.Count; i++) { if (metadata[i] is RequiredAttribute attribute) { break; } } var model = new UserGroupsViewModel(); return(View(model)); }
public ActionResult Groups(UserEditorViewModel editorViewModel) { questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { // TODO throw new Exception("LogOperation failed"); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(editorViewModel._ctx); if (!questStatusDef.IsSuccess(status)) { // TODO throw new Exception("Authorize failed"); } /*---------------------------------------------------------------------------------------------------------------------------------- * Perform operation *---------------------------------------------------------------------------------------------------------------------------------*/ UserGroupsViewModel userGroupsViewModel = null; UserGroupsModeler userGroupsModeler = new UserGroupsModeler(this.Request, this.UserSession); status = userGroupsModeler.Read(editorViewModel, out userGroupsViewModel); if (!questStatusDef.IsSuccess(status)) { // TODO throw new Exception("Authorize failed"); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return view. *---------------------------------------------------------------------------------------------------------------------------------*/ // TEMPORARY return(View(userGroupsViewModel)); }
public ActionResult Save(UserGroupsViewModel viewModel) { questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(viewModel._ctx); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Perform operation. *---------------------------------------------------------------------------------------------------------------------------------*/ UserGroupsModeler userGroupsModeler = new UserGroupsModeler(this.Request, this.UserSession); status = userGroupsModeler.Save(viewModel); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return result. *---------------------------------------------------------------------------------------------------------------------------------*/ status = new questStatus(Severity.Success, "User groups successfully saved"); viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
public ActionResult Read(UserGroupsViewModel viewModel) { questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(viewModel._ctx); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Get list of items. *---------------------------------------------------------------------------------------------------------------------------------*/ UserGroupsViewModel userGroupsViewModel = null; UserGroupsModeler userGroupsModeler = new UserGroupsModeler(this.Request, this.UserSession); status = userGroupsModeler.Read(viewModel, out userGroupsViewModel); if (!questStatusDef.IsSuccess(status)) { viewModel.questStatus = status; return(Json(viewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return view *---------------------------------------------------------------------------------------------------------------------------------*/ userGroupsViewModel.questStatus = new questStatus(Severity.Success); return(Json(userGroupsViewModel, JsonRequestBehavior.AllowGet)); }
public async Task <IHttpActionResult> Get(int?userID) { return(Ok(await UserGroupsViewModel.MapFromAsync(db.UserGroups.Where(x => x.UserID == userID).ToList()))); }
public questStatus Read(UserGroupsViewModel viewModel, out UserGroupsViewModel userGroupsViewModel) { // Initialize questStatus status = null; userGroupsViewModel = null; UserId userId = new UserId(viewModel.Id); // Get the user User user = null; UsersMgr usersMgr = new UsersMgr(this.UserSession); status = usersMgr.Read(userId, out user); if (!questStatusDef.IsSuccess(status)) { return(status); } // Get groups List <SearchField> searchFieldList = new List <SearchField>(); SearchOptions searchOptions = new SearchOptions(); searchOptions.SearchFieldList = searchFieldList; QueryOptions queryOptions = new QueryOptions(); queryOptions.SearchOptions = searchOptions; QueryResponse queryResponse = null; List <Group> groupList = null; GroupsMgr groupsMgr = new GroupsMgr(this.UserSession); status = groupsMgr.List(queryOptions, out groupList, out queryResponse); if (!questStatusDef.IsSuccess(status)) { return(status); } // Get user groups List <Group> userGroupList = null; AccountMgr accountMgr = new AccountMgr(this.UserSession); status = accountMgr.GetUserGroups(userId, out userGroupList); if (!questStatusDef.IsSuccess(status)) { return(status); } // Remove from groups lists whatever groups the user is already in. List <Group> unassignedGroupList = new List <Group>(); foreach (Group group in groupList) { Group userGroup = userGroupList.Find(delegate(Group g) { return(g.Id == group.Id); }); if (userGroup == null) { unassignedGroupList.Add(group); } } // Sort group lists unassignedGroupList.Sort(delegate(Group i1, Group i2) { return(i1.Name.CompareTo(i2.Name)); }); userGroupList.Sort(delegate(Group i1, Group i2) { return(i1.Name.CompareTo(i2.Name)); }); // Transfer model userGroupsViewModel = new UserGroupsViewModel(this.UserSession, viewModel); UserEditorViewModel userEditorViewModel = new UserEditorViewModel(); BufferMgr.TransferBuffer(user, userEditorViewModel); userGroupsViewModel.User = userEditorViewModel; foreach (Group group in unassignedGroupList) { BootstrapTreenodeViewModel groupNode = null; status = FormatBootstrapTreeviewNode(group, out groupNode); if (!questStatusDef.IsSuccess(status)) { return(status); } userGroupsViewModel.Groups.Add(groupNode); } foreach (Group group in userGroupList) { BootstrapTreenodeViewModel userGroupNode = null; status = FormatBootstrapTreeviewNode(group, out userGroupNode); if (!questStatusDef.IsSuccess(status)) { return(status); } userGroupsViewModel.UserGroups.Add(userGroupNode); } return(new questStatus(Severity.Success)); }
public questStatus Save(UserGroupsViewModel userGroupsViewModel) { // Initialize questStatus status = null; DbMgrTransaction trans = null; Mgr mgr = new Mgr(this.UserSession); try { // BEGIN TRANSACTION status = mgr.BeginTransaction("FMS", "SaveUserGroups_" + userGroupsViewModel.Id.ToString() + "_" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Remove all the user's groups. UserId userId = new UserId(userGroupsViewModel.Id); GroupUsersMgr groupUsersMgr = new GroupUsersMgr(this.UserSession); status = groupUsersMgr.Delete(trans, userId); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } // Save all the groups the user is assigned. GroupUser groupUser = new GroupUser(); groupUser.User.Id = userGroupsViewModel.User.Id; foreach (BootstrapTreenodeViewModel userGroupNode in userGroupsViewModel.UserGroups) { GroupUserId groupUserId = null; groupUser.Group.Id = userGroupNode.Id; status = groupUsersMgr.Create(trans, groupUser, out groupUserId); if (!questStatusDef.IsSuccess(status)) { mgr.RollbackTransaction(trans); return(status); } } // COMMIT TRANSACTION status = mgr.CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } } catch (System.Exception ex) { if (trans != null) { mgr.RollbackTransaction(trans); } return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.InnerException != null ? ex.InnerException.Message : ex.Message))); } return(new questStatus(Severity.Success)); }