public async Task <IActionResult> Edit(int id, [Bind("GradeSubjectId,GradeId,SubjectId,HoursNumber")] GradeSubject gradeSubject)
        {
            if (id != gradeSubject.GradeSubjectId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gradeSubject);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GradeSubjectExists(gradeSubject.GradeSubjectId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GradeId"]   = new SelectList(_context.GradesInfo, "GradeId", "GradeName", gradeSubject.GradeId);
            ViewData["SubjectId"] = new SelectList(_context.Subjects, "SubjectId", "SubjectName", gradeSubject.SubjectId);
            return(View(gradeSubject));
        }
        public async Task <IActionResult> Create([Bind("GradeSubjectId,GradeId,SubjectId,HoursNumber")] GradeSubject gradeSubject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gradeSubject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GradeId"]   = new SelectList(_context.GradesInfo, "GradeId", "GradeName", gradeSubject.GradeId);
            ViewData["SubjectId"] = new SelectList(_context.Subjects, "SubjectId", "SubjectName", gradeSubject.SubjectId);
            return(View(gradeSubject));
        }
Example #3
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 #4
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 #5
0
 public bool DeleteGradeSubject(long gradeSubjectId)
 {
     try
     {
         GradeSubject gradeSubject = gradeSubjectRepository.Find(gradeSubjectId);
         gradeSubjectRepository.Remove(gradeSubject);
         unitOfWork.Save();
         return(true);
     }
     catch (DbUpdateException ex)
     {
         Logger.Warn(ex.Message, ex);
         throw;
     }
     catch (Exception ex)
     {
         Logger.Warn(ex.Message, ex);
         throw;
     }
 }