Esempio n. 1
0
        // POST api/<controller>
        public HttpResponseMessage Post(RaceViewModel viewModel)
        {
            try {
                if (ModelState.IsValid)
                {
                    var raceType = _raceTypeService.GetRaceType(viewModel.RaceTypeId);

                    var race = new Race();
                    race.Name       = viewModel.Name;
                    race.RaceLength = viewModel.RaceLength;
                    race.RaceType   = raceType;
                    race.StartDate  = DateTime.Now;
                    _raceService.SaveRace(race);

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Invalid Model"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Esempio n. 2
0
        private Workout MapToEntity(WorkoutDto workoutViewDto, Workout workoutEntity)
        {
            var user     = _userService.GetUser(1);
            var raceType = _raceTypeService.GetRaceType(workoutViewDto.RaceTypeId);

            workoutEntity.Name           = workoutViewDto.Name;
            workoutEntity.Length         = workoutViewDto.Length;
            workoutEntity.AvgSpeed       = workoutViewDto.AvgSpeed;
            workoutEntity.StartDateTime  = workoutViewDto.StartDateTime;
            workoutEntity.EndDateTime    = workoutViewDto.EndDateTime;
            workoutEntity.ElapsedHours   = workoutViewDto.ElapsedHours;
            workoutEntity.ElapsedMinutes = workoutViewDto.ElapsedMinutes;
            workoutEntity.ElapsedSeconds = workoutViewDto.ElapsedSeconds;
            workoutEntity.User           = user;
            workoutEntity.RaceType       = raceType;

            foreach (var gpsCoord in workoutViewDto.GpsCoords)
            {
                workoutEntity.GpsCoords.Add(new WorkoutGpsCoord
                {
                    Latitude  = gpsCoord.Latitude,
                    Longitude = gpsCoord.Longtitude,
                    Elevation = gpsCoord.Elevation,
                    TimeStamp = gpsCoord.Timestamp
                });
            }

            return(workoutEntity);
        }
Esempio n. 3
0
        private Workout MapToEntity(WorkoutViewModel workoutViewModel, Workout workoutEntity)
        {
            var user     = _userService.GetUser(1);
            var raceType = _raceTypeService.GetRaceType(workoutViewModel.RaceTypeId);

            workoutEntity.Name           = workoutViewModel.Name;
            workoutEntity.Length         = workoutViewModel.Length;
            workoutEntity.AvgSpeed       = workoutViewModel.AvgSpeed;
            workoutEntity.StartDateTime  = workoutViewModel.StartDateTime;
            workoutEntity.EndDateTime    = workoutViewModel.EndDateTime;
            workoutEntity.ElapsedHours   = workoutViewModel.ElapsedHours;
            workoutEntity.ElapsedMinutes = workoutViewModel.ElapsedMinutes;
            workoutEntity.ElapsedSeconds = workoutViewModel.ElapsedSeconds;
            workoutEntity.User           = user;
            workoutEntity.RaceType       = raceType;

            return(workoutEntity);
        }