Example #1
0
        private async Task <IActionResult> saveVote(int nextBeer)
        {
            if (CurrentVote.VoteId == -1)
            {
                var vote = new Vote()
                {
                    Appearance = CurrentVote.Appearance,
                    Note       = CurrentVote.Note,
                    Taste      = CurrentVote.Taste,
                    Overall    = CurrentVote.Overall,
                    BeerId     = CurrentVote.BeerId,
                    TasterId   = CurrentVote.TasterId,
                    TastingId  = CurrentVote.TastingId
                };

                if (!vote.IsBlank())
                {
                    _context.Vote.Add(vote);
                    await _context.SaveChangesAsync();
                }
            }
            else
            {
                var vote = await _context.Vote.FirstOrDefaultAsync(x => x.VoteId == CurrentVote.VoteId);

                vote.Note       = CurrentVote.Note;
                vote.Appearance = CurrentVote.Appearance;
                vote.BeerId     = CurrentVote.BeerId;
                vote.Overall    = CurrentVote.Overall;
                vote.Taste      = CurrentVote.Taste;
                vote.TasterId   = CurrentVote.TasterId;
                vote.TastingId  = CurrentVote.TastingId;

                _context.Vote.Update(vote);
                await _context.SaveChangesAsync();
            }

            var tastingId = CurrentVote.TastingId;

            return(RedirectToAction("OnGetAsync", new { id = tastingId, beernumber = nextBeer }));
        }