Exemplo n.º 1
0
        public JsonResult Post([FromBody] WellnessUserMetric vm)
        {
            try
            {
                var metricUpdate = Mapper.Map <WellnessUserMetric>(vm);

                _repository.ModifyUserMetric(metricUpdate);

                if (_repository.SaveAll())
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Json(metricUpdate));
                }

                return(Json("TODO Update wellness METRICS of Metric ID"));
            }
            catch (Exception ex)
            {
                _logger.LogError("Falied to update metric", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { MessageBody = ex.Message }));
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed", ModelState = ModelState }));
        }
Exemplo n.º 2
0
        public JsonResult Post([FromBody] TeamViewModel vm)
        {
            //Join a team
            try
            {
                if (ModelState.IsValid)
                {
                    var newTeam = Mapper.Map <Team>(vm);

                    newTeam.Name = vm.Name;

                    //DB insert
                    _logger.LogInformation("Attempting to save a new Team");

                    _repository.CreateTeam(newTeam);

                    if (_repository.SaveAll())
                    {
                        Response.StatusCode = (int)HttpStatusCode.Created;
                        return(Json(Mapper.Map <TeamViewModel>(newTeam)));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Falied to save new Team", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { MessageBody = ex.Message }));
            }


            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed", ModelState = ModelState }));
        }
Exemplo n.º 3
0
        public JsonResult Post([FromBody] WellnessUserMetric vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newMetric = Mapper.Map <WellnessUserMetric>(vm);
                    newMetric.UserName = User.Identity.Name;

                    _repository.AddUserMetric(newMetric);

                    if (_repository.SaveAll())
                    {
                        Response.StatusCode = (int)HttpStatusCode.Created;
                        return(Json(Mapper.Map <MetricViewModel>(newMetric)));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Falied to save new metric", ex);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { MessageBody = ex.Message }));
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed", ModelState = ModelState }));
        }