Example #1
0
        public async Task <IActionResult> Update(UpdateLessonBindingModel model)
        {
            bool areSeatsCorrect = this.lessonsUsersService.CheckIfSeatsValueIsPositiveBasedOnAlreadyEnrolledUsers(model.Id, model.Seats);

            if (areSeatsCorrect == false)
            {
                IEnumerable <IdNameViewModel> subjects = this.subjectsService.GetAll();
                ViewBag.Subjects = subjects;

                string errorNotificationMessage = string.Format(
                    NotificationsConstants.InvalidSeatsValue,
                    this.lessonsUsersService.SeatsTakenInLesson(model.Id)
                    );
                this.TempData[NotificationsConstants.ErrorNotification] = errorNotificationMessage;

                return(this.View(model));
            }

            bool isUpdated = await this.lessonsService.UpdateAsync(model);

            if (isUpdated == false)
            {
                return(this.BadRequest());
            }

            return(this.RedirectToAction("index"));
        }
Example #2
0
        public IActionResult Update(int id)
        {
            UpdateLessonBindingModel lesson = this.lessonsService.GetByIdForUpdateMethod(id);

            IEnumerable <IdNameViewModel> subjects = this.subjectsService.GetAll();

            bool isLessonNull     = lesson == null;
            bool areSubjectsEmpty = subjects.Count() == 0;

            if (isLessonNull || areSubjectsEmpty)
            {
                return(this.RedirectToAction("index"));
            }

            ViewBag.Subjects = subjects;

            return(this.View(lesson));
        }
Example #3
0
        public UpdateLessonBindingModel GetByIdForUpdateMethod(int id)
        {
            UpdateLessonBindingModel lesson = this.dbContext.Lessons
                                              .Select(l => new UpdateLessonBindingModel
            {
                Id               = l.Id,
                Name             = l.Name,
                Seats            = l.Seats,
                Hours            = l.Hours,
                IsOnline         = l.IsOnline,
                PresentationDate = l.PresentationDate,
                SubjectId        = l.SubjectId,
            })
                                              .Where(l => l.Id == id)
                                              .SingleOrDefault();

            return(lesson);
        }
Example #4
0
        public async Task <bool> UpdateAsync(UpdateLessonBindingModel model)
        {
            Lesson lesson = this.GetLessonById(model.Id);

            bool isLessonNull = lesson == null;

            if (isLessonNull)
            {
                return(false);
            }

            lesson.Name             = model.Name;
            lesson.IsOnline         = model.IsOnline;
            lesson.Hours            = model.Hours;
            lesson.PresentationDate = model.PresentationDate;
            lesson.Seats            = model.Seats;
            lesson.SubjectId        = model.SubjectId;

            this.dbContext.Lessons.Update(lesson);
            await this.dbContext.SaveChangesAsync();

            return(true);
        }