protected void btUsersOK_Click(object sender, EventArgs e) { Guid groupID; if (!Guid.TryParse(hdUsersGroupID.Value, out groupID)) { return; } Guid userID; if (!Guid.TryParse(lstUsers.SelectedValue, out userID)) { return; } AccessLevelEnum accessLevel; if (!Enum.TryParse(ddlAccessLevels.SelectedItem.Value.ToString(), out accessLevel)) { return; } var group = DataContext.UM_Groups.FirstOrDefault(n => n.ID == groupID); if (group == null) { return; } var user = DataContext.UM_Users.FirstOrDefault(n => n.ID == userID); if (user == null) { return; } var exists = DataContext.UM_GroupUsers.Count(n => n.DateDeleted == null && n.GroupID == groupID && n.UserID == userID) > 0; if (exists) { return; } var groupUser = new UM_GroupUser { ID = Guid.NewGuid(), DateCreated = DateTime.Now, GroupID = groupID, UserID = userID, AccessLevel = (int)accessLevel }; DataContext.UM_GroupUsers.InsertOnSubmit(groupUser); DataContext.SubmitChanges(); CacheEntitiesUtil.ResetAll(); tlGroups.RefreshVirtualTree(); }
protected void AddUser() { var loginName = tbLoginName.Text.Trim(); var password = tbPassword.Text.Trim(); var firstName = tbFirstName.Text.Trim(); var lastName = tbLastName.Text.Trim(); var email = tbEmail.Text.Trim(); var address = tbAddress.Text.Trim(); var passwordExpirationDate = DataConverter.ToDateTime(tbPasswordExpirationDate.Text); var activate = chkActivate.Checked; var user = InitializeUser ( loginName, password, firstName, lastName, email, address, passwordExpirationDate, activate ); DataContext.UM_Users.InsertOnSubmit(user); var nodes = tlGroups.GetSelectedNodes(); foreach (var treeListNode in nodes) { var nodeObject = treeListNode.Key; var group = NodeKeyObject.Parse(nodeObject); var groupUser = new UM_GroupUser { ID = Guid.NewGuid(), DateCreated = DateTime.Now, GroupID = @group.GroupID, UserID = user.ID, AccessLevel = (int)Enum.Parse(typeof(AccessLevelEnum), ddlAccessLevels.SelectedItem.Value.ToString()) }; user.GroupUsers.Add(groupUser); } try { DataContext.SubmitChanges(); } catch (Exception e) { Response.Write(e.Message); } ResetFields(); }
protected void btUserOK_Click(object sender, EventArgs e) { var model = selectUserControl.Model; var userID = model.User.UserID; var groupID = model.ParentID; var accessLevel = DataConverter.ToNullableEnum <AccessLevelEnum>(model.AccessLevel); if (userID == null || groupID == null || accessLevel == null) { return; } var group = HbSession.Query <UM_Group>().FirstOrDefault(n => n.ID == groupID); if (group == null) { return; } var user = HbSession.Query <UM_User>().FirstOrDefault(n => n.ID == userID); if (user == null) { return; } var exists = (from n in HbSession.Query <UM_GroupUser>() where n.DateDeleted == null && n.GroupID == groupID && n.UserID == userID select n).Any(); if (exists) { return; } var groupUser = new UM_GroupUser { ID = Guid.NewGuid(), DateCreated = DateTime.Now, GroupID = groupID.Value, UserID = userID.Value, AccessLevel = (int)accessLevel }; HbSession.SubmitChanges(groupUser); FillGroupsTree(); mpeGroup.Hide(); }
protected void btnUserOK_Click(object sender, EventArgs e) { var model = createUserControl.Model; if (!ValidateUser(model)) { mpeUserForm.Show(); return; } if (String.IsNullOrWhiteSpace(model.User.Password)) { model.User.Password = "******"; } var user = HbSession.Query <UM_User>().FirstOrDefault(n => n.ID == model.User.ID); if (user == null) { user = new UM_User { ID = Guid.NewGuid(), DateCreated = DateTime.Now, }; } var converter = new UserModelEntityConverter(HbSession); converter.FillObject(user, model.User); var groups = model.Groups; if (groups != null && groups.Groups != null && groups.Groups.GroupsID != null) { foreach (var groupID in groups.Groups.GroupsID) { var groupUser = new UM_GroupUser { ID = Guid.NewGuid(), DateCreated = DateTime.Now, GroupID = groupID.Value, UserID = user.ID, AccessLevel = groups.AccessLevel }; user.GroupUsers.Add(groupUser); } } HbSession.SubmitChanges(user); FillUserGrid(); }
public static UM_GroupUser ToEntity(this GroupUserContract contract) { if (contract == null) { return(null); } var entity = new UM_GroupUser(); entity.DateChanged = contract.DateChanged; entity.DateCreated = contract.DateCreated; entity.DateDeleted = contract.DateDeleted; entity.GroupID = contract.GroupID; entity.ID = contract.ID; entity.UserID = contract.UserID; return(entity); }
public static GroupUserContract ToContract(this UM_GroupUser entity) { if (entity == null) { return(null); } var contract = new GroupUserContract(); contract.DateChanged = entity.DateChanged; contract.DateCreated = entity.DateCreated; contract.DateDeleted = entity.DateDeleted; contract.GroupID = entity.GroupID; contract.ID = entity.ID; contract.UserID = entity.UserID; return(contract); }
protected void btOK_Click(object sender, EventArgs e) { var model = registerUserControl.Model; if (model.GroupID == null) { lblError.Text = "გთხოვთ, აირჩიეთ ჯგუფი"; return; } if (String.IsNullOrWhiteSpace(model.LoginName)) { lblError.Text = "გთხოვთ, შეავსოთ სავალდებულო ველები"; return; } if (String.IsNullOrWhiteSpace(model.Email)) { lblError.Text = "გთხოვთ შეიყვანეთ ელ.ფოსტის მისამართი"; return; } if (String.IsNullOrWhiteSpace(model.Password)) { lblError.Text = "გთხოვთ შეიყვანეთ პაროლი"; return; } if (model.Password != model.ConfirmPassword) { lblError.Text = "პაროლები არ ემთხვევა ერთმანეთს"; return; } var dbUser = (from n in HbSession.Query <UM_User>() where n.DateDeleted == null && ( n.LoginName.ToLower() == model.LoginName.ToLower() || n.Email.ToLower() == model.LoginName.ToLower() ) select n).FirstOrDefault(); if (dbUser != null) { lblError.Text = "მომხმარებელი მითითებული ელ.ფოსტის მისამარტთ უკვე რეგისტრირებულია"; return; } using (var transaction = HbSession.BeginTransaction()) { dbUser = new UM_User { ID = Guid.NewGuid(), DateCreated = DateTime.Now, IsActive = false, LoginName = model.LoginName, Email = model.Email, Phone = model.Phone, FirstName = model.FirstName, LastName = model.LastName, BirthDate = model.BirthDate, Password = model.Password, UserCode = Convert.ToString(Guid.NewGuid()), PasswordExpirationDate = DateTime.Now.AddDays(30), GroupUsers = new List <UM_GroupUser>() }; HbSession.Save(dbUser); var @group = HbSession.Query <UM_Group>().FirstOrDefault(n => n.ID == model.GroupID); if (@group != null) { var groupUser = new UM_GroupUser { ID = Guid.NewGuid(), DateCreated = DateTime.Now, GroupID = @group.ID, UserID = dbUser.ID, AccessLevel = 0 }; HbSession.Save(groupUser); } try { if (ConfigUtil.UserActivationEnabled) { EmailUtil.SendActivationEmail(dbUser); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } } pnlCompleted.Visible = true; pnlUserData.Visible = false; if (ConfigUtil.UserActivationEnabled) { lblMessage.Text = "რეგისტრაცია წარმატებით დასრულდა, მომხმარებლის გასააქტიურებლად შეამოწმეთ ელ.ფოსტა"; } else { lblMessage.Text = "რეგისტრაცია წარმატებით დასრულდა, აკტივაციისთვის მიმართეთ ადმინისტრატორს"; lblAdminEmail.Text = ConfigurationManager.AppSettings["AdminEmail"]; } }