Exemplo n.º 1
0
        public async Task <WTServiceResponse <string> > ActivateOrDeactivateProgram(WorkoutProgramVM programModel)
        {
            // serialize it
            var serializedProgram = JsonConvert.SerializeObject(programModel);

            var httpClient = await _workoutTrackerHttpClient.GetClient();

            var path = "activate";

            if (programModel.ToBeActivated == false)
            {
                path = "deactivate";
            }

            var response = await httpClient.PostAsync($"/api/Programs/user/{UserId()}/program/{programModel.ID}/{path}",
                                                      new StringContent(serializedProgram, System.Text.Encoding.Unicode, "application/json"));

            return(HandleApiResponse(response, () =>
            {
                return new WTServiceResponse <string>
                {
                    StatusCode = response.StatusCode,
                    ViewModel = "",
                };
            }));
        }
Exemplo n.º 2
0
        public async Task <WTServiceResponse <string> > SaveProgram(WorkoutProgramVM program)
        {
            // serialize it
            var serializedProgram = JsonConvert.SerializeObject(program);

            var httpClient = await _workoutTrackerHttpClient.GetClient();

            var response = await httpClient.PutAsync($"/api/Programs/user/{UserId()}/program/{program.ID}",
                                                     new StringContent(serializedProgram, System.Text.Encoding.Unicode, "application/json"));

            return(HandleApiResponse(response, () =>
            {
                return new WTServiceResponse <string>
                {
                    StatusCode = response.StatusCode,
                    ViewModel = "",
                };
            }));
        }
        public async Task <IActionResult> SaveProgram([FromForm] WorkoutProgramVM program)
        {
            var routines = JsonConvert.DeserializeObject <List <WorkoutRoutineVM> >(program.RoutinesSerialized);

            program.WorkoutRoutines = routines;
            if (program.Image != null)
            {
                program.ImagePath = program.Image.FileName;
                using (var fileStream = program.Image.OpenReadStream())
                {
                    using (var ms = new MemoryStream())
                    {
                        fileStream.CopyTo(ms);
                        program.ImageBytes = ms.ToArray();
                    }
                }
            }

            var response = await _workoutTrackerService.SaveProgram(program);

            return(Json(response));
        }
Exemplo n.º 4
0
        public async Task <WTServiceResponse <WorkoutProgramVM> > AddProgram(WorkoutProgramVM program)
        {
            // serialize it
            var serializedProgram = JsonConvert.SerializeObject(program);

            var httpClient = await _workoutTrackerHttpClient.GetClient();

            var response = await httpClient.PostAsync($"/api/Programs/user/{UserId()}",
                                                      new StringContent(serializedProgram, System.Text.Encoding.Unicode, "application/json"));

            return(await HandleApiResponse(response, async() =>
            {
                var content = await response.Content.ReadAsStringAsync();
                var programVM = JsonConvert.DeserializeObject <WorkoutProgramVM>(content);

                return new WTServiceResponse <WorkoutProgramVM>
                {
                    StatusCode = response.StatusCode,
                    ViewModel = programVM
                };
            }));
        }
        public async Task <IActionResult> ActivateOrDeactivateProgram([FromForm] WorkoutProgramVM programModel)
        {
            var response = await _workoutTrackerService.ActivateOrDeactivateProgram(programModel);

            return(Json(response));
        }