Exemplo n.º 1
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            try
            {
                if (IsAdmin())
                {
                    //Erase UID of buyer


                    // _context.Update(users);
                    //await _context.SaveChangesAsync();
                    var personsToUpdate = _context.Products.Where(o => o.UID == id);
                    foreach (Products p in personsToUpdate)
                    {
                        p.UID = null;
                    }

                    _context.SaveChanges();



                    var users = await _context.Users.FindAsync(id);

                    // var product = await _context.Products.FindAsync(users.UID);

                    _context.Users.Remove(users);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "Home"));
            }
        }