Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(int?id, string returnPath)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var storedWorkout = await _workoutRepository.GetById(id.Value, new WorkoutWithIntervalsAndLengthsSpecification())//WorkoutWithIntervalsAndIntervalTypeSpecification
                                .ConfigureAwait(false);

            //var storedWorkout = await _workoutRepository.GetById(id.Value, w => w.Intervals, wi => ((WorkoutInterval)wi).WorkoutIntervalType); // i => ((WorkoutInterval)i).Lengths
            if (storedWorkout == null)
            {
                return(NotFound());
            }

            //TempData[ValueKeys.TempDataReturnPathKey] = returnPath;
            ReturnPath = string.IsNullOrWhiteSpace(returnPath) ? Url.Page("Index") : returnPath;

            //storedWorkout.Intervals = await _workoutIntervalRepository.GetList(i => i.WorkoutId == storedWorkout.Id, i => i.Lengths);
            Workout = _mapper.Map <WorkoutViewModel>(storedWorkout);
            var intervals = Workout.Intervals
                            .OrderBy(wi => wi.IntervalNo)
                            .ToList();

            InsertRests(intervals);
            Workout.Intervals.Clear();
            Workout.Intervals.AddRange(intervals);

            var displayIntervals = new List <IntervalDisplayData>();

            foreach (var interval in storedWorkout.Intervals)
            {
                var obj = DisplayDataHelper.CreateIntervalDisplayData(interval);
                displayIntervals.Add(obj);
            }

            //var formatter = (Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonOutputFormatter)options.Value.OutputFormatters.First(f => f.GetType() == typeof(Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonOutputFormatter));
            var settings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            this.SerializedIntervals = JsonConvert.SerializeObject(displayIntervals, settings);//, );
            // config.Formatters.JsonFormatter.SerializerSettings.ContractResolver

            //var requestWithParams = QueryHelpers.ParseQuery(Request.QueryString.Value)
            //    .Select(p => new { p.Key, Value = p.Value.ToString() })
            //    .ToDictionary(a => a.Key, v => v.Value);
            //requestWithParams.Remove(nameof(showRests));

            return(Page());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ModifyLengths([FromBody] ModifyIntervalLengthsRequest requestData)
        {
            if (requestData?.IntervalData == null)
            {
                return(new JsonResult(new ApiResultBase {
                    Success = false, Message = "No input data!"
                }));
            }

            if (requestData.SelectedLengthNo <= 0)
            {
                return(new JsonResult(new ApiResultBase {
                    Success = false, Message = "Invalid Length No!"
                }));
            }

            var inputInterval = requestData.IntervalData;

            if (inputInterval.Lengths?.Count == 0)
            {
                return(new JsonResult(new ApiResultBase {
                    Success = false, Message = "No Lengths!"
                }));
            }

            var interval = DisplayDataHelper.CreateInterval(inputInterval);

            // Perform modifications

            var resultInterval = DisplayDataHelper.CreateIntervalDisplayData(interval);

            resultInterval.IntervalTypeName = inputInterval.IntervalTypeName;

            var result = new ModifyIntervalLengthsResponse
            {
                Success = true,
                Result  = resultInterval
            };

            return(new JsonResult(result));
        }