Exemple #1
0
        public async Task <ActionResult> Create(DepartmentCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(model.Name))
                {
                    var depart = await DepartmentManager.FindDepartmentByNameAsync(model.Name);

                    if (depart == null)
                    {
                        depart = new Department()
                        {
                            Name = model.Name
                        };
                        await DepartmentManager.AddEntityAsync(depart);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "已有相同名称");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "不能为空");
                }
            }
            return(View(model));
        }