public ActionResult CreateSave(BudgetCenter model, string returnUrl = "Index") { ViewBag.Path1 = "参数设置"; if (ModelState.IsValid) { try { db.BudgetCenter.Add(model); db.PPSave(); Common.RMOk(this, "记录:'" + model.Name + "'新建成功!"); return(Redirect(Url.Content(returnUrl))); } catch (Exception e) { if (e.InnerException.Message.Contains("Cannot insert duplicate key row")) { ModelState.AddModelError(string.Empty, "相同名称的记录已存在,保存失败!"); } } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 ViewBag.ReturnUrl = returnUrl; return(View("Create", model)); }
public ActionResult CreateSave(Supplier model, string returnUrl = "Index") { ViewBag.Path1 = "参数设置"; //检查记录在权限范围内 //end if (ModelState.IsValid) { try { db.Supplier.Add(model); db.PPSave(); Common.RMOk(this, "记录:" + model + "新建成功!"); return(Redirect(Url.Content(returnUrl))); } catch (Exception e) { if (e.InnerException.Message.Contains("Cannot insert duplicate key row")) { ModelState.AddModelError(string.Empty, "相同名称的记录已存在,保存失败!"); } } } ViewBag.ReturnUrl = returnUrl; return(View("Create", model)); }
public ActionResult Create(Education education) { if (ModelState.IsValid) { try { db.Education.Add(education); db.PPSave(); return(RedirectToAction("Index")); } catch (DbUpdateException ex) { if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key row")) { ModelState.AddModelError(string.Empty, "相同名称的记录已存在,保存失败!"); } } } ViewBag.EmployeeId = new SelectList(db.Employee, "Id", "Name", education.EmployeeId); return(View(education)); }
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)); }
public ActionResult DeleteSave(int id, string returnUrl = "HREmployeeIndex") { ViewBag.Path1 = "员工管理"; //检查记录在权限范围内 var result = Common.GetHREmployeeQuery(db).Where(a => a.Id == id).SingleOrDefault(); if (result == null) { Common.RMError(this); return(Redirect(Url.Content(returnUrl))); } //end var removeName = result.ToString(); try { db.Employee.Remove(result); db.PPSave(); Common.RMOk(this, "记录:" + removeName + "删除成功!"); return(Redirect(Url.Content(returnUrl))); } catch (Exception e) { if (e.InnerException.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint")) { Common.RMError(this, "记录" + removeName + "被其他记录引用, 不能删除!"); } else { Common.RMError(this, "记录" + removeName + "删除失败!" + e.ToString()); } } return(Redirect(Url.Content(returnUrl))); }