- Timestamp:
- 08/28/24 21:41:13 (4 weeks ago)
- Branches:
- main
- Children:
- a850333
- Parents:
- 118e414
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/VetCenterController.cs
r118e414 re9bb9d1 5 5 using Microsoft.AspNetCore.Mvc.Rendering; 6 6 using System.Threading.Tasks; 7 using Npgsql; 8 using PostgreSqlDotnetCore.Data; 7 9 8 10 namespace PostgreSqlDotnetCore.Controllers … … 10 12 public class VetCenterController : BaseController 11 13 { 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)); 14 24 } 15 25 … … 45 55 return View(vetCenters); 46 56 }*/ 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 */ 47 73 public async Task<ActionResult> Index() 48 74 { 49 var vetCenters = await db.VetCenters Obj.ToListAsync();75 var vetCenters = await db.VetCentersWithCity.ToListAsync(); 50 76 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 51 77 // no access for standard user 52 78 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 53 79 54 // Проверете дали корисникот е администратор или менаџер80 55 81 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 56 // ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);57 82 58 83 ViewBag.hasAccess = customerClass != null; … … 62 87 63 88 64 public async Task<ActionResult> Details(int? id) 89 90 /*public async Task<ActionResult> Details(int? id) 65 91 { 66 92 if (id == null) … … 82 108 } 83 109 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 84 150 [HttpPost] 85 151 [ValidateAntiForgeryToken] … … 99 165 return View(vetClass); 100 166 } 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 101 209 102 210 public async Task<ActionResult> Edit(int? id) … … 149 257 } 150 258 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 156 265 if (id == null) 157 266 {
Note:
See TracChangeset
for help on using the changeset viewer.