public IHttpActionResult Post([FromBody] WellnessStatusColor status) { if (!ModelState.IsValid) { string errors = ""; foreach (var modelstate in ModelState.Values) { foreach (var error in modelstate.Errors) { errors += "|" + error.ErrorMessage + "|" + error.Exception; } } throw new BadInputException() { ExceptionMessage = errors }; } var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal; var username = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value; var id = _accountService.GetAccountByUsername(username).GordonID; var result = _wellnessService.PostStatus(status, id); if (result == null) { return(NotFound()); } return(Created("Recorded answer :", result)); }
/// <summary> /// Stores wellness Status in database. /// </summary> /// <param name="id"> ID of the user to post the status for</param> /// <param name="status"> Status that is being posted, one of the WellnessStatusColors </param> /// <returns>Status that was successfully recorded</returns> public Health_Status PostStatus(WellnessStatusColor status, string id) { var account = _unitOfWork.AccountRepository.FirstOrDefault(x => x.gordon_id == id); if (account == null) { throw new ResourceNotFoundException() { ExceptionMessage = "The account was not found." }; } var now = DateTime.Now; var statusObject = new Health_Status { ID_Num = int.Parse(id), HealthStatusID = (byte)status, Created = now, Expires = ExpirationDate(now), CreatedBy = "360.WellnessCheck", Emailed = null }; var result = _unitOfWork.WellnessRepository.Add(statusObject); if (result == null) { throw new ResourceNotFoundException() { ExceptionMessage = "The data was not found." }; } _unitOfWork.Save(); return(result); }