예제 #1
0
 public ActionResult CreateSave(Client model, string returnUrl = "Index")
 {
     ViewBag.Path1 = "参数设置";
     //检查记录在权限范围内
     //end
     if (ModelState.IsValid)
     {
         try
         {
             db.Client.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);
 }
예제 #2
0
        public ActionResult RestoreSave(Client record, string returnUrl = "Index")
        {
            ViewBag.Path1 = "参数设置";
            //检查记录在权限范围内
            var result = Common.GetClientQuery(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));
        }
예제 #3
0
        public ActionResult EditSave(Client model, string returnUrl = "Index")
        {
            ViewBag.Path1 = "参数设置";
            //检查记录在权限范围内
            var result = Common.GetClientQuery(db).Where(a => a.Id == model.Id).SingleOrDefault();
            if (result == null)
            {
                Common.RMError(this);
                return Redirect(Url.Content(returnUrl));
            }
            //end

            if (ModelState.IsValid)
            {
                try
                {
                    result.Name = model.Name;
                    result.HRAdminId = model.HRAdminId;
                    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("Edit", model);
        }