Changeset 72b1da2
- Timestamp:
- 08/23/24 03:03:32 (2 months ago)
- Branches:
- main
- Children:
- 118e414
- Parents:
- 57fc402
- Location:
- PostgreSqlDotnetCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
r57fc402 r72b1da2 30 30 */ 31 31 32 public async Task<ActionResult> Index() 33 { 34 // Проверка за автентикација 35 bool isAuthenticated = User.Identity.IsAuthenticated; 36 37 if (!isAuthenticated) 38 { 39 return RedirectToAction("AccessDenied", "Error"); 40 } 41 42 // Список на блог постови 43 var blogPosts = await db.BlogPostControllerObj.ToListAsync(); 44 45 // Предавање на ViewBag за проверка на автентикација 46 ViewBag.isAuthenticated = isAuthenticated; 47 48 return View(blogPosts); 49 } 32 /* public async Task<ActionResult> Index() 33 { 34 // Проверка за автентикација 35 bool isAuthenticated = User.Identity.IsAuthenticated; 36 37 if (!isAuthenticated) 38 { 39 return RedirectToAction("AccessDenied", "Error"); 40 } 41 42 // Список на блог постови 43 var blogPosts = await db.BlogPostControllerObj.ToListAsync(); 44 45 // Предавање на ViewBag за проверка на автентикација 46 ViewBag.isAuthenticated = isAuthenticated; 47 48 return View(blogPosts); 49 }*/ 50 51 public async Task<ActionResult> Index() 52 { 53 // Проверка за автентикација 54 bool isAuthenticated = User.Identity.IsAuthenticated; 55 56 if (!isAuthenticated) 57 { 58 return RedirectToAction("AccessDenied", "Error"); 59 } 60 61 // Список на блог постови 62 var blogPosts = await db.BlogPostControllerObj.ToListAsync(); 63 64 // Вземи тековниот корисник 65 var currentUser = await _userManager.GetUserAsync(User); 66 var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email); 67 68 // Предавање на ViewBag за проверка на автентикација и корисничкиот ID 69 ViewBag.isAuthenticated = isAuthenticated; 70 ViewBag.CurrentUserId = customerClass?.id; 71 72 return View(blogPosts); 73 } 74 75 76 77 78 50 79 // GET: Customer/Details/5 51 80 public async Task<ActionResult> DetailsAsync(int? id) … … 100 129 [HttpPost] 101 130 [ValidateAntiForgeryToken] 102 103 104 105 106 107 108 109 110 111 112 113 114 131 public async Task<ActionResult> CreateAsync([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 132 { 133 if (ModelState.IsValid) 134 { 135 bool isAuthenticated = User.Identity.IsAuthenticated; 136 if (isAuthenticated) 137 { 138 var user = await _userManager.GetUserAsync(User); 139 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 140 if (customerClass != null) 141 { 142 // Поставете users_id на идентификаторот на корисникот 143 blogClass.users_id = customerClass.id; 115 144 //blogClass.date_askes = DateOnly.FromDateTime(DateTime.UtcNow); 116 145 blogClass.date_askes = DateOnly.FromDateTime(DateTime.Now); // Ова ќе стави локално време 117 146 118 147 db.BlogPostControllerObj.Add(blogClass); 119 await db.SaveChangesAsync(); 120 return RedirectToAction("Index"); 121 } 122 } 123 else 124 { 125 return RedirectToAction("AccessDenied", "Error"); 126 } 127 } 128 129 return View(blogClass); 130 } 131 132 133 148 await db.SaveChangesAsync(); 149 return RedirectToAction("Index"); 150 } 151 } 152 else 153 { 154 return RedirectToAction("AccessDenied", "Error"); 155 } 156 } 157 158 return View(blogClass); 159 } 160 161 162 163 134 164 135 165 … … 151 181 // check for permission 152 182 UsersClass customerClass = await checkAuthorizationAsync(); 183 //dodadeno na 23.08 184 ViewBag.isAuthenticated = await getCrrentUser(); 153 185 if (customerClass == null) 154 186 { … … 174 206 [HttpPost] 175 207 [ValidateAntiForgeryToken] 176 public ActionResult Edit([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 208 /* public ActionResult Edit([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 209 { 210 if (ModelState.IsValid) 211 { 212 db.Entry(blogClass).State = EntityState.Modified; 213 db.SaveChanges(); 214 return RedirectToAction("Index"); 215 } 216 return View(blogClass); 217 }*/ 218 219 220 public async Task<ActionResult> EditAsync(int id, [Bind(include: "id,date_askes,title,description")] BlogPostConsultation blogClass) 177 221 { 178 222 if (ModelState.IsValid) 179 223 { 180 db.Entry(blogClass).State = EntityState.Modified; 181 db.SaveChanges(); 182 return RedirectToAction("Index"); 183 } 184 return View(blogClass); 185 } 224 var existingBlogClass = await db.BlogPostControllerObj.FindAsync(id); 225 if (existingBlogClass != null) 226 { 227 // Запамтете ја старата вредност на users_id 228 blogClass.users_id = existingBlogClass.users_id; 229 230 db.Entry(existingBlogClass).CurrentValues.SetValues(blogClass); 231 await db.SaveChangesAsync(); 232 return RedirectToAction("Index"); 233 } 234 } 235 return View(blogClass); 236 } 237 238 186 239 187 240 // GET: Customer/Delete/5 188 public async Task<ActionResult> DeleteAsync(int? id) 189 { 241 public async Task<ActionResult> DeleteAsync(int? id) { 242 // UsersClass customerClass = await checkAuthorizationAsync(); 243 244 ViewBag.isAuthenticated = await getCrrentUser(); 245 190 246 if (id == null) 191 247 { -
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
r57fc402 r72b1da2 17 17 18 18 [HttpGet] 19 public async Task<ActionResult> Create() 20 { 19 /* public async Task<ActionResult> Create() 20 { 21 22 var vetCenters = await db.VetCentersObj.ToListAsync(); 23 24 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 25 26 return View(); 27 }*/ 28 public async Task<ActionResult> Create() 29 { 30 31 32 UsersClass customerClass = await getCrrentUser(); 21 33 34 ViewBag.isAuthenticated = customerClass; 22 35 var vetCenters = await db.VetCentersObj.ToListAsync(); 23 24 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 25 26 return View(); 27 } 36 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 37 38 return View(); 39 } 40 41 42 28 43 29 44 // GET: Customer … … 111 126 [HttpPost] 112 127 [ValidateAntiForgeryToken] 113 public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid")] Pet_CaresClass peClass) 114 { 115 bool isAuthenticated = User.Identity.IsAuthenticated; 116 if (!isAuthenticated) 117 { 118 return RedirectToAction("AccessDenied", "Error"); 119 } 128 public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid")] Pet_CaresClass peClass) 129 { 130 bool isAuthenticated = User.Identity.IsAuthenticated; 131 if (!isAuthenticated) 132 { 133 return RedirectToAction("AccessDenied", "Error"); 134 } 135 ViewBag.isAuthenticated = new UsersClass(); 136 120 137 if (ModelState.IsValid) 121 { 138 { 139 ViewBag.isAuthenticated = new UsersClass(); 122 140 peClass.dateending = DateTime.SpecifyKind(peClass.dateending, DateTimeKind.Utc); 123 peClass.start_date = DateTime.SpecifyKind(peClass.start_date, DateTimeKind.Utc); 124 var user = await _userManager.GetUserAsync(User); 125 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 126 peClass.usersid = customerClass.id; 127 db.PetCaresObj.Add(peClass); 128 db.SaveChanges(); 129 return RedirectToAction("Index"); 130 } 131 132 return View(peClass); 133 } 141 peClass.start_date = DateTime.SpecifyKind(peClass.start_date, DateTimeKind.Utc); 142 var user = await _userManager.GetUserAsync(User); 143 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 144 peClass.usersid = customerClass.id; 145 db.PetCaresObj.Add(peClass); 146 db.SaveChanges(); 147 return RedirectToAction("Index"); 148 } 149 var vetCenters = await db.VetCentersObj.ToListAsync(); 150 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 151 152 return View(peClass); 153 } 154 155 156 157 158 159 160 161 162 134 163 135 164 // GET: Customer/Edit/5 -
PostgreSqlDotnetCore/Controllers/VetCenterController.cs
r57fc402 r72b1da2 31 31 } 32 32 33 /* public async Task<ActionResult> Index() 34 { 35 36 var vetCenters = await db.VetCentersObj.ToListAsync(); 37 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 38 39 // Check if the user is an admin 40 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 41 ViewBag.hasAccess = customerClass != null; 42 43 return View(vetCenters); 44 }*/ 33 45 public async Task<ActionResult> Index() 34 46 { … … 36 48 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 37 49 38 // Check if the user is an admin50 // Проверете дали корисникот е администратор или менаџер 39 51 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 52 // ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 53 40 54 ViewBag.hasAccess = customerClass != null; 41 55 42 56 return View(vetCenters); 43 57 } 58 44 59 45 60 public async Task<ActionResult> Details(int? id) … … 124 139 } 125 140 126 public async Task<ActionResult> Delete(int? id) 127 { 141 public async Task<ActionResult> Delete(int? id) { 142 UsersClass customerClass = await checkAuthorizationAsync(); 143 144 ViewBag.isAuthenticated = await getCrrentUser(); 145 128 146 if (id == null) 129 147 { -
PostgreSqlDotnetCore/Views/Blog/Edit.cshtml
r57fc402 r72b1da2 41 41 </div> 42 42 </div> 43 <div class="form-group">43 @*<div class="form-group"> 44 44 @Html.LabelFor(model => model.users_id, htmlAttributes: new { @class = "control-label col-md-2" }) 45 45 <div class="col-md-10"> … … 48 48 </div> 49 49 </div> 50 50 *@ 51 51 <div class="form-group"> 52 52 <div class="col-md-offset-2 col-md-10"> -
PostgreSqlDotnetCore/Views/Blog/Index.cshtml
r57fc402 r72b1da2 45 45 </th> 46 46 47 47 @*<td> 48 48 @Html.ActionLink("Edit", "Edit", new { id = item.id }) | 49 49 @Html.ActionLink("Answers", "Details", new { id = item.id }) | 50 50 @Html.ActionLink("Delete", "Delete", new { id = item.id }) 51 51 </td> 52 *@ 53 54 55 56 57 @if (item.users_id == ViewBag.CurrentUserId) 58 { 59 <td> 60 @Html.ActionLink("Edit", "Edit", new { id = item.id }) 61 @Html.ActionLink("Delete", "Delete", new { id = item.id }) 62 63 </td> 64 } 65 66 67 68 @if (item.users_id == ViewBag.CurrentUserId || item.users_id != ViewBag.CurrentUserId) 69 { 70 <td> 71 72 @Html.ActionLink("Answers", "Details", new { id = item.id }) 73 74 75 </td> 76 } 77 78 79 80 81 82 52 83 </tr> 53 84 } -
PostgreSqlDotnetCore/Views/Products/Index.cshtml
r57fc402 r72b1da2 98 98 <div class="col-md-6 col-xs-6"> 99 99 <h3>@item.name</h3> 100 @if (SignInManager.IsSignedIn(User)) 100 @if (SignInManager.IsSignedIn(User) && ViewBag.hasAccess != null) 101 // SignInManager.IsSignedIn(User) && ViewBag.hasAccess != null 102 //SignInManager.IsSignedIn(User) && ViewBag.hasAccess != null && ViewBag.hasAccess == true 103 104 101 105 { 102 106 <div class="edit-crud-products"> … … 107 111 } 108 112 </div> 113 114 109 115 <div class="col-md-6 col-xs-6 price"> 110 116 <h3> -
PostgreSqlDotnetCore/Views/VetCenter/Index.cshtml
r57fc402 r72b1da2 85 85 </td> 86 86 87 @if (SignInManager.IsSignedIn(User)) 87 88 89 @* @if ((SignInManager.IsSignedIn(User))) 88 90 { 89 91 <td> … … 95 97 </td> 96 98 } 99 *@ 100 101 @* Додадете условие за проверка на улогите *@ 102 @if (SignInManager.IsSignedIn(User) && (ViewBag.hasAccess != null && ViewBag.hasAccess == true)) 103 { 104 <td> 105 @Html.ActionLink("Edit", "Edit", new { id = item.id }) | 106 @Html.ActionLink("Details", "Details", new { id = item.id }) | 107 @Html.ActionLink("Delete", "Delete", new { id = item.id }) 108 </td> 109 } 97 110 98 111 </tr>
Note:
See TracChangeset
for help on using the changeset viewer.