Ignore:
Timestamp:
08/29/24 20:27:21 (4 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
99d0ecc
Parents:
a850333
Message:

fix issues

fix bugs with nested tables
fix delete nested fk items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/PetCaresController.cs

    ra850333 re90ba32  
    5757        {
    5858            // check for permission
     59            bool isAuthenticated = User.Identity.IsAuthenticated;
    5960            UsersClass customerClass = await getCrrentUser();
    6061            // set if is authenticated
     
    7576
    7677                var userPetCares =
    77                     await query.ToListAsync<Pet_CaresClass>();
     78                    await query.Include(n => n.PetsClass).ToListAsync<Pet_CaresClass>();
    7879
    7980                return View(userPetCares);
     
    8182            else
    8283            {
    83                 return View(db.PetCaresObj.ToList());
     84                return View(db.PetCaresObj.Include(n => n.PetsClass).ToList());
    8485            }
    8586
     
    280281
    281282        // POST: Customer/Delete/5
     283        /*  [HttpPost, ActionName("Delete")]
     284          [ValidateAntiForgeryToken]
     285          public ActionResult DeleteConfirmed(int id)
     286          {
     287              Pet_CaresClass peClass = db.PetCaresObj.Find(id);
     288              db.PetCaresObj.Remove(peClass);
     289              db.SaveChanges();
     290              return RedirectToAction("Index");
     291          }
     292        */
     293
    282294        [HttpPost, ActionName("Delete")]
    283295        [ValidateAntiForgeryToken]
    284         public ActionResult DeleteConfirmed(int id)
    285         {
    286             Pet_CaresClass peClass = db.PetCaresObj.Find(id);
     296        public async Task<ActionResult> DeleteConfirmed(int id)
     297        {
     298            Pet_CaresClass peClass = await db.PetCaresObj.FindAsync(id);
     299            if (peClass == null)
     300            {
     301                return RedirectToAction("NotExist", "Error");
     302            }
    287303            db.PetCaresObj.Remove(peClass);
    288             db.SaveChanges();
     304            await db.SaveChangesAsync();
    289305            return RedirectToAction("Index");
    290306        }
Note: See TracChangeset for help on using the changeset viewer.