public IActionResult Create(int id, [FromBody] CardBindingModel cardBindingModel) { var userId = this.usersService.GetUserId(this.HttpContext.User); try { var cardId = this.cardsService.CreateCard(id, userId, cardBindingModel.Word, cardBindingModel.Translation, cardBindingModel.Hint, cardBindingModel.ImageURL); return(this.Ok(new { Id = cardId, message = "Successfully added word to deck!" })); } catch (AuthorizationException e) { return(this.StatusCode(401, new { message = e.Message })); } catch (ArgumentException e) { return(this.NotFound(new { message = e.Message })); } }
public IActionResult Edit(int id, [FromBody] CardBindingModel cardBindingModel) { var userId = this.usersService.GetUserId(this.HttpContext.User); try { int deckId = this.cardsService.EditCard(id, userId, cardBindingModel.Word, cardBindingModel.Translation, cardBindingModel.Hint, cardBindingModel.ImageURL); return(Ok( new { id = deckId, message = "Successfully edited card!" })); } catch (ArgumentException e) { return(this.NotFound(new { message = e.Message })); } catch (AuthorizationException e) { return(this.StatusCode(401, new { message = e.Message })); } }
public IHttpActionResult UpdateCard([FromBody] CardBindingModel card) { using (UnitOfWork) { UnitOfWork.CardService.UpdateCard(card); return(Ok()); } }
/// <summary> /// Updates card /// </summary> /// <param name="card">Card view model</param> public void UpdateCard(CardBindingModel card) { var cardEntity = _cardsRepo .FindBy(c => c.Id == card.Id); if (cardEntity != null) { var updatedCard = this.entityService.ConvertTo <CardBindingModel, Cards>(card); this.entityService.AssignTo <Cards, Cards>(updatedCard, cardEntity); _cardsRepo.Update(cardEntity); } }
/// <summary> /// Creates new card /// </summary> /// <param name="card">Card view model</param> public void CreateCard(CardBindingModel cardModel) { //if (!string.IsNullOrEmpty(cardModel.Name) && !string.IsNullOrEmpty(card.Image)) //{ // try // { // Cards newCard = new Cards(); // newCard = this.entityService.ConvertTo<CardBindingModel, Cards>(cardModel); // if (newCard != null) // { // newCard.Image = Convert.FromBase64String(card.Image); // _cardsRepo.Create(newCard); // } // } // catch (FormatException) // { // throw new InvalidPictureFormatException("Picture has a bad format"); // } //} }