コード例 #1
0
        public ActionResult Create(CarModelFormStub model)
        {
            //bool isNameExist = RepoCarModel.Find().Where(p => p.name == model.Name).Count() > 0;

            if (ModelState.IsValid)
            {
                car_model dbItem = new car_model();
                dbItem = model.GetDbObject(dbItem);

                try
                {
                    RepoCarModel.Save(dbItem);
                }
                catch (Exception e)
                {
                    model.FillCarBrandOptions(RepoCarBrand.FindAll());
                    return(View("Form", model));
                }

                //message
                string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString();
                this.SetMessage(model.Name, template);

                return(RedirectToAction("Index"));
            }
            else
            {
                model.FillCarBrandOptions(RepoCarBrand.FindAll());
                return(View("Form", model));
            }
        }