/// <summary> /// 添加、修改数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOK_Click(object sender, EventArgs e) { //验证表单数据:页面中文本框 if (this.CheckForm() == false) { CloseDivImplementation(); return; } RoleEO roleEO = new RoleEO(); if (Request.QueryString["State"] == "U") { roleEO = roleManage.GetRoleByPK(Request.QueryString["Rlid"]); } roleEO.RlName = this.txtRlName.Text.Trim(); roleEO.PfId = this.ddlPf.SelectedValue; roleEO.RlState = this.rblState.SelectedValue; //创建角色信息 if (Request.QueryString["State"] == "A") { //判断角色名称是否存在 if (this.CheckRoleName() == false) { this.divAlert.Visible = true; this.lblAlert.Text = this.ddlPf.SelectedItem.Text + Resources.Resource.Middle_role_name + this.txtRlName.Text.Trim() + Resources.Resource.Already_exist; CloseDivImplementation(); return; } string id = GetBigGuid(); roleEO.RlId = id; roleEO.RlDel = "0"; roleEO.RlAddUser = GetUserID(); roleEO.RlAddTime = DateTime.Now; if (roleManage.AddRole(roleEO) > 0) { SetGameChannel(id); //插入操作日志 InsertLog(Resources.Resource.Create_role, string.Format("rolename:{0},id:{1}", roleEO.RlName, roleEO.RlId), 4, GetPlatformIdByValue(1)); CloseDivImplementation(); Jswork.Alert(Resources.Resource.Role_information_creation_success, "RoleList.aspx"); } else { this.divAlert.Visible = true; this.lblAlert.Text = Resources.Resource.Role_information_creation_failed;//"角色信息创建失败"; } } //修改角色 if (Request.QueryString["State"] == "U") { //修改时判断角色名称是否存在 if (hfRoleName.Value != this.txtRlName.Text.Trim()) { //判断角色名称是否存在 if (this.CheckRoleName() == false) { this.divAlert.Visible = true; this.lblAlert.Text = this.ddlPf.SelectedItem.Text + Resources.Resource.Middle_role_name + this.txtRlName.Text.Trim() + Resources.Resource.Already_exist; CloseDivImplementation(); return; } } if (roleManage.EditRole(roleEO) > 0) { SetGameChannel(roleEO.RlId); //插入操作日志 InsertLog(Resources.Resource.Modify_role, string.Format("rolename:{0},id:{1}", roleEO.RlName, roleEO.RlId), 5, GetPlatformIdByValue(1)); CloseDivImplementation(); Jswork.Alert(Resources.Resource.Role_information_change_success, "RoleList.aspx"); } else { this.divAlert.Visible = true; this.lblAlert.Text = Resources.Resource.Role_information_modification_failed;//"角色信息修改失败"; } } CloseDivImplementation(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { //check the code var db = new JustFoodDBEntities(); Code code = db.Codes.FirstOrDefault(m => m.Code1 == model.Code); if (code == null) { ModelState.AddModelError(model.Code, "Your given code is not valid."); return(View(model)); } // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); //create new user. if (code.Percentage == null) { code.Percentage = 0; } if (code.Salary == null) { code.Salary = 0; } var user = new User { LogName = model.UserName, Name = model.PersonName, IsEmployee = code.IsEmployee, IsOwner = code.IsOwner, IsAccessToAdmin = code.IsAccessToAdmin, Percentage = (double)code.Percentage, Salary = (double)code.Salary, Email = model.Email, IsValidEmail = true }; //there is no need to keep the used code. db.Entry(code).State = EntityState.Deleted; db.Users.Add(user); db.SaveChanges(); //Roles.CreateRole(""); var roleManager = new RoleManage(); string role = ""; if (user.IsAccessToAdmin) { role = RoleNames.Admin; } else if (user.IsEmployee) { role = RoleNames.SalesMan; } roleManager.AddRole(user.LogName, role); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }