public async Task <int> CreateGroup(CreateEditGroupInputModel model)
        {
            DateTime startDate = model.StartDate ?? DateTime.Now;
            DateTime endDate   = model.EndDate ?? DateTime.Now;
            TimeSpan duration  = TimeSpan.FromMinutes(model.Duration);

            var group = new Group
            {
                Name                = model.Name,
                AgeGroup            = model.AgeGroup,
                CurrentLessonNumber = 1, //0 and add logic for increasing lesson numbers
                DayOfWeek           = model.DayOfWeek,
                Duration            = duration,
                StartDate           = startDate,
                EndDate             = endDate,
                StartTime           = model.StartTime,
                EndTime             = model.StartTime.Add(duration),
                LevelId             = model.LevelId,
                Status              = GroupStatus.Empty,
                ActiveStatus        = GroupActiveStatus.Initial,
                MaxStudents         = (int)model.AgeGroup
            };

            if (model.TeacherId != 0)
            {
                group.TeacherId = model.TeacherId;
            }


            await this.db.Groups.AddAsync(group);

            await this.db.SaveChangesAsync();

            return(group.Id);
        }
        public async Task <IActionResult> Create(CreateEditGroupInputModel model)
        {
            if (ModelState.IsValid == false)
            {
                model.Teachers = this.teachersService.GetAllForSelection();
                model.Levels   = this.levelsService.GetAllForSelection();
                return(await Task.Run(() => this.View(model)));
            }
            var groupId = await this.groupsService.CreateGroup(model);

            return(RedirectToAction("Details", new { groupId = groupId }));
        }
        public IActionResult Create()
        {
            var teachersList = this.teachersService.GetAllForSelection();
            var levelsList   = this.levelsService.GetAllForSelection();
            var model        = new CreateEditGroupInputModel()
            {
                Teachers = teachersList,
                Levels   = levelsList
            };

            return(this.View(model));
        }
        public async Task <IActionResult> EditInfo(CreateEditGroupInputModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(await Task.Run(() => this.View(model)));
            }

            int groupId = await CheckStudentId(TempData["groupId"]);

            model.Id = groupId;
            await this.groupsService.EditInfo(model);

            return(await Task.Run(() => this.RedirectToAction("Details", new { groupId = model.Id })));
        }
        public async Task <CreateEditGroupInputModel> GetInfoForEdit(int groupId)
        {
            var group = await this.db.Groups
                        .FirstOrDefaultAsync(x => x.Id == groupId);

            var model = new CreateEditGroupInputModel
            {
                Name      = group.Name,
                AgeGroup  = group.AgeGroup,
                DayOfWeek = group.DayOfWeek,
                Duration  = (int)group.Duration.TotalMinutes,
                StartDate = group.StartDate,
                EndDate   = group.EndDate,
                StartTime = group.StartTime,
            };

            return(model);
        }
        public async Task EditInfo(CreateEditGroupInputModel model)
        {
            DateTime StartDate = model.StartDate ?? DateTime.Now;
            DateTime EndDate   = model.EndDate ?? DateTime.Now;
            TimeSpan duration  = TimeSpan.FromMinutes(model.Duration);


            var group = await this.db.Groups.FirstOrDefaultAsync(x => x.Id == model.Id);

            group.Name      = model.Name;
            group.AgeGroup  = model.AgeGroup;
            group.StartDate = StartDate;
            group.EndDate   = EndDate;
            group.StartTime = model.StartTime;
            group.Duration  = duration;
            group.EndTime   = model.StartTime.Add(duration);
            group.DayOfWeek = model.DayOfWeek;

            await this.db.SaveChangesAsync();
        }