public ActionResult Edit(Guid id) { owner owner = RepoOwner.FindByPk(id); OwnerFormStub formStub = new OwnerFormStub(owner); ViewBag.name = owner.name; return(View("Form", formStub)); }
public ActionResult Edit(OwnerFormStub model) { //bool isNameExist = RepoKompetitor.Find().Where(p => p.name == model.Name && p.id != model.Id).Count() > 0; var currentDate = DateTime.Now; model.UpdatedBy = User.Identity.Name; model.UpdatedTime = currentDate; //Entah kenapa validation failed terus klo ga di buat seperti ini ModelState.Remove("CreatedBy"); ModelState.Remove("UpdatedBy"); if (ModelState.IsValid) { owner dbItem = RepoOwner.FindByPk(model.Id); if (dbItem.code != model.Code) { var checkUniqueness = RepoOwner.CheckCodeUniqueness(model.Code); if (checkUniqueness == false) { ModelState.AddModelError("Code", "Code sudah pernah digunakan sebelumnya"); ViewBag.name = dbItem.name; return(View("Form", model)); } } model.UpdateDbObject(dbItem); //Remove this line when User Identity Name is working if (dbItem.created_by == null) { dbItem.created_by = ""; } try { RepoOwner.Save(dbItem); } catch (Exception e) { return(View("Form", model)); } //message string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString(); this.SetMessage(model.Name, template); return(RedirectToAction("Index")); } else { var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); owner owner = RepoOwner.FindByPk(model.Id); ViewBag.name = owner.name; return(View("Form", model)); } }
public ActionResult Create(OwnerFormStub model) { var currentDate = DateTime.Now; model.CreatedBy = User.Identity.Name; model.CreatedTime = currentDate; model.UpdatedBy = User.Identity.Name; model.UpdatedTime = currentDate; bool checkUniqueness = RepoOwner.CheckCodeUniqueness(model.Code); if (checkUniqueness == false) { ModelState.AddModelError("Code", "Code sudah pernah digunakan sebelumnya"); } //Entah kenapa validation failed terus klo ga di buat seperti ini ModelState.Remove("CreatedBy"); ModelState.Remove("UpdatedBy"); if (ModelState.IsValid) { owner dbItem = new owner(); dbItem = model.GetDbObject(); RepoOwner.Save(dbItem); //message string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString(); this.SetMessage(model.Name, template); return(RedirectToAction("Index")); } else { //var errors = ModelState.Select(x => x.Value.Errors) // .Where(y => y.Count > 0) // .ToList(); return(View("Form", model)); } }
public ActionResult Create() { OwnerFormStub formStub = new OwnerFormStub(); return(View("Form", formStub)); }