コード例 #1
0
 public void Delete(SavedBrewery brewery)
 {
     if (brewery == null)
     {
         throw new NotImplementedException(nameof(brewery));
     }
     _context.SavedBreweries.Remove(brewery);
 }
コード例 #2
0
        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());
        }
コード例 #3
0
        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 }));
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public void Update(SavedBrewery brewery)
 {
     _context.SavedBreweries.Update(brewery);
 }