public IActionResult Save(ProductFormViewModel viewModel) { // sample scenario: same name checking in the database if (viewModel.Title.ToLower() == "abc") { return(FormResult.CreateWarningResult("'Abc' is already exist in the database.")); } try { //... return(FormResult.CreateSuccessResult("Product saved.")); // Success form result with redirect //return FormResult.CreateSuccessResult("Product saved.", Url.Action("List", "Home")); // Success form result with redirect with delay time (15 seconds) // The message will be on the screen for 15 seconds. //return FormResult.CreateSuccessResult("Product saved.", Url.Action("List", "Home"), 15000); } catch { return(FormResult.CreateErrorResult("An error occurred!")); } // CreateSuccessResult Called this usage: //return Json(new FormResult(FormResultStatus.Success) //{ // Message = "Product saved." //}); }
public IActionResult Save(Student student) { if (student.IsNew) { if (_studentList.Any(x => x.StudentNumber == student.StudentNumber)) { return(FormResult.CreateWarningResult("Aynı öğrenci numarasını kullanan başka bir öğrenci vardır.")); } _studentList.Add(student); return(FormResult.CreateSuccessResult("Öğrenci eklendi.", Url.Action("List", "Home"))); } else { var currentStudent = _studentList.Single(x => x.Id == student.Id); currentStudent = student; return(FormResult.CreateSuccessResult("Öğrenci güncellendi.", Url.Action("List", "Home"))); } }