public IHttpActionResult Complete(int id, EditChallengeResponseViewModel model) { if (model != null && ModelState.IsValid) { var challengeResponse = this.data.ChallengeResponses.Find(id); if (challengeResponse != null && challengeResponse.ChallengeeId == this.CurrentUser.Id) { if (challengeResponse.Status != ChallengeStatus.Active) { return this.BadRequest("Challenge isn't active."); } //if (HttpContext.Current.Request.Files.AllKeys.Any()) //{ // var httpPostedFile = HttpContext.Current.Request.Files["photo"]; // string url = await photoService.UploadPhotoAsync(httpPostedFile); // model.ImageUrl = url; //} if (string.IsNullOrEmpty(model.ImageUrl)) { return this.BadRequest("We need proof! Add an image!"); } Mapper.Map<EditChallengeResponseViewModel, ChallengeResponse>(model, challengeResponse); challengeResponse.Status = ChallengeStatus.Completed; //TODO: make cleverer if (challengeResponse.Challenge.CreatorId != this.CurrentUser.Id) { this.CurrentUser.Score += (((int)challengeResponse.Challenge.Difficulty + 1) * 12); } this.data.ChallengeResponses.Update(challengeResponse); this.data.SaveChanges(); return this.Ok(model); } } return this.BadRequest("Couldn't edit challenge response."); }
public IHttpActionResult Complete(int id) { var challengeResponse = this.data.ChallengeResponses.Find(id); if (challengeResponse == null || challengeResponse.ChallengeeId != this.CurrentUser.Id) { return this.BadRequest("Not your challenge to edit."); } var model = new EditChallengeResponseViewModel() { ImageUrl = challengeResponse.ImageUrl, VideoUrl = challengeResponse.VideoUrl, }; return this.Ok(model); }