public void Delete(SavedBrewery brewery) { if (brewery == null) { throw new NotImplementedException(nameof(brewery)); } _context.SavedBreweries.Remove(brewery); }
public ActionResult Update(int id, SavedBrewery brewery) { var breweryModel = _service.GetBreweryById(id); if (breweryModel == null) { return(NotFound()); } brewery.BreweryId = breweryModel.BreweryId; _service.Delete(breweryModel); _service.Update(brewery); _service.SaveChanges(); return(NoContent()); }
public ActionResult <SavedBrewery> Create(SavedBrewery brewery) { try { _service.Create(brewery); _service.SaveChanges(); return(CreatedAtRoute(nameof(GetBreweryById), new { Id = brewery.BreweryId }, brewery)); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public void Create(SavedBrewery brewery) { if (brewery == null) { throw new ArgumentNullException(nameof(brewery)); } //make sure user has not already saved brewery using brewery name and user id string breweryName = brewery.BreweryName; int breweryId = brewery.BreweryId; if (_context.SavedBreweries.Any(b => b.BreweryName == brewery.BreweryName && b.BreweryId == breweryId)) { throw new AppException(breweryName + " has already been added to your favorites list"); } _context.SavedBreweries.Add(brewery); }
public void Update(SavedBrewery brewery) { _context.SavedBreweries.Update(brewery); }