protected void gridUsers_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { try { SessionManager.IsEditFormCreated = false; //insert user User cc = this.CollectNewDataFromForm(0, null, e.NewValues, true); int insertedId = BuUser.InsertUser(cc); //update rights List <int> selectedRights = GetRightsFromList(); foreach (KeyValuePair <int, int> pair in SessionManager.CheckBoxListHelper) { BuUser.UpdateRightsRelation(insertedId, pair.Value, selectedRights.Contains(pair.Key)); } e.Cancel = true; gridUsers.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
/// <summary> /// Insert new User. /// </summary> /// <param name="user"></param> public static int InsertUser(Canon.Data.User user) { int result = ((CanonMembershipProvider)Membership.Provider).CreateUser(user); CleanUsersCache(); return(result); }
protected void gridUsers_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { try { SessionManager.IsEditFormCreated = false; int keyToUpdate = int.Parse(e.Keys[0].ToString()); //update user User cc = this.CollectNewDataFromForm(keyToUpdate, e.OldValues, e.NewValues, false); BuUser.UpdateUser(cc, e.OldValues["UserName"].ToString()); //update rights List <int> selectedRights = GetRightsFromList(); foreach (KeyValuePair <int, int> pair in SessionManager.CheckBoxListHelper) { BuUser.UpdateRightsRelation(keyToUpdate, pair.Value, selectedRights.Contains(pair.Key)); } e.Cancel = true; gridUsers.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
/// <summary> /// Get user by ID. /// </summary> /// <param name="userID"></param> /// <returns></returns> public Canon.Data.User GetUserByID(int userID) { Canon.Data.User user = ((CanonMembershipProvider)Membership.Provider).GetUserByID(userID); if (user == null) { Logger.Log("User with specified ID doesn't exists in database. User ID:'" + userID + "'", LogLevel.Warn); } return(user); }
/// <summary> /// Delete user by id. /// </summary> /// <param name="userId"></param> public static void DeleteUserById(int userId) { //user deletion CanonDataContext db = Cdb.Instance; Canon.Data.User user = db.Users.First(u => u.UserId == userId); //db.Users.DeleteOnSubmit(user); user.IsForbidden = true; db.SubmitChanges(); CleanUsersCache(); }
/// <summary> /// Change email with the password to the user. /// </summary> /// <param name="email"></param> public static bool SendRemindPasswordEmail(string email) { Canon.Data.User user = GetUserByEmail(email); if (user != null) { string password = ((CanonMembershipProvider)Membership.Provider).ChangePassword(user.UserId); string changePasswordUrl = String.Concat( HttpContext.Current.Request.Url.Scheme, "://", HttpContext.Current.Request.Url.Host, ":", HttpContext.Current.Request.Url.Port, HttpContext.Current.Request.ApplicationPath, "/Default.aspx?changepassword=yes"); try { EmailGateway.Send( String.Empty, email, Utilities.GetResourceString("Common", "EmailRemindEmailSubject"), String.Format(Utilities.GetResourceString("Common", "EmailRemindEmailText"), password, changePasswordUrl, user.UserName), new List <Attachment>(), true); } catch { return(false); } return(true); } return(false); }
/// <summary> /// Update user. /// </summary> /// <param name="user"></param> /// <param name="previousLogin"></param> public static void UpdateUser(Canon.Data.User user, string previousLogin) { ((CanonMembershipProvider)Membership.Provider).UpdateUser(user, previousLogin); CleanUsersCache(); }