[HttpGet("{id}")] // api/lesson/735 public async Task <ActionResult <LessonOutputModel> > LessonGetById(int id) { Lesson lesson = await lessonStorage.GetLessonById(id); if (lesson == null) { return(BadRequest($"Lesson {id} does not exist")); } return(Ok(LessonMapper.ToOutputModel(lesson))); }
[HttpPost] // api/lesson public async Task <ActionResult <int> > AddOrUpdateLesson([FromBody] LessonInputModel inputModel) { Lesson lesson = LessonMapper.ToDataModel(inputModel); if (lesson == null) { return(BadRequest("Model is empty")); } return(Ok(await lessonStorage.AddOrUpdateLesson(lesson))); }
public List <DTOLesson> GetAll() { List <DTOLesson> LessonsList = new List <DTOLesson>(); foreach (Lesson item in UnitOfWork.LessonRepository.GetAll()) { LessonsList.Add(LessonMapper.GetDTOLesson(item)); } return(LessonsList); }
public IActionResult AllLessons() { var lessons = _dbContext.Lessons .Include(a => a.Teacher) .Include(a => a.Technology); List <LessonInfoViewModel> model = new List <LessonInfoViewModel>(); foreach (var item in lessons) { model.Add(LessonMapper.Mapping(item)); } return(View(model)); }
[HttpPost("with-journals")] //api/lesson/with-journals public async Task <ActionResult <int?> > AddLessonWithJournals([FromBody] LessonInputModel inputModel) { if (inputModel == null) { return(BadRequest("Model is empty")); } Lesson dataModel = LessonMapper.ToDataModel(inputModel); if (dataModel == null) { return(BadRequest("Failed to add an object")); } return(Ok(await lessonStorage.AddJournals(dataModel))); }
public Lesson update(Lesson newLesson) { Lesson oldLesson = _repository.get(newLesson.IDLesson); if (oldLesson == null) { return(null); } oldLesson = LessonMapper.mapModel(oldLesson, newLesson); if (oldLesson == null) { return(null); } _repository.update(oldLesson); return(oldLesson); }
public int Update(DTOLesson dtoLesson, out string ErrorText) { Lesson entityLesson = LessonMapper.GetEntityLesson(dtoLesson); ErrorText = ""; //Controlli da effettuare prima di salvare la lezione //Controllo se ci sono già lezioni dello stesso percorso in quel giorno escludendo se stessa if (UnitOfWork.LessonRepository.GetAll().Where(lesson => lesson.Id != entityLesson.Id && lesson.IdCourse == entityLesson.IdCourse && (lesson.StartDate.GetValueOrDefault().Date == entityLesson.StartDate.GetValueOrDefault().Date)).Count() > 0) { ErrorText = "Impossibile salvare la lezione. Un'altra lezione per questo percorso è organizzata per quella giornata."; return(-1); } //Controllo se la stanza è già stata prenotata quel giorno escludendo se stessa if (UnitOfWork.LessonRepository.GetAll().Where(lesson => lesson.Id != entityLesson.Id && lesson.IdRoom == dtoLesson.IdRoom && (lesson.StartDate.GetValueOrDefault().Date == entityLesson.StartDate.GetValueOrDefault().Date)).Count() > 0) { ErrorText = "Impossibile salvare la lezione. La sala scelta è già occupata da un'altra lezione in quella data."; return(-1); } //Prima elimino tutte le relazioni tra lezioni e studenti foreach (LessonsResource item in UnitOfWork.LessonsResourceRepository.GetAll().Where(link => link.IdLesson == dtoLesson.Id)) { UnitOfWork.LessonsResourceRepository.Delete(item); } foreach (DTOResource item in dtoLesson.Students) { UnitOfWork.LessonsResourceRepository.Add(new LessonsResource { IdLesson = entityLesson.Id, IdStudent = item.Id }); } UnitOfWork.LessonRepository.Update(entityLesson); UnitOfWork.Commit(); return(entityLesson.Id); }
public DTOLesson GetById(int Id) { return(LessonMapper.GetDTOLesson(UnitOfWork.LessonRepository.GetByID(Id))); }
public async Task <ActionResult <List <LessonOutputModel> > > LessonGetAll() { List <Lesson> lessons = await lessonStorage.GetAllLesson(); return(Ok(LessonMapper.ToOutputModels(lessons))); }