Пример #1
0
        public async Task <IActionResult> Create(ScheduleCreateViewModel inputModel)
        {
            var schedule = this.scheduleRepository.All().FirstOrDefault(x => x.Name == inputModel.Name);

            if (schedule != null)
            {
                this.TempData["Message"] = GlobalConstants.Messages.AlreadyExist;
                return(View(inputModel));
            }

            if (this.ModelState.IsValid)
            {
                schedule = new Schedule
                {
                    Name         = inputModel.Name,
                    NumberOfDays = inputModel.NumberOfDays,
                    CreatedFrom  = "Not Implemented User",
                };
                await this.scheduleRepository.AddAsync(schedule);

                await this.scheduleRepository.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

            return(View(inputModel));
        }
        public IActionResult CreateSchedule()
        {
            ScheduleCreateViewModel model  = new ScheduleCreateViewModel();
            IEnumerable <Movie>     movies = _movieRepository.GetAllMovies();

            foreach (var item in movies.ToList())
            {
                model.Movies.Add(item);
            }
            return(View(model));
        }
        public async Task <IHttpActionResult> PostSchedule(ScheduleCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var schedule = await _schedules.Add(new Schedule
            {
                TimeStarted  = model.TimeStarted,
                TimeFinished = model.TimeFinished,
                DayOfWeek    = model.DayOfWeek
            });

            return(CreatedAtRoute("DefaultApi", new { id = schedule.Id }, (ScheduleResultViewModel)schedule));
        }
Пример #4
0
        public async Task <ScheduleCreateViewModel> GetCreateViewModel(int schoolId)
        {
            var schoolSubjects = await this.data.Subjects.Where(s => s.SchoolId == schoolId)
                                 .Select(s => new SubjectModel
            {
                Id       = s.Id,
                Name     = s.Name,
                SchoolId = s.Id
            })
                                 .ToListAsync();

            var resultModel = new ScheduleCreateViewModel
            {
                Subjects = schoolSubjects
            };

            return(resultModel);
        }
        public async Task <IActionResult> Create(ScheduleCreateViewModel inputModel)
        {
            if (this.ScheduleExists <ScheduleCreateViewModel>(inputModel.Name, null))
            {
                this.TempData["Message"] = GlobalConstants.Messages.AlreadyExist;
                return(this.View(inputModel));
            }

            var name         = inputModel.Name;
            var numberOfDays = inputModel.NumberOfDays;

            if (this.ModelState.IsValid)
            {
                await this.schedulesService.CreateAsync(name, numberOfDays, this.Creator());

                return(this.RedirectToAction("Index"));
            }

            return(this.View(inputModel));
        }
        public IActionResult CreateSchedule(ScheduleCreateViewModel model)
        {
            ScheduleCreateViewModel originalModel = new ScheduleCreateViewModel();
            IEnumerable <Movie>     movies        = _movieRepository.GetAllMovies();

            foreach (var item in movies.ToList())
            {
                originalModel.Movies.Add(item);
            }

            if (ModelState.IsValid)
            {
                Movie movie = _movieRepository.GetMovieByName(model.movieName);

                List <Time> SchedulesofModel = _movieRepository.GetScheduleOfAMovie(movie.Id).ToList();

                foreach (var item in SchedulesofModel)
                {
                    if (String.Equals(item.fromTime, model.FromTime) && Convert.ToDateTime(item.Date).Date == model.Date)
                    {
                        ModelState.AddModelError("", $"Phim {model.movieName} vào ngày {model.Date.ToShortDateString()} đã tồn tại khung giờ này.");
                        return(View(originalModel));
                    }
                }
                Time schedule = new Time()
                {
                    Id       = _movieRepository.GetMaxIDSchedule(),
                    IDMovie  = movie.Id,
                    fromTime = model.FromTime,
                    Date     = model.Date.ToShortDateString()
                };

                _movieRepository.AddNewSchedule(schedule);
            }
            return(View(originalModel));
        }