public RoomSessionsModel GetRoomSessions(int id) { RoomSessionsModel model = new RoomSessionsModel(); try { RoomSession roomSessions = dbContext.RoomSessions.FirstOrDefault(x => x.SectionID == id); try { model.SessionID = roomSessions.SessionID; model.ClassID = roomSessions.ClassID; model.SectionID = roomSessions.SectionID; //model.CourseID = roomSessions.CourseID; dbContext.SaveChanges(); } catch { throw new ApiException("This room session does not exist"); } } catch (Exception exception) { throw new Exception(exception.Message); } return(model); }
public void SaveRoomSessions([FromBody] RoomSessionsModel model) { try { roomSessionsService.SaveRoomSessions(model); } catch (ApiException) { throw; } catch (Exception exception) { throw new ApiException(exception.GetExceptionMessage()); } }
public void SaveRoomSessions(RoomSessionsModel model) { if (model == null) { throw new Exception("Invalid Value"); } if (string.IsNullOrEmpty(model.SessionID.ToString())) { throw new Exception("Please Select Session"); } if (string.IsNullOrEmpty(model.ClassID.ToString())) { throw new Exception("Please Select Class"); } if (string.IsNullOrEmpty(model.SectionID.ToString())) { throw new Exception("Please Select Section"); } if (string.IsNullOrEmpty(model.CourseID.ToString())) { throw new Exception("Please Select Course"); } try { foreach (var course in model.CourseID) { RoomSession roomSessions = new RoomSession(); roomSessions.SessionID = model.SessionID; roomSessions.ClassID = model.ClassID; roomSessions.SectionID = model.SectionID; roomSessions.CourseID = course; roomSessions.StartDate = DateTime.Now; dbContext.RoomSessions.Add(roomSessions); } dbContext.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } }