Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CountryId,IsDeleted,DeletedOn,ModifiedOn")] Brewery brewery)
        {
            if (id != brewery.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (brewery.IsDeleted)
                    {
                        brewery.DeletedOn = DateTime.Now;
                    }
                    brewery.ModifiedOn = DateTime.Now;
                    _context.Update(brewery);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BreweryExists(brewery.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Name", brewery.CountryId);
            return(View(brewery));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Rating,Name,Text,TargetBeerId,AuthorId,CreatedOn,ModifiedOn,IsDeleted,DeletedOn")] Review review)
        {
            if (id != review.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    review.ModifiedOn = DateTime.Now;
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"]     = new SelectList(_context.Users, "Id", "Email", review.AuthorId);
            ViewData["TargetBeerId"] = new SelectList(_context.Beers, "Id", "Name", review.TargetBeerId);
            return(View(review));
        }
Example #3
0
        public async Task <IActionResult> Edit(int id, [Bind("FirstName,LastName,DateOfBirth,CreatedOn,isBanned,banDescription,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ModifiedOn,IsDeleted,DeletedOn")] BeerType beerType)
        {
            if (id != beerType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (beerType.IsDeleted)
                    {
                        beerType.DeletedOn = DateTime.Now;
                    }
                    beerType.ModifiedOn = DateTime.Now;
                    _context.Update(beerType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BeerTypeExists(beerType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(beerType));
        }
Example #5
0
        public BeerDTO UpdateBeer(int id, string beerName, double?abv, string description, int beerTypeId, int breweryId)
        {
            var beer = _beerOverflowContext.Beers
                       .Where(b => b.DateUnlisted == null)
                       .FirstOrDefault(b => b.Id == id);

            if (beer == null)
            {
                throw new ArgumentNullException("Beer is null!");
            }

            if (beerName != null)
            {
                beer.BeerName = beerName;
            }

            if (abv != null)
            {
                beer.AlcByVol = (double)abv;
            }

            if (description != null)
            {
                beer.Description = description;
            }

            if (breweryId != 0)
            {
                var _brewery = _beerOverflowContext.Breweries.Find(breweryId);
                if (_brewery == null)
                {
                    throw new ArgumentException("Provided brewery is not within the list of breweries");
                }
                beer.BreweryId = _brewery.Id;
            }

            if (beerTypeId != 0)
            {
                var _beerType = _beerOverflowContext.BeerTypes.Find(beerTypeId);
                if (_beerType == null)
                {
                    throw new ArgumentException("Provided beer type is not within the list of beer types");
                }
                beer.BeerTypeId = _beerType.Id;
            }
            _beerOverflowContext.Update(beer);
            _beerOverflowContext.SaveChanges();

            return(GetBeer(id));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,TypeId,BreweryId,DeletedOn,ModifiedOn,IsDeleted,AlcoholByVolume,ImgUrl")] Beer beer)
        {
            if (id != beer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (beer.IsDeleted)
                    {
                        beer.DeletedOn = DateTime.Now;
                    }
                    beer.ModifiedOn = DateTime.Now;
                    _context.Update(beer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BeerExists(beer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BreweryId"] = new SelectList(_context.Breweries, "Id", "Name", beer.BreweryId);
            ViewData["TypeId"]    = new SelectList(_context.BeerTypes, "Id", "Name", beer.TypeId);
            return(View(beer));
        }