예제 #1
0
        public ActionResult Add(Location model)
        {
            if (ModelState.IsValid)
            {
                //more validation
                bool IsExist = RepoLocation.IsExist(model.Code);

                if (IsExist)
                {
                    ModelState.AddModelError("Code", "Code sudah terdaftar");
                    return(View("Form", model));
                }

                if (model.Type != "Provinsi")
                {
                    if (!model.ParentId.HasValue)
                    {
                        ModelState.AddModelError("ParentId", "Parent harus diisi");
                        return(View("Form", model));
                    }
                }

                Context.Location dbitem = new Context.Location();
                model.setDb(dbitem);

                RepoLocation.save(dbitem);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }