Пример #1
0
        public IActionResult CreateDay(DayDto dayDto)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("CreateDay", "bdbusr", new { id = dayDto.UserId }));
            }

            var day = _utilities.CreateDayEntity(dayDto.Name, dayDto.Date, dayDto.UserId);

            if (!_workoutRepository.Save() || day == null)
            {
                return(RedirectToAction("CreateDay", "bdbusr", new { id = dayDto.UserId }));
            }

            foreach (var e in dayDto.ExerciseNames)
            {
                if (e != "")
                {
                    var exercise = _workoutRepository.GetExerciseByName(e);
                    if (exercise == null)
                    {
                        exercise = _utilities.CreateExerciseEntity(e);
                        if (!_workoutRepository.Save())
                        {
                            return(RedirectToAction("CreateDay", "bdbusr", new { id = dayDto.UserId }));
                        }
                    }

                    var dayExercise = _utilities.CreateDayExerciseEntity(day.Id, exercise.Id);
                    if (!_workoutRepository.Save() || dayExercise == null)
                    {
                        return(RedirectToAction("CreateDay", "bdbusr", new { id = dayDto.UserId }));
                    }

                    var workload = _utilities.CreateWorkloadEntity(day.Id, exercise.Id);
                }
            }

            _workoutRepository.AddDayForUser(dayDto.UserId, day);
            if (!_workoutRepository.Save())
            {
                return(RedirectToAction("CreateDay", "bdbusr", new { id = dayDto.UserId }));
            }

            return(RedirectToAction("ViewDay", "bdbusr", new { id = day.Id }));
        }
Пример #2
0
        public IActionResult AddExerciseToMyDay(WorkloadDto workloadDto)
        {
            var exercise = _workoutRepository.GetExerciseByName(workloadDto.exerciseName);

            if (exercise == null)
            {
                exercise      = _utilities.CreateExerciseEntity(workloadDto.exerciseName);
                exercise.Type = workloadDto.exerciseType;
                if (!_workoutRepository.Save())
                {
                    return(RedirectToAction("ViewMyDay", "Day", new { id = workloadDto.dayId }));
                }
            }

            var dayExercise = _utilities.CreateDayExerciseEntity(workloadDto.dayId, exercise.Id);

            if (!_workoutRepository.Save() || dayExercise == null)
            {
                return(RedirectToAction("ViewMyDay", "Day", new { id = workloadDto.dayId }));
            }


            var workload = _utilities.CreateWorkloadEntity(workloadDto.dayId, exercise.Id);

            if (!_workoutRepository.Save())
            {
                return(RedirectToAction("ViewMyDay", "Day", new { id = workloadDto.dayId }));
            }

            workloadDto.workloadId = workload.Id;
            workload = _utilities.MapWorkloadDtoToWorkload(workloadDto);
            if (!_workoutRepository.Save())
            {
                return(RedirectToAction("ViewMyDay", "Day", new { id = workloadDto.dayId }));
            }

            return(RedirectToAction("ViewMyDay", "Day", new { id = workloadDto.dayId }));
        }