public IActionResult Post([FromBody] Favourite favourite) { try { service.AddFavourite(favourite); return(Created("api/Favourite", 201)); } catch (FavouriteAlreadyExistsException ex) { return(Conflict(ex.Message)); } }
public ActionResult Add([FromBody] Favourite favourite) { try { Favourite fav = favouriteService.AddFavourite(favourite); return(Created("/api/favourite", fav)); } catch (FavouritePlayerNotAddedException favouriteException) { return(Conflict(favouriteException.Message)); } }
public IActionResult AddFavourite([FromBody] Favourite fav) { try { return(Created("", _service.AddFavourite(fav))); } catch (FavouriteNotFound ex) { return(Conflict(ex.Message)); } //catch //{ // return StatusCode(500, "Internal Server Error"); //} }
public IActionResult Post([FromBody] Favourite favourite) { try { return(Ok(service.AddFavourite(favourite))); } catch (PlayerAlreadyExistsException p) { return(StatusCode(403, JsonConvert.SerializeObject(p.Message))); } catch (Exception e) { return(StatusCode(500, JsonConvert.SerializeObject(e.Message))); } }
public async Task <IActionResult> AddFavorite(int propertyId) { var userId = User.GetUserId(); if (await _favouriteService.FavouriteExists(userId, propertyId)) { var userFavourite = await _favouriteService.GetFavourite(userId, propertyId); _favouriteService.RemoveFavourite(userFavourite); return(Ok(_response.Ok("The property has been removed from your favourite list"))); } var favourite = await _favouriteService.AddFavourite(userId, propertyId); return(Ok(_response.Ok(favourite))); }