Beispiel #1
0
        public async Task <IActionResult> AddTraining(int id)
        {
            AddTrainingToDayModel model = await this.daysService.GetDayTrainingsByIdAsync(id, this.User.Identity.Name);

            this.ViewData["id"] = id;

            return(this.View(model));
        }
Beispiel #2
0
        public async Task <AddTrainingToDayModel> GetDayTrainingsByIdAsync(int dayId, string username)
        {
            var trainings = await this.trainingsService.GetAllUserTrainingsAsync(username);

            var model = new AddTrainingToDayModel()
            {
                Id        = dayId,
                Trainings = trainings.Select(t => new SelectListItem(t.Name, t.Id.ToString()))
            };

            return(model);
        }
Beispiel #3
0
        public async Task <IActionResult> AddTraining(int dayId, AddTrainingToDayModel model)
        {
            try
            {
                await this.daysService.AddTrainingToDayAsync(dayId, model.Id, this.User.Identity.Name);
            }
            catch (Exception)
            {
                this.ModelState.AddModelError(string.Empty, alreadyAddedTraining);

                return(await this.AddTraining(dayId));
            }

            return(this.RedirectToAction(ActionConstants.Details, ControllerConstants.Days, new { id = dayId }));
        }