public async Task <ActionResult> CreateGrade(GradeCreateViewModel model) { if (ModelState.IsValid) { if (model.GradeNumber == 0) { ModelState.AddModelError("", "GradeNumber不能为0"); } else { var grade = await InstitutionManager.FindGradeByGradeNumberAsync(model.GradeNumber); if (grade == null) { await InstitutionManager.AddGradeAsync(model.GradeNumber); return(RedirectToAction("AllGrade")); } else { ModelState.AddModelError("", "已有相同名称"); } } } return(View(model)); }
public IActionResult Create() { GradeCreateViewModel gradeCreateViewModel = new GradeCreateViewModel(); gradeCreateViewModel.SelectListItems = PopulateCoursesDropDownList(); return(View("Create", gradeCreateViewModel)); }
public IActionResult Create(GradeCreateViewModel gradeCreateViewModel) { if (ModelState.IsValid) { var createGradeResponse = _gradeService.Create(new CreateGradeRequest { CourseID = gradeCreateViewModel.GradeView.CourseID, GradeNumber = gradeCreateViewModel.GradeView.GradeNumber, Value = gradeCreateViewModel.GradeView.Value, Note = gradeCreateViewModel.GradeView.Note, }); if (createGradeResponse.IsSuccess == true) { return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Create Grade Error"); gradeCreateViewModel.SelectListItems = PopulateCoursesDropDownList(); return(View("Create", gradeCreateViewModel)); } } else { gradeCreateViewModel.SelectListItems = PopulateCoursesDropDownList(); ModelState.AddModelError(string.Empty, "Invalid Input Error"); return(View("Create", gradeCreateViewModel)); } }
public async Task <IActionResult> Edit(GradeCreateViewModel model) { if (ModelState.IsValid) { var storeobj = _unitofWork.grade.Get(model.id); if (storeobj == null) { TempData["error"] = "Record Not Found"; return(NotFound()); } storeobj.id = model.id; storeobj.type = model.type; _unitofWork.grade.Update(storeobj); bool res = _unitofWork.Save(); TempData["success"] = "Record Update successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public async Task <IActionResult> Create(GradeCreateViewModel model) { if (ModelState.IsValid) { var obj = new Grade { id = model.id , type = model.type , isdeleted = false , isactive = false }; _unitofWork.grade.Add(obj); bool res = _unitofWork.Save(); TempData["success"] = "Record Save successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public IActionResult Edit(int id) { var objcategory = _unitofWork.grade.Get(id); if (objcategory == null) { return(NotFound()); } var model = new GradeCreateViewModel() { id = objcategory.id, type = objcategory.type, }; return(View(model)); }
public async Task <ActionResult> Create(GradeCreateViewModel model) { if (ModelState.IsValid) { var grade = await GradeManager.FindGradeByGradeNumberAsync(model.GradeNumber); if (grade == null) { var instance = new Grade() { GradeNum = model.GradeNumber }; await GradeManager.AddEntityAsync(instance); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "已有相同名称"); } } return(View(model)); }
public IActionResult Create() { var model = new GradeCreateViewModel(); return(View(model)); }