Ignore:
Timestamp:
08/20/24 23:14:03 (6 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
57fc402
Parents:
63bd770
Message:

Аccess permission

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/VetCenterController.cs

    r63bd770 rd6040ef  
    33using Microsoft.EntityFrameworkCore;
    44using PostgreSqlDotnetCore.Models;
     5using Microsoft.AspNetCore.Mvc.Rendering;
    56using System.Data;
    67using System.Net;
     
    1213        public VetCenterController(UserManager<IdentityUser> userManager) : base(userManager)
    1314        {
    14 
    15             // set if is authenticated
    16             ViewBag.isAuthenticated = new UsersClass();
    17         }
     15        }
     16
     17         public async Task<ActionResult> Create()
     18         {
     19             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
     20             if (customerClass == null)
     21             {
     22                 return RedirectToAction("AccessDenied", "Error");
     23             }
     24             var citiess = await db.CitiesObj.ToListAsync();
     25
     26             ViewBag.Citiess = new SelectList(citiess, "id", "name");
     27
     28             return View();
     29         }
    1830
    1931        // GET: Customer
     32        /* public ActionResult Index()
     33         {
     34             return View(db.VetCentersObj.ToList());
     35         }*/
     36
    2037        public ActionResult Index()
    2138        {
    22             return View(db.VetCentersObj.ToList());
    23         }
     39            var vetCenters = db.VetCentersObj.ToList();
     40
     41            // Составување на списокот на ветеринарни центри и проверка на автентикацијата
     42            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
     43
     44            return View(vetCenters);
     45        }
     46
    2447
    2548        // GET: Customer/Details/5
     
    3962
    4063        // GET: Customer/Create
    41         public async Task<ActionResult> CreateAsync()
    42         {
    43             // check for permission
    44             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
    45             if (customerClass == null)
    46             {
    47                 return RedirectToAction("AccessDenied", "Error");
    48             }
    49             return View();
    50         }
     64        /*  public async Task<ActionResult> CreateAsync()
     65          {
     66              // check for permission
     67              UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
     68              if (customerClass == null)
     69              {
     70                  return RedirectToAction("AccessDenied", "Error");
     71              }
     72              return View();
     73          }*/
    5174
    5275        // POST: Customer/Create
     
    5578        [HttpPost]
    5679        [ValidateAntiForgeryToken]
     80 
     81
    5782        public ActionResult Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
    5883        {
     
    85110                return RedirectToAction("AccessDenied", "Error");
    86111            }
     112            var citiess = await db.CitiesObj.ToListAsync();
     113            ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid);
    87114            return View(vetClass);
    88115        }
     
    93120        [HttpPost]
    94121        [ValidateAntiForgeryToken]
    95         public ActionResult Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
     122        /*
     123         public  ActionResult Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
     124         {
     125             if (ModelState.IsValid)
     126             {
     127                 db.Entry(vetClass).State = EntityState.Modified;
     128                 db.SaveChanges();
     129                 return RedirectToAction("Index");
     130             }
     131             return View(vetClass);
     132         }*/
     133
     134        // POST: VetCenter/Edit/5
     135
     136        public async Task<ActionResult> Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
    96137        {
    97138            if (ModelState.IsValid)
    98139            {
    99140                db.Entry(vetClass).State = EntityState.Modified;
    100                 db.SaveChanges();
     141                await db.SaveChangesAsync();
    101142                return RedirectToAction("Index");
    102143            }
    103             return View(vetClass);
    104         }
     144
     145            var citiess = await db.CitiesObj.ToListAsync();
     146            ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid);
     147
     148            return View(vetClass);
     149        }
     150
     151
    105152
    106153        // GET: Customer/Delete/5
Note: See TracChangeset for help on using the changeset viewer.