예제 #1
0
        /*public override Task OnConnectedAsync()
         * {
         *  _userId = Context.UserIdentifier;
         *  Console.WriteLine(_userId);
         *
         *  return base.OnConnectedAsync();
         * }*/

        public async Task UpdateIngredientOwned(string stringId, string stringOwned)
        {
            // await Clients.All.SendAsync("UpdateIngredientOwned", user, id, owned);
            _userId = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
            try
            {
                var id    = Int32.Parse(stringId);
                var owned = Boolean.Parse(stringOwned);
                // System.Console.WriteLine(_userId + ", " + id + ", " + owned);
                // Console.WriteLine(userId);
                // Console.WriteLine("User id: " + _userId);
                Ingredient ingredient = await _context.Ingredient.FirstOrDefaultAsync(m => m.IngredientID == id && m.User == _userId);

                ingredient.Owned = owned;

                _context.Attach(ingredient).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (FormatException)
            {
                _logger.LogError("Unable to mark ingredient id " + stringId + " as owned. Unable to parse id.");
            }
            catch (DbUpdateConcurrencyException)
            {
                _logger.LogError("Error trying to access database for ingredient id " + stringId);
            }
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(item).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_dbUtil.IngredientExists(_userId, item.IngredientID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }