public ActionResult RestoreSave(Employee record, string returnUrl = "HREmployeeIndex") { ViewBag.Path1 = "员工管理"; //检查记录在权限范围内 var result = Common.GetHREmployeeQuery(db, true).Where(a => a.IsDeleted == true).Where(a => a.Id == record.Id).SingleOrDefault(); if (result == null) { Common.RMError(this); return Redirect(Url.Content(returnUrl)); } //end try { result.IsDeleted = false; db.PPSave(); Common.RMOk(this, "记录:" + result + "恢复成功!"); return Redirect(Url.Content(returnUrl)); } catch (Exception e) { Common.RMOk(this, "记录" + result + "恢复失败!" + e.ToString()); } return Redirect(Url.Content(returnUrl)); }
public ActionResult CreateCandidateSave(CreateCandidate model, string returnUrl = "CandidateIndex") { ViewBag.Path1 = "用户"; if (ModelState.IsValid) { // 尝试注册用户 try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { // transaction string tmpPassword = GenerateRandomPassword(6); WebSecurity.CreateUserAndAccount(model.UserName, tmpPassword, new { Mail = model.Mail, IsDeleted = false }); Roles.AddUsersToRoles(new[] { model.UserName }, new[] { "Candidate" }); var user = db.User.Where(a => a.Name == model.UserName).Single(); var employee = new Employee { UserId = user.Id, User = user, EmployeeStatus = EmployeeStatus.新增未通知, ChineseName = model.ChineseName, ClientId = model.ClientId }; db.Employee.Add(employee); db.PPSave(); Common.MailTo(model.Mail, "E-Onboarding新建用户通知", "您的用户名:" + model.UserName + ",密码:" + tmpPassword + ",登陆网址:" + "<a href='" + Url.Action("Login", "Account", null, "http") + "'>登陆E-Onboarding</a>"); scope.Complete(); // end transaction } Common.RMOk(this, "记录:'" + model.UserName + "'新建成功!"); return Redirect(Url.Content(returnUrl)); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 ViewBag.ReturnUrl = returnUrl; return View("CreateCandidate", model); }