예제 #1
0
        public async Task <IActionResult> SaveProfile([FromBody] ProfileRequest model)
        {
            var profile = _profileRepository.GetProfile(CurrentUserId);

            if (profile == null)
            {
                profile = new Profile.Profile
                {
                    UserId = CurrentUserId
                };
            }
            profile.DoB    = model.DoB;
            profile.Gender = model.Gender;

            var measures = _measurementRepository.GetMeasures(CurrentUserId);

            if (model.Weight.HasValue && model.Weight != measures.FirstOrDefault(m => m.Id == Constants.Measurements.WeightId)?.LatestValue)
            {
                _measurementRepository.CreateMeasurement(new Measurement
                {
                    MeasureId = Constants.Measurements.WeightId,
                    UserId    = CurrentUserId,
                    Time      = DateTimeOffset.Now,
                    Value     = model.Weight.Value
                });
            }
            if (model.Height.HasValue && model.Height != measures.FirstOrDefault(m => m.Id == Constants.Measurements.HeightId)?.LatestValue)
            {
                _measurementRepository.CreateMeasurement(new Measurement
                {
                    MeasureId = Constants.Measurements.HeightId,
                    UserId    = CurrentUserId,
                    Time      = DateTimeOffset.Now,
                    Value     = model.Height.Value
                });
            }
            if (model.Rmr.HasValue && model.Rmr != measures.FirstOrDefault(m => m.Id == Constants.Measurements.RmrId)?.LatestValue)
            {
                _measurementRepository.CreateMeasurement(new Measurement
                {
                    MeasureId = Constants.Measurements.RmrId,
                    UserId    = CurrentUserId,
                    Time      = DateTimeOffset.Now,
                    Value     = model.Rmr.Value
                });
            }

            _profileRepository.SaveProfile(profile);

            return(await GetProfile());
        }
예제 #2
0
        public IActionResult CreateMeasurement([FromRoute] string token, [FromBody] CreateMeasurementRequest measurementRequest)
        {
            Measurement measurement = _measurementRepository.CreateMeasurement(measurementRequest.payload, token, HttpContext.User.Identity.Name);

            if (measurement == null)
            {
                return(BadRequest(new { statusCode = 400, message = "bad_request" }));
            }
            return(StatusCode(201, new { statusCode = 201, message = "created" }));
        }
예제 #3
0
 public IActionResult Create([FromBody] MeasurementRequest request)
 {
     CreateMeasures(request.Measurements);
     foreach (var reqMeasurement in request.Measurements)
     {
         var measurement = new Measurement
         {
             UserId    = CurrentUserId,
             MeasureId = reqMeasurement.MeasureId.Value,
             Time      = request.Time,
             Value     = reqMeasurement.Value
         };
         if (reqMeasurement.MeasurementId.HasValue)
         {
             measurement.Id = reqMeasurement.MeasurementId.Value;
             measurementRepository.UpdateMeasurement(measurement);
         }
         else
         {
             measurementRepository.CreateMeasurement(measurement);
         }
     }
     return(Ok());
 }