public async Task <ActionResult> LogoAndWin([FromBody] LogoWinRequest model) { if (model.PhotoInput == null) { ViewBag.Error = "PICTURE_REQUIRED"; return(CurrentUmbracoPage()); } if (model.ParticipationId == null || model.ParticipationId == default) { ViewBag.Error = "PARTICIPATION_ID_REQUIRED"; return(CurrentUmbracoPage()); } if (model.ParticipantId == null || model.ParticipantId == default) { ViewBag.Error = "PARTICIPANT_ID_REQUIRED"; return(CurrentUmbracoPage()); } var filePath = FileHelper.StoreFileTemporarily(model.PhotoInput); bool isLogoValid = await _validationService.CheckValidLogoAsync(filePath); FileHelper.RemoveTemporarilyStoredFile(filePath); if (!isLogoValid) { ViewBag.Error = "LOGO_INVALID"; return(CurrentUmbracoPage()); } var participation = new ParticipationDto { Id = model.ParticipationId, ParticipantId = model.ParticipantId }; await _participationService.UpdateLogoValidatedParticipationAsync(participation); var instantWinResult = await _participationService.UpdateInstantWinStatusAsync(participation); var congratsOrLosePageId = instantWinResult.winStatus ? _configurationService.GetCongratulationPageId() : _configurationService.GetLosePageId(); return(RedirectToUmbracoPage(congratsOrLosePageId)); }
public async Task <IHttpActionResult> LogoAndWinCheck() { dynamic expando = new ExpandoObject(); var apiResponse = new ApiResponse { Success = false }; var model = new LogoWinRequest { PhotoInput = HttpContext.Current.Request.Files[0], ParticipantId = Guid.Parse(HttpContext.Current.Request.Form["ParticipantId"]), ParticipationId = Guid.Parse(HttpContext.Current.Request.Form["ParticipationId"]), }; try { if (model.PhotoInput == null) { expando.Description = "PICTURE_REQUIRED"; apiResponse.Message = "Please provide a picture"; apiResponse.Data = expando; return(Content(HttpStatusCode.BadRequest, apiResponse)); } if (model.ParticipationId == null || model.ParticipationId == default) { expando.Description = "PARTICIPATION_ID_REQUIRED"; apiResponse.Message = "Please provide a participation Id"; apiResponse.Data = expando; return(Content(HttpStatusCode.BadRequest, apiResponse)); } if (model.ParticipantId == null || model.ParticipantId == default) { expando.Description = "PARTICIPANT_ID_REQUIRED"; apiResponse.Message = "Please provide a participant Id"; apiResponse.Data = expando; return(Content(HttpStatusCode.BadRequest, apiResponse)); } var filePath = FileHelper.StoreFileTemporarily(model.PhotoInput); bool isLogoValid = await _validationService.CheckValidLogoAsync(filePath); FileHelper.RemoveTemporarilyStoredFile(filePath); if (!isLogoValid) { expando.Description = "LOGO_INVALID"; apiResponse.Message = "Could not validate uploaded pictures"; apiResponse.Data = expando; return(Content(HttpStatusCode.BadRequest, apiResponse)); } var participation = new ParticipationDto { Id = model.ParticipationId, ParticipantId = model.ParticipantId }; await _participationService.UpdateLogoValidatedParticipationAsync(participation); var instantWinResult = await _participationService.UpdateInstantWinStatusAsync(participation); expando.Description = instantWinResult.winStatus ? "LOGO_VALID_AND_WON" : "LOGO_VALID_BUT_LOST"; expando.GameStatus = instantWinResult.winStatus ? "WIN" : "LOSE"; expando.PrizeName = instantWinResult.winStatus ? instantWinResult.prize.Name : string.Empty; apiResponse.Success = true; apiResponse.Message = "Logo valid and instant win checked"; apiResponse.Data = expando; return(Ok(apiResponse)); } catch (Exception e) { apiResponse.Success = false; apiResponse.Message = e.Message; expando.Description = $"Error occured in {e.Source}: {e.StackTrace}"; apiResponse.Data = expando; return(Content(HttpStatusCode.InternalServerError, apiResponse)); } }