Example #1
0
 private bool ValidateGradeSubjectModel(GradeSubjectViewModel gradeSubject)
 {
     if (gradeSubject.GradeId == 0 || gradeSubject.SubjectAreaId == 0)
     {
         return(false);
     }
     return(true);
 }
        public void TestMethod_ShouldSaveGradeSubject()
        {
            var gradeSubject = new GradeSubjectViewModel
            {
                SubjectAreaId = 4,
                GradeId       = 14
            };
            var isGradeSubjectSaved = _gradeSubjectService.SaveGradeSubject(gradeSubject);

            Assert.IsTrue(isGradeSubjectSaved);
        }
        public HttpResponseMessage UpdateGradeSubject(GradeSubjectViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ""));
            }

            try
            {
                var isGradeSubjectUpdated = _gradeSubjectService.UpdateGradeSubject(model);
                return(Request.CreateResponse(HttpStatusCode.OK, isGradeSubjectUpdated));
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw;
            }
        }
Example #4
0
        public IActionResult EditGrade(int Id)
        {
            GradeSubjectViewModel gsvm = new GradeSubjectViewModel
            {
                SubjectList = Db.Subjects
                              .Where(s => s.UserIdSubject == this.User.FindFirstValue(ClaimTypes.NameIdentifier))
                              .ToList(),

                Grade = Db.Grades
                        .Where(s => s.Id == Id)
                        .Where(g => g.UserIdGrade == this.User.FindFirstValue(ClaimTypes.NameIdentifier))
                        .FirstOrDefault()
            };

            if (Request.Method == "POST")
            {
                if (ModelState.IsValid)
                {
                    var model = Db.Grades.Where(s => s.Id == Id).FirstOrDefault();

                    model.Grade       = Decimal.Parse(Request.Form["Grade.Grade"]);
                    model.Coefficient = Decimal.Parse(Request.Form["Grade.Coefficient"]);

                    if (Request.Form["Grade.IsExam"] == "false")
                    {
                        model.IsExam = Convert.ToBoolean("False");
                    }
                    else
                    {
                        model.IsExam = Convert.ToBoolean("True");
                    }

                    model.Subjectid = Int32.Parse(Request.Form["Grade.Subject.Id"]);

                    Db.Grades.Update(model);
                    Db.SaveChanges();
                    return(RedirectToAction("Grade"));
                }
            }

            return(View(gsvm));
        }
Example #5
0
 public bool SaveGradeSubject(GradeSubjectViewModel gradeSubject)
 {
     try
     {
         if (ValidateGradeSubjectModel(gradeSubject))
         {
             var s = new GradeSubject();
             s.SubjectAreaId = gradeSubject.SubjectAreaId;
             s.GradeId       = gradeSubject.GradeId;
             gradeSubjectRepository.Add(s);
             unitOfWork.Save();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Warn(ex.Message, ex);
         throw;
     }
 }
Example #6
0
 public bool UpdateGradeSubject(GradeSubjectViewModel model)
 {
     try
     {
         if (ValidateGradeSubjectModel(model))
         {
             var gradeSubject = new GradeSubject();
             gradeSubject.SubjectAreaId = model.SubjectAreaId;
             gradeSubject.GradeId       = model.GradeId;
             gradeSubjectRepository.Update(gradeSubject);
             unitOfWork.Save();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Warn(ex.Message, ex);
         throw;
     }
 }
Example #7
0
        public IActionResult CreateGrade(GradeSubjectViewModel model)
        {
            GradeSubjectViewModel gsvm = new GradeSubjectViewModel
            {
                SubjectList = Db.Subjects
                              .Where(s => s.UserIdSubject == this.User.FindFirstValue(ClaimTypes.NameIdentifier))
                              .ToList()
            };

            if (Request.Method == "POST")
            {
                if (ModelState.IsValid)
                {
                    model.Grade.UserIdGrade = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                    Db.Grades.Add(model.Grade);
                    Db.SaveChanges();
                    return(RedirectToAction("Grade"));
                }
            }
            return(View(gsvm));
        }
        public HttpResponseMessage SaveGradeSubject(GradeSubjectViewModel gradeSubject)
        {
            var isGradeSubjectSaved = _gradeSubjectService.SaveGradeSubject(gradeSubject);

            return(Request.CreateResponse(HttpStatusCode.OK, isGradeSubjectSaved));
        }