Пример #1
0
        public void SaveSessionStudent(SessionStudentModel model, int id)
        {
            if (model == null)
            {
                throw new Exception("Invalid Value");
            }
            if (string.IsNullOrEmpty(model.RoomSessionsID.ToString()))
            {
                throw new Exception("please select Room Session.");
            }
            if (string.IsNullOrEmpty(model.StudentID.ToString()))
            {
                throw new Exception("Please select Student.");
            }

            try
            {
                SessionStudent sessionStudent =
                    dbContext.SessionStudents.FirstOrDefault(
                        x => x.StudentID == id && x.ClassID == model.ClassID && x.RoomSessionsID == model.RoomSessionsID);
                if (sessionStudent == null)
                {
                    sessionStudent = new SessionStudent();
                    sessionStudent.RoomSessionsID = model.RoomSessionsID;
                    sessionStudent.StudentID      = id;
                    sessionStudent.ClassID        = model.ClassID;
                    dbContext.SessionStudents.Add(sessionStudent);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
 public void SaveSessionStudent([FromBody] SessionStudentModel model, int id)
 {
     try
     {
         sessionStudentService.SaveSessionStudent(model, id);
     }
     catch (ApiException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ApiException(ex.GetExceptionMessage());
     }
 }