Beispiel #1
0
        public ActionResult Supplier(SupplierViewModel model)
        {
            //验证模型
            if (ModelState.IsValid)
            {
                //判断名称与编码重复
                var db = new DbEntities <Supplier>().SimpleClient;

                if (db.IsAny(su => su.SupplierName == model.SupplierName || su.SupplierNo == model.SupplierNo))
                {
                    ModelState.AddModelError("SupplierCode", "供应商名称或者编码已存在");
                }
                else
                {
                    if (new IdentityAuth().GetCurUserID(HttpContext, out int curUserID))
                    {
                        //转换为实体
                        Supplier entity = model.InitAddSupplier(curUserID);

                        if (new DbEntities <Supplier>().SimpleClient.Insert(entity))
                        {
                            TempData["Msg"] = $"供应商 {model.SupplierName} 添加成功";
                            return(RedirectToAction("Supplier", "Materials"));
                        }
                        else
                        {
                            TempData["Msg"] = "添加失败";
                        }
                    }
                }
            }
            return(View());
        }