Esempio n. 1
0
        public IActionResult Edit(long id, TrainingSchedule trainingSchedule)
        {
            if (id != trainingSchedule.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _iTrainingScheduleManager.Update(trainingSchedule);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TrainingScheduleExists(trainingSchedule.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainingSchedule));
        }
Esempio n. 2
0
        public Task <TrainingSchedule> CreateAsync(TrainingSchedule trainingSchedule)
        {
            _context.TrainingSchedules.Add(trainingSchedule);
            _context.SaveChangesAsync();

            return(Task.FromResult(trainingSchedule));
        }
Esempio n. 3
0
 public IActionResult Create(TrainingSchedule trainingSchedule)
 {
     if (ModelState.IsValid)
     {
         _iTrainingScheduleManager.Add(trainingSchedule);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(trainingSchedule));
 }
Esempio n. 4
0
        public int AddUpdateTrainingSchedule(TrainingScheduleViewModel model, int OrganizationId)
        {
            TrainingSchedule schedule = Mapper.Map <TrainingScheduleViewModel, TrainingSchedule>(model);

            if (schedule.TrainingScheduleId == 0)
            {
                schedule.OrganizationId = OrganizationId;
                schedule.Completed      = false;
                base.Insert(schedule);
                this._unitOfWork.Save();
            }
            else
            {
                base.RepositoryContext.SP_DeleteALLTrainingScheduleRole(schedule.TrainingScheduleId, OrganizationId);
                base.RepositoryContext.SP_DeleteALLTrainingScheduleUser(schedule.TrainingScheduleId, OrganizationId);
            }
            if (model.UserList != null && model.UserList.Any())
            {
                foreach (var data in model.UserList)
                {
                    TrainingScheduleUser user = Mapper.Map <TrainingScheduleUserViewModel, TrainingScheduleUser>(data);
                    user.TrainingScheduleId = schedule.TrainingScheduleId;
                    user.OrganizationId     = OrganizationId;
                    this._ITrainingScheduleUserRepository.Add(user, 0, OrganizationId);
                }
            }
            if (model.RoleList != null && model.RoleList.Any())
            {
                foreach (var data in model.RoleList)
                {
                    TrainingScheduleRole role = Mapper.Map <TrainingScheduleRoleViewModel, TrainingScheduleRole>(data);
                    role.TrainingScheduleId = schedule.TrainingScheduleId;
                    role.OrganizationId     = OrganizationId;
                    this._ITrainingScheduleRoleRepository.Add(role, 0, OrganizationId);
                }
            }
            this._unitOfWork.Save();
            return(schedule.TrainingScheduleId);
        }
        public SchemaMutation(ExerciseService exercises, TrainingScheduleService trainingSchedules, WorkoutService workoutService,
                              UserService userService)
        {
            Name = "Mutation";
            Field <ExerciseType>(
                "createExercise",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ExerciseCreateInputType> > {
                Name = "exercise"
            }),
                resolve: context =>
            {
                var input = context.GetArgument <ExerciseCreateInputType>("exercise");
                var order = new Exercise {
                    Name = input.Name
                };
                return(exercises.CreateAsync(order));
            }
                );

            FieldAsync <TrainingScheduleType>(
                "createTrainingSchedule",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <TrainingScheduleCreateInputType> >
            {
                Name = "trainingSchedule"
            }),
                resolve: async context =>
            {
                var input = context.GetArgument <TrainingScheduleCreateDto>("trainingSchedule");

                var trainingSchedule = new TrainingSchedule
                {
                    Name = input.Name,
                    User = await userService.GetUserByIdAsync(1),
                    TrainingScheduleExercises = input.ExercisesWithSets
                                                .Select(
                        exerciseIdWithSets => new TrainingScheduleExercise
                    {
                        ExerciseId = exerciseIdWithSets.Id,
                        Sets       = exerciseIdWithSets.Sets
                    }).ToList()
                };

                return(await context.TryAsyncResolve(async c =>
                                                     await trainingSchedules.CreateAsync(trainingSchedule)));
            }
                );

            FieldAsync <WorkoutType>(
                "createWorkout",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <WorkoutCreateInputType> >
            {
                Name = "workout"
            }),
                resolve: async context =>
            {
                var input = context.GetArgument <WorkoutCreateDto>("workout");

                var trainingSchedule = new Workout
                {
                    User      = await userService.GetUserByIdAsync(1),
                    Exercises = input.Exercises
                                .Select(
                        exercise => new WorkoutExercise
                    {
                        ExerciseId = exercise.Id,
                        Sets       = exercise.Sets,
                        DateTime   = exercise.DateTime
                    }).ToList()
                };

                return(await context.TryAsyncResolve(async c =>
                                                     await workoutService.CreateAsync(trainingSchedule)));
            }
                );
        }
Esempio n. 6
0
 public void Update(TrainingSchedule entity, int LoggedInUserId, int LoggedInOrganizationId)
 {
     base.Update(entity);
     _unitOfWork.Save();
 }