Ignore:
Timestamp:
08/28/24 21:41:13 (4 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
a850333
Parents:
118e414
Message:

Use of views

  1. Use of views in VetCenters.
  2. Ability to provide a response to a given response.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/VetCenterController.cs

    r118e414 re9bb9d1  
    55using Microsoft.AspNetCore.Mvc.Rendering;
    66using System.Threading.Tasks;
     7using Npgsql;
     8using PostgreSqlDotnetCore.Data;
    79
    810namespace PostgreSqlDotnetCore.Controllers
     
    1012    public class VetCenterController : BaseController
    1113    {
    12         public VetCenterController(UserManager<IdentityUser> userManager) : base(userManager)
    13         {
     14        /* 
     15         public VetCenterController(UserManager<IdentityUser> userManager) : base(userManager)
     16           {
     17           }
     18        */
     19        private readonly ApplicationDbContext db;
     20
     21        public VetCenterController(UserManager<IdentityUser> userManager, ApplicationDbContext context) : base(userManager)
     22        {
     23            db = context ?? throw new ArgumentNullException(nameof(context));
    1424        }
    1525
     
    4555             return View(vetCenters);
    4656         }*/
     57        /* public async Task<ActionResult> Index()
     58         {
     59             var vetCenters = await db.VetCentersObj.ToListAsync();
     60             ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
     61             // no access for standard user
     62             ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     63
     64             // Проверете дали корисникот е администратор или менаџер
     65             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
     66             // ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     67
     68             ViewBag.hasAccess = customerClass != null;
     69
     70             return View(vetCenters);
     71         }
     72     */
    4773        public async Task<ActionResult> Index()
    4874        {
    49             var vetCenters = await db.VetCentersObj.ToListAsync();
     75            var vetCenters = await db.VetCentersWithCity.ToListAsync();
    5076            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
    5177            // no access for standard user
    5278            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    5379
    54             // Проверете дали корисникот е администратор или менаџер
     80           
    5581            UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
    56                // ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    5782
    5883            ViewBag.hasAccess = customerClass != null;
     
    6287
    6388
    64         public async Task<ActionResult> Details(int? id)
     89
     90        /*public async Task<ActionResult> Details(int? id)
    6591        {
    6692            if (id == null)
     
    82108        }
    83109
     110
     111       */
     112        public async Task<IActionResult> Details(int? id)
     113        {
     114            if (id == null)
     115            {
     116                return RedirectToAction("NotExist", "Error");
     117            }
     118
     119            // Логирајте го ID-то за дебугирање
     120            Console.WriteLine($"ID: {id}");
     121
     122            // Обидете се да најдете запис во view
     123            VetCenterWithCity vetClass = await db.VetCentersWithCity
     124                                                 .Where(v => v.id == id)
     125                                                 .FirstOrDefaultAsync();
     126            if (vetClass == null)
     127            {
     128                return RedirectToAction("NotExist", "Error");
     129            }
     130
     131           
     132            UsersClass customerClass = await getCrrentUser();
     133            ViewBag.isAuthenticated = customerClass;
     134
     135           
     136            return View(vetClass);
     137        }
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
    84150        [HttpPost]
    85151        [ValidateAntiForgeryToken]
     
    99165            return View(vetClass);
    100166        }
     167
     168   
     169
     170         /*public async Task<ActionResult> Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
     171         {
     172             // Логирање на параметрите
     173             Console.WriteLine($"Parameters: {vetClass.name}, {vetClass.adress}, {vetClass.description}, {vetClass.workinghours}, {vetClass.phonenumber}, {vetClass.latitude}, {vetClass.longitude}, {vetClass.citiesid}");
     174
     175             if (ModelState.IsValid)
     176             {
     177                 // Повик на складираната процедура
     178                 var parameters = new[]
     179                 {
     180             new NpgsqlParameter("@name", vetClass.name),
     181             new NpgsqlParameter("@adress", vetClass.adress),
     182             new NpgsqlParameter("@description", vetClass.description),
     183             new NpgsqlParameter("@workinghours", vetClass.workinghours),
     184             new NpgsqlParameter("@phonenumber", vetClass.phonenumber),
     185             new NpgsqlParameter("@latitude", (decimal)vetClass.latitude),
     186             new NpgsqlParameter("@longitude", (decimal)vetClass.longitude),
     187             new NpgsqlParameter("@citiesid", vetClass.citiesid)
     188         };
     189
     190                 await db.Database.ExecuteSqlRawAsync("CALL project.AddVetCenter(@name, @adress, @description, @workinghours, @phonenumber, @latitude, @longitude, @citiesid)", parameters);
     191
     192                 return RedirectToAction("Index");
     193             }
     194
     195             // Ако моделот не е валиден, повторно пополнете ги градовите за паѓачкиот мени
     196             var citiess = await db.CitiesObj.ToListAsync();
     197             ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid);
     198
     199             return View(vetClass);
     200         }
     201
     202         
     203
     204
     205        */
     206
     207
     208
    101209
    102210        public async Task<ActionResult> Edit(int? id)
     
    149257        }
    150258
    151         public async Task<ActionResult> Delete(int? id) {
    152              UsersClass customerClass = await checkAuthorizationAsync();
    153        
    154         ViewBag.isAuthenticated = await getCrrentUser();
    155        
     259        public async Task<ActionResult> Delete(int? id)
     260        {
     261            UsersClass customerClass = await checkAuthorizationAsync();
     262
     263            ViewBag.isAuthenticated = await getCrrentUser();
     264
    156265            if (id == null)
    157266            {
Note: See TracChangeset for help on using the changeset viewer.