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));
        }
Exemple #2
0
        public IActionResult Create()
        {
            GradeCreateViewModel gradeCreateViewModel = new GradeCreateViewModel();

            gradeCreateViewModel.SelectListItems = PopulateCoursesDropDownList();
            return(View("Create", gradeCreateViewModel));
        }
Exemple #3
0
        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));
            }
        }
Exemple #4
0
        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());
            }
        }
Exemple #5
0
        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());
            }
        }
Exemple #6
0
        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));
        }
Exemple #8
0
        public IActionResult Create()
        {
            var model = new GradeCreateViewModel();

            return(View(model));
        }