public async Task <ClassRoom> CreateClassRoom(ClassRoom classRoom) { if (classRoom.Id == 0) { _context.ClassRoom.Add(classRoom); } try { await _context.SaveChangesAsync(); return(classRoom); } catch (Exception ex) { throw ex; } }
public string SaveNewClassRoom(ClassRoom classRoom) { var classRoomExist = _context.ClassRoom.Where(r => r.BranchClassId == classRoom.BranchClassId && r.RoomId == classRoom.RoomId && r.SectionId == classRoom.SectionId && r.TeacherId == classRoom.TeacherId ).FirstOrDefault(); if (classRoomExist == null) { var bc = _context.BranchClass.Where(r => r.Id == classRoom.BranchClassId).FirstOrDefault(); var isinRoom = _context.Room.Where(w => w.BranchId == bc.BranchId && w.Id == classRoom.RoomId).FirstOrDefault(); if (isinRoom != null) { var teacherExist = _context.ClassRoom.Where(r => r.TeacherId == classRoom.TeacherId).FirstOrDefault(); if (teacherExist == null) { var sessionExist = _context.ClassRoom.Where(r => r.SectionId == classRoom.SectionId).FirstOrDefault(); if (sessionExist == null) { var isinSession = _context.Section.Where(w => w.BranchClassId == classRoom.BranchClassId && w.Id == classRoom.SectionId).FirstOrDefault(); if (isinSession != null) { _context.ClassRoom.Add(classRoom); try { _context.SaveChanges(); return("Successfully Created New Class Room."); } catch (Exception ex) { throw ex; } } return("This Session are not in Branch class."); } return("A Class Room Contain only one Session."); } return("A Teacher not able to more then one class teacher."); } return("This Room not into this branch."); } return("This Class Room Already Exist."); }