public ActionResult EditGroup(UserGroup record) { try { if (record != null) { var groupBusiness = new UserGroupBusiness(); var temp = groupBusiness.GetById(record.Id); temp.Code = record.Code; temp.Modifieddate = DateTime.Now; temp.Name = record.Name; temp.Status = record.Status; temp.Description = record.Description; groupBusiness.Edit(temp); return(RedirectToAction("Groups")); } return(View()); } catch (FaultException ex) { var exep = Function.GetExeption(ex); var codeExp = exep[1]; string url = "Error/ErrorFunction/" + codeExp; return(RedirectToActionPermanent(url)); } }
public ActionResult ManageRolesForGroup(long?id, int?page) { try { int currentPageIndex = page.HasValue ? page.Value : 1; InitSelectListItemRole(id); var userGroupRoleBusiness = new UserGroupRoleBusiness(); var userGroupBusiness = new UserGroupBusiness(); if (id != null) { IList <UserGroupRole> userGroupRole = userGroupRoleBusiness.GetByGroupId((long)id).ToPagedList(currentPageIndex, 30); var userGroup = userGroupBusiness.GetById((long)id); ViewData["group_name"] = userGroup.Name; return(View((IPagedList <UserGroupRole>)userGroupRole)); } } catch (FaultException ex) { var exep = Function.GetExeption(ex); var codeExp = exep[1]; string url = "Error/ErrorFunction/" + codeExp; return(RedirectToActionPermanent(url)); } return(RedirectToAction("Groups")); }
public PermissionForm() { InitializeComponent(); saveMode = SaveMode.None; permissionBusiness = new PermissionBusiness(); userGroupBusiness = new UserGroupBusiness(); perDetailBusiness = new PermissionDetailBusiness(); }
public bool DeleteUserfromDB(int id) { bool result = default(bool); BaseDataAccess _db = new BaseDataAccess(); using (DbTransaction dbTransaction = _db.CreateTransaction()) { try { // 1- Select User From DB by ID UserBusiness userBusiness = new UserBusiness(); UserList userList = userBusiness.SelectRows(id, null, null, null); if (userList != null && userList.Count > 0) { // 2- Select User Groups From DB by User ID UserGroupBusiness userGroupBusiness = new UserGroupBusiness(); UserGroupList userGroupList = userGroupBusiness.SelectRows(null, id, null); if (userGroupList != null && userGroupList.Count > 0) { // 3- Delete User Groups first (we must remove children first because of DB relation) foreach (UserGroup userGroup in userGroupList) { userGroupBusiness = new UserGroupBusiness(); userGroupBusiness.DeleteRow(dbTransaction, userGroup); } } // 4- Then Delete The User itself userBusiness = new UserBusiness(); if (userBusiness.DeleteRow(dbTransaction, userList[0]) > 0) { dbTransaction.Commit(); result = true; } else { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } else { dbTransaction.Rollback(); throw new Exception("User Id Not Found in DB"); } } catch (Exception) { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } return(result); }
public UserDTO GetUserByIDfromDB(int id) { ICollection <UserDTO> outputList = default(ICollection <UserDTO>); UserDTO output = new UserDTO(); try { // 1- Select User From DB by ID UserBusiness _UserBusiness = new UserBusiness(); UserList _UserList = _UserBusiness.SelectRows(id, null, null, null); if (_UserList != null && _UserList.Count > 0) //outputList = Mapper.MapUserAsOutput(); { // 2- Prepare Mapping Obects (Fill Values from DB) Mapper._GroupList = fillGroupList(); //default(List<Group>); Mapper._FunctionList = fillFunctionList(); //default(List<Function>); Mapper._UserList = _UserList; Mapper._UserGroupList = new List <UserGroup>(); //default(List<UserGroup>); Mapper._GroupFunctionList = fillGroupFunctionList(); //default(List<GroupFunction>); UserGroupBusiness _UserGroupBusiness = new UserGroupBusiness(); UserGroupList _UserGroupList = default(UserGroupList); foreach (User _User in _UserList) { _UserGroupList = _UserGroupBusiness.SelectRows(null, _User.Id, null); if (_UserGroupList != null && _UserGroupList.Count > 0) { foreach (UserGroup _UserGroup in _UserGroupList) { Mapper._UserGroupList.Add(Copier.copyUserGroup(_UserGroup)); } } } // 3- Perform Mapping to Output outputList = Mapper.MapUserAsOutput(); if (outputList != null && outputList.Count > 0) { output = outputList.First(); } } } catch (Exception ex) { // Log Exception Here throw; //new Exception(ex.Message); } return(output); }
//Khởi tạo danh sách chọn Module protected void InitSelectListItemGroup(long?id) { var listItemGroup = new List <SelectListItem>(); var listGroup = new UserGroupBusiness().GetGroupByNotInUser((long)id); foreach (var record in listGroup) { listItemGroup.Add(new SelectListItem { Text = record.Name, Value = record.Id.ToString() }); } ViewBag.ListItemGroup = listItemGroup; }
private void UserForm_Load(object sender, System.EventArgs e) { currentUser = UserBusiness.User; var userGroupBusiness = new UserGroupBusiness(); textEditId.EditValue = UserBusiness.User.UserID; textEditFullName.EditValue = UserBusiness.User.FullName; textEditEmail.EditValue = UserBusiness.User.Email; textEditAddress.EditValue = UserBusiness.User.Address; textUserGroup.EditValue = userGroupBusiness.GetByUserGroupID(UserBusiness.User.UserGroupID).UserGroupName; textEditUsername.EditValue = UserBusiness.User.Username; dateDateOfBirth.EditValue = UserBusiness.User.DateOfBirth; }
private void UserManagerForm_Load(object sender, System.EventArgs e) { var users = userBusiness.GetAllWithUserGroupName(); gridControl1.DataSource = users; var userGroupBusiness = new UserGroupBusiness(); var lookup = lookUpEditUerGroup.Properties; lookup.DataSource = userGroupBusiness.GetAll(); lookup.Columns.Add(new LookUpColumnInfo("UserGroupID", "Mã")); lookup.Columns.Add(new LookUpColumnInfo("UserGroupName", "Tên loại người dùng")); lookup.DisplayMember = "UserGroupName"; lookup.ValueMember = "UserGroupID"; }
public ActionResult DetailGridBatchUpdate(MVCxGridViewBatchUpdateValues <SystemUser, int> updateValues, List <int> permissions, UserGroupModel master) { //TODO //master 要轉成 Entity(UserGroup) var deleteKeys = updateValues.DeleteKeys; var insertList = updateValues.Insert; // SaveChanges(ref Models.UserGroup entity, List<int> permissions, List<int> insertUser, List<int> deleteUser, EntityState state) var data = _Service.GetByKey(master.ID); UserGroupBusiness.ToEntity(ref data, master); ViewData["MasterForm"] = ReadViewHelper.PartialView(this, "_MasterForm", UserGroupBusiness.FromEntity(data)); ViewData["TreeList"] = ReadViewHelper.PartialView(this, "_MasterForm", UserGroupBusiness.FromEntity(data)); return(PartialView("_DetailGrid", _Service.GetGroupUser(master.ID))); }
public ActionResult Groups(string key, int?page) { try { ViewData["key"] = key; int currentPageIndex = page.HasValue ? page.Value : 1; IList <UserGroup> list = new UserGroupBusiness().GetByKey(key).ToPagedList(currentPageIndex, 20); return(View((IPagedList <UserGroup>)list)); } catch (FaultException ex) { var exep = Function.GetExeption(ex); var codeExp = exep[1]; string url = "Error/ErrorFunction/" + codeExp; return(RedirectToActionPermanent(url)); } }
// // GET: /CMSBHDType/Create public ActionResult EditGroup(long id = 0) { try { InitSelectListItemStatus(); UserGroupBusiness groupBusiness = new UserGroupBusiness(); var record = groupBusiness.GetById(id); if (record == null) { return(HttpNotFound()); } return(View(record)); } catch (FaultException ex) { var exep = Function.GetExeption(ex); var codeExp = exep[1]; string url = "Error/ErrorFunction/" + codeExp; return(RedirectToActionPermanent(url)); } }
public ActionResult CreateGroup(UserGroup record) { try { if (ModelState.IsValid) { UserGroupBusiness groupBusiness = new UserGroupBusiness(); record.Createdate = DateTime.Now; record.Modifieddate = DateTime.Now; groupBusiness.AddNew(record); return(RedirectToAction("Groups")); } return(View(record)); } catch (FaultException ex) { var exep = Function.GetExeption(ex); var codeExp = exep[1]; string url = "Error/ErrorFunction/" + codeExp; return(RedirectToActionPermanent(url)); } }
public ActionResult DetailGrid(int?key) { if (key.HasValue) { var data = _Service.GetByKey(key.Value); ViewData["MasterForm"] = ReadViewHelper.PartialView(this, "_MasterForm", UserGroupBusiness.FromEntity(data)); return(PartialView("_DetailGrid", _Service.GetGroupUser(key.Value))); } else { //ViewData["MasterForm"] = ReadViewHelper.PartialView(this, "_MasterForm", new ViewModel.UserGroup.UserGroupModel()); return(PartialView("_DetailGrid", new List <Models.SystemUser>())); } }
public UserGroupController(UserGroupBusiness userGroupBusiness) { _userGroupBusiness = userGroupBusiness; }
public UserDTO UpdateUserinDB(UserDTO userDTO) { BaseDataAccess _db = new BaseDataAccess(); using (DbTransaction dbTransaction = _db.CreateTransaction()) { try { // 1- Perform Mapping to Input (for Saving in DB) if (Mapper.MapUserAsInput(userDTO)) { ////User user = Mapper._User; ////List<UserGroup> userGroups = Mapper._UserGroupListInput; //UserBusiness userBusiness = new UserBusiness(); //if (userBusiness.InsertRow(dbTransaction, Mapper._User) > 0) //{ // UserGroupBusiness userGroupBusiness = new UserGroupBusiness(); // if (Mapper._UserGroupListInput != null && Mapper._UserGroupListInput.Count > 0) // { // foreach (UserGroup userGroup in Mapper._UserGroupListInput) // { // userGroup.userId = Mapper._User.Id; // userGroupBusiness = new UserGroupBusiness(); // userGroupBusiness.InsertRow(dbTransaction, userGroup); // } // dbTransaction.Commit(); // } // else // dbTransaction.Rollback(); //} //else // throw new DataException("DataBase Operation Failure"); // 2- Select User to be updated UserBusiness userBusiness = new UserBusiness(); UserList userList = userBusiness.SelectRows(Mapper._User.Id, null, null, null); if (userList != null && userList.Count > 0) { userList[0].userName = Mapper._User.userName; userList[0].fullName = Mapper._User.fullName; userList[0].Password = Mapper._User.Password; userList[0].status = Mapper._User.status; // 3- Update User Data by Input Values userBusiness = new UserBusiness(); if (userBusiness.UpdateRow(dbTransaction, userList[0]) > 0) { // 4- Remove User Groups Already Saved for that User in DB UserGroupBusiness userGroupBusiness = new UserGroupBusiness(); UserGroupList userGroupList = userGroupBusiness.SelectRows(null, Mapper._User.Id, null); if (userGroupList != null && userGroupList.Count > 0) { //foreach (UserGroup userGroup in Mapper._UserGroupList) //{ // userGroupBusiness = new UserGroupBusiness(); // userGroupBusiness.DeleteRow(dbTransaction, userGroup); //} foreach (UserGroup userGroup in userGroupList) { userGroupBusiness = new UserGroupBusiness(); userGroupBusiness.DeleteRow(dbTransaction, userGroup); } } // 5- Add New User Groups from Input if (Mapper._UserGroupListInput != null && Mapper._UserGroupListInput.Count > 0) { foreach (UserGroup userGroup in Mapper._UserGroupListInput) { userGroupBusiness = new UserGroupBusiness(); userGroupBusiness.InsertRow(dbTransaction, userGroup); } dbTransaction.Commit(); } } else { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } else { throw new Exception("User Id Not Found in DB"); } } else { throw new ArgumentNullException("userDTO"); } } catch (Exception ex) { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } return(userDTO); }
public UserDTO AddUsertoDB(UserDTO userDTO) { BaseDataAccess _db = new BaseDataAccess(); using (DbTransaction dbTransaction = _db.CreateTransaction()) { try { // 1- Perform Mapping to Input (for Saving in DB) if (Mapper.MapUserAsInput(userDTO)) { //User user = Mapper._User; //List<UserGroup> userGroups = Mapper._UserGroupListInput; Mapper._User.createDate = DateTime.Now; // 2- Insert User in DB UserBusiness userBusiness = new UserBusiness(); if (userBusiness.InsertRow(dbTransaction, Mapper._User) > 0) { userDTO.Id = Mapper._User.Id; if (Mapper._UserGroupListInput != null && Mapper._UserGroupListInput.Count > 0) { UserGroupBusiness userGroupBusiness = new UserGroupBusiness(); // 3- Insert User Groups in DB foreach (UserGroup userGroup in Mapper._UserGroupListInput) { userGroup.userId = Mapper._User.Id; userGroupBusiness = new UserGroupBusiness(); userGroupBusiness.InsertRow(dbTransaction, userGroup); } dbTransaction.Commit(); } else { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } else { throw new Exception("DataBase Operation Failure"); } } else { throw new ArgumentNullException("userDTO"); } } catch (Exception ex) { dbTransaction.Rollback(); throw new Exception("DataBase Operation Failure"); } } return(userDTO); }