public async Task <IActionResult> PostCardOfUser([FromBody] PostCardOfUserRequest card) { if (card.FrontSide == null) { return(ControllerError.BadRequest(localizer["InvalidCardEmptyFrontSide"].Value, this)); } if (card.BackSide == null) { card.BackSide = ""; } if (card.AdditionalInfo == null) { card.AdditionalInfo = ""; } if (card.FrontSideImageList == null) { return(ControllerError.BadRequest("Invalid input: card.FrontSideImageList == null", this)); } if (card.BackSideImageList == null) { return(ControllerError.BadRequest("Invalid input: card.BackSideImageList == null", this)); } if (card.AdditionalInfoImageList == null) { return(ControllerError.BadRequest("Invalid input: card.AdditionalInfoImageList == null", this)); } if (card.UsersWithVisibility == null) { return(ControllerError.BadRequest("Invalid input: card.UsersWithVisibility == null", this)); } if (card.Tags == null) { return(ControllerError.BadRequest("Invalid input: card.Tags == null", this)); } try { var user = await userManager.GetUserAsync(HttpContext.User); var versionDescription = localizer["InitialCardVersionCreation"].Value; var request = new CreateCard.Request(user, card.FrontSide, card.FrontSideImageList, card.BackSide, card.BackSideImageList, card.AdditionalInfo, card.AdditionalInfoImageList, card.LanguageId, card.Tags, card.UsersWithVisibility, versionDescription); var cardId = await new CreateCard(dbContext).RunAsync(request, localizer); if (card.AddToDeck != Guid.Empty) { await new AddCardInDeck(dbContext).RunAsync(card.AddToDeck, cardId); } return(Ok()); } catch (RequestInputException e) { return(ControllerError.BadRequest(e.Message, this)); } catch (Exception e) { return(ControllerError.BadRequest(e, this)); } }
public async Task <IActionResult> PostCardOfUser([FromBody] PostCardOfUserRequest card) { CheckBodyParameter(card); var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager); var versionDescription = Get("InitialCardVersionCreation"); var request = new CreateCard.Request(userId, card.FrontSide !, card.FrontSideImageList, card.BackSide !, card.BackSideImageList, card.AdditionalInfo !, card.AdditionalInfoImageList, card.LanguageId, card.Tags, card.UsersWithVisibility, versionDescription); var cardId = (await new CreateCard(callContext).RunAsync(request)).CardId; if (card.AddToDeck != Guid.Empty) { await new AddCardsInDeck(callContext).RunAsync(new AddCardsInDeck.Request(userId, card.AddToDeck, cardId.AsArray())); } return(ControllerResultWithToast.Success(Get("CardSavedOk"), this)); }