Changeset e9bb9d1 for PostgreSqlDotnetCore/Controllers
- Timestamp:
- 08/28/24 21:41:13 (3 months ago)
- Branches:
- main
- Children:
- a850333
- Parents:
- 118e414
- Location:
- PostgreSqlDotnetCore/Controllers
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
r118e414 re9bb9d1 89 89 } 90 90 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id); 91 UsersClass customerClass = await getCrrentUser(); 92 ViewBag.isAuthenticated = customerClass; 91 93 if (blogClass == null) 92 94 { … … 102 104 var blogAnswers = query.ToList(); 103 105 blogClass.BlogPostAnswers = blogAnswers; 106 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 104 107 return View(blogClass); 105 108 } … … 121 124 122 125 // check for permission 123 UsersClass customerClass = await getCrrentUser(); 126 //UsersClass customerClass = await checkAuthorizationAsync(); 127 // ViewBag.isAuthenticated = await getCrrentUser(); 128 UsersClass customerClass = await getCrrentUser(); 124 129 // set if is authenticated 125 130 ViewBag.isAuthenticated = customerClass; … … 143 148 var user = await _userManager.GetUserAsync(User); 144 149 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 150 //dodadeno na 25.08 151 ViewBag.isAuthenticated = await getCrrentUser(); 145 152 if (customerClass != null) 146 153 { … … 184 191 } 185 192 186 // check for permission 187 UsersClass customerClass = await checkAuthorizationAsync(); 188 //dodadeno na 23.08 193 // izbriseno na 26.08 194 UsersClass customerClass = await checkAuthorizationAsync(); 195 //dodadeno na 26.08 196 // UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 189 197 ViewBag.isAuthenticated = await getCrrentUser(); 190 198 if (customerClass == null) … … 204 212 // no access for standard user 205 213 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 214 ViewBag.OnlyAdminManager1 = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 206 215 207 216 … … 233 242 if (existingBlogClass != null) 234 243 { 244 245 235 246 // Запамтете ја старата вредност на users_id 236 247 blogClass.users_id = existingBlogClass.users_id; … … 247 258 248 259 // GET: Customer/Delete/5 260 249 261 public async Task<ActionResult> DeleteAsync(int? id) 250 262 { … … 286 298 } 287 299 300 288 301 // POST: Customer/Delete/5 289 302 … … 298 311 return RedirectToAction("Index"); 299 312 } 313 314 // GET: Customer/Delete/5 315 // GET: Customer/Delete/5 316 // GET: Customer/Delete/5 317 318 300 319 301 320 protected override void Dispose(bool disposing) -
PostgreSqlDotnetCore/Controllers/BlogPostAnswersController.cs
r118e414 re9bb9d1 14 14 15 15 // GET: Customer 16 public ActionResult Index() 17 { 18 //return View(Enumerable.Empty<UsersClass>()); 16 //public ActionResult Index() 17 public async Task<ActionResult> IndexAsync() 18 { 19 //return View(Enumerable.Empty<UsersClass>()); 20 UsersClass customerClass = await getCrrentUser(); 21 22 // set if is authenticated 23 ViewBag.isAuthenticated = customerClass; 24 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 19 25 return View(db.BlogPostAnswersObj.ToList()); 20 26 } 21 27 28 29 30 22 31 // GET: Customer/Details/5 23 public ActionResult Details(int? id) 32 // public ActionResult Details(int? id) 33 public async Task<ActionResult> Details(int? id) 24 34 { 25 35 if (id == null) … … 27 37 return RedirectToAction("NotExist", "Error"); 28 38 } 39 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 40 ViewBag.isAuthenticated = customerClass; 29 41 BlogPostAnswers answerClass = db.BlogPostAnswersObj.Find(id); 30 42 if (answerClass == null) … … 32 44 return RedirectToAction("NotExist", "Error"); 33 45 } 46 47 48 // query 49 var query = from st in db.BlogPostAnswersObj 50 where st.parent_id == answerClass.id 51 select st; 52 //elenaaa 53 var answersUnderA = query.Where(x => x.id != answerClass.id).ToList(); 54 55 answerClass.blogPostAnswers = answersUnderA; 56 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 34 57 return View(answerClass); 35 58 } … … 46 69 // check for permission 47 70 UsersClass customerClass = await checkAuthorizationAsync(); 71 // UsersClass customerClass = await getCrrentUser(); 72 // set if is authenticated 73 ViewBag.isAuthenticated = customerClass; 48 74 if (customerClass == null) 49 75 { 50 76 return RedirectToAction("AccessDenied", "Error"); 51 77 } 78 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 52 79 return View(); 53 80 } … … 90 117 return RedirectToAction("Details", "Blog", new { id }); 91 118 } 119 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 92 120 93 121 return View(answerClass); … … 139 167 public async Task<ActionResult> DeleteAsync(int? id) 140 168 { 169 141 170 if (id == null) 142 171 { … … 159 188 } 160 189 } 161 return View(answerClass); 190 // return View(answerClass); 191 return View(answerClass); 162 192 } 163 193 -
PostgreSqlDotnetCore/Controllers/HomeController.cs
r118e414 re9bb9d1 1 1 using Microsoft.AspNetCore.Identity; 2 2 using Microsoft.AspNetCore.Mvc; 3 using Microsoft.EntityFrameworkCore; 3 4 using PostgreSqlDotnetCore.Data; 4 5 using PostgreSqlDotnetCore.Models; … … 30 31 if (user != null) 31 32 { 32 UsersClass customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);33 UsersClass customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 33 34 if (customerClass == null) 34 35 { … … 43 44 lastName = nameLastName[0].Split('.')[1]; 44 45 } 45 } catch(Exception ex) { 46 } 47 catch (Exception ex) 48 { 46 49 } 47 50 db.CustomerObj.Add(new UsersClass( … … 65 68 } 66 69 67 } else 70 } 71 else 68 72 { 69 73 ViewBag.isAuthenticated = null; … … 86 90 public async Task<IActionResult> ContactAsync() 87 91 { 92 93 //var query = db.Database.ExecuteSqlRaw("CALL get_pet_details()"); 94 //var query = db.Database.ExecuteSqlRaw("SELECT * FROM get_pet_details()"); 95 96 88 97 // set if is authenticated 89 98 ViewBag.isAuthenticated = await getCrrentUser(); -
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
r118e414 re9bb9d1 36 36 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 37 37 38 39 // check if the user is authenticated so we can take only his pets 40 if (customerClass != null) 41 { 42 var queryPetsByUser = from st in db.PetsObj 43 where st.usersid == customerClass.id 44 select st; 45 var userPets = await queryPetsByUser.ToListAsync<PetsClass>(); 46 ViewBag.Pets = new SelectList(userPets, "id", "name"); 47 48 } 38 49 return View(); 39 50 } … … 63 74 select st; 64 75 65 var userPets = 66 //db.PetCaresObj.FromSql($"SELECT * FROM pets where usersid={customerClass.id}").ToListAsync(); 76 var userPetCares = 67 77 await query.ToListAsync<Pet_CaresClass>(); 68 78 69 return View(userPets); 70 71 PetCareAllData petCareAllData = new PetCareAllData(); 72 petCareAllData.PetCares = userPets; 73 74 75 // query 76 var queryVetCenters = from kk in db.VetCentersObj 77 select kk; 78 79 // query 80 var queryUsers = from st in db.CustomerObj 81 select st; 82 83 var users = await queryUsers.ToListAsync<UsersClass>(); 84 petCareAllData.Users = users; 85 86 //var vetCenters = await queryVetCenters.ToListAsync<VetCenter>(); 87 //petCareAllData.VetCenters = vetCenters; 88 89 return View(petCareAllData); 79 return View(userPetCares); 90 80 } 91 81 else … … 133 123 [HttpPost] 134 124 [ValidateAntiForgeryToken] 135 public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid ")] Pet_CaresClass peClass)125 public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid, pet_id")] Pet_CaresClass peClass) 136 126 { 137 127 bool isAuthenticated = User.Identity.IsAuthenticated; … … 143 133 // no access for standard user 144 134 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 145 135 UsersClass customerClass = null; 146 136 if (ModelState.IsValid) 147 137 { … … 150 140 peClass.start_date = DateTime.SpecifyKind(peClass.start_date, DateTimeKind.Utc); 151 141 var user = await _userManager.GetUserAsync(User); 152 varcustomerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);142 customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 153 143 peClass.usersid = customerClass.id; 154 144 db.PetCaresObj.Add(peClass); … … 159 149 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 160 150 161 return View(peClass); 162 } 163 164 165 166 167 168 169 151 152 var queryPetsByUser = from st in db.PetsObj 153 where st.usersid == customerClass.id 154 select st; 155 var userPets =await queryPetsByUser.ToListAsync<PetsClass>(); 156 ViewBag.Pets= new SelectList(userPets, "id", "name"); 157 158 159 return View(peClass); 160 } 170 161 171 162 … … 219 210 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name", peClass.vetcentersid); 220 211 // dodadeno na 22.08 221 ViewBag.isAuthenticated = await getCrrentUser(); 212 UsersClass customerClass = await getCrrentUser(); 213 // check if the user is authenticated so we can take only his pets 214 if (customerClass != null) 215 { 216 var queryPetsByUser = from st in db.PetsObj 217 where st.usersid == customerClass.id 218 select st; 219 var userPets = await queryPetsByUser.ToListAsync<PetsClass>(); 220 ViewBag.Pets = new SelectList(userPets, "id", "name"); 221 222 } 223 ViewBag.isAuthenticated = customerClass; 222 224 return View(peClass); 223 225 } … … 230 232 [HttpPost] 231 233 [ValidateAntiForgeryToken] 232 public async Task<ActionResult> EditAsync([Bind(include: "id,title,description,dateending, vetcentersid ")] Pet_CaresClass peClass)234 public async Task<ActionResult> EditAsync([Bind(include: "id,title,description,dateending, vetcentersid, pet_id")] Pet_CaresClass peClass) 233 235 { 234 236 bool isAuthenticated = User.Identity.IsAuthenticated; -
PostgreSqlDotnetCore/Controllers/PetsController.cs
r118e414 re9bb9d1 31 31 if (customerClass.role_id == RoleConstants.Standard) 32 32 { 33 // kco33 // filter user pets by UserID 34 34 var query = from st in db.PetsObj 35 35 where st.usersid == customerClass.id -
PostgreSqlDotnetCore/Controllers/ProductsController.cs
r118e414 re9bb9d1 48 48 } 49 49 50 51 50 52 // GET: Customer/Details/5 51 53 public async Task<ActionResult> Details(int? id) … … 55 57 return RedirectToAction("NotExist", "Error"); 56 58 } 57 UsersClass customerClass = await getCrrentUser(); 59 // додано на 28.08 60 61 62 63 64 UsersClass customerClass = await getCrrentUser(); 58 65 ViewBag.isAuthenticated = customerClass; 59 66 ProductsClass prodClass = db.ProductObj.Find(id); -
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.