Changeset 57fc402
- Timestamp:
- 08/22/24 01:46:17 (3 months ago)
- Branches:
- main
- Children:
- 72b1da2
- Parents:
- d6040ef
- Location:
- PostgreSqlDotnetCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
rd6040ef r57fc402 79 79 //} 80 80 81 public ActionResult Create() 82 { 83 var model = new BlogPostConsultation(); 84 return View(model); 81 /* public ActionResult Create() 82 { 83 var model = new BlogPostConsultation(); 84 return View(model); 85 }*/ 86 87 public async Task<ActionResult> CreateAsync() 88 { 89 90 // check for permission 91 UsersClass customerClass = await getCrrentUser(); 92 // set if is authenticated 93 ViewBag.isAuthenticated = customerClass; 94 return View(); 85 95 } 86 96 … … 90 100 [HttpPost] 91 101 [ValidateAntiForgeryToken] 92 public async Task<ActionResult> CreateAsync([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 93 { 94 if (ModelState.IsValid) 95 { 96 bool isAuthenticated = User.Identity.IsAuthenticated; 97 if (isAuthenticated) 98 { 99 var user = await _userManager.GetUserAsync(User); 100 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 101 blogClass.users_id = customerClass.id; 102 db.BlogPostControllerObj.Add(blogClass); 103 db.SaveChanges(); 104 return RedirectToAction("Index"); 105 } 106 else 107 { 108 return RedirectToAction("AccessDenied", "Error"); 109 } 110 } 111 112 return View(blogClass); 113 } 102 public async Task<ActionResult> CreateAsync([Bind(include: "id,date_askes,title,description,users_id")] BlogPostConsultation blogClass) 103 { 104 if (ModelState.IsValid) 105 { 106 bool isAuthenticated = User.Identity.IsAuthenticated; 107 if (isAuthenticated) 108 { 109 var user = await _userManager.GetUserAsync(User); 110 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 111 if (customerClass != null) 112 { 113 // Поставете users_id на идентификаторот на корисникот 114 blogClass.users_id = customerClass.id; 115 //blogClass.date_askes = DateOnly.FromDateTime(DateTime.UtcNow); 116 blogClass.date_askes = DateOnly.FromDateTime(DateTime.Now); // Ова ќе стави локално време 117 118 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 134 135 114 136 115 137 // GET: Customer/Edit/5 -
PostgreSqlDotnetCore/Controllers/CityController.cs
rd6040ef r57fc402 17 17 public async Task<ActionResult> IndexAsync() 18 18 { 19 // check for permission 20 UsersClass customerClass = await checkAuthorizationAsync(); 21 22 23 if (customerClass == null) 24 { 25 return RedirectToAction("AccessDenied", "Error"); 26 } 27 28 var citiess = await db.CitiesObj.ToListAsync(); 29 30 return View(citiess); 31 } 32 33 34 35 36 /* public async Task<ActionResult> IndexAsync() 37 { 19 38 // check for permission 20 39 UsersClass customerClass = await checkAuthorizationAsync(); … … 26 45 return View(db.CitiesObj.ToList()); 27 46 } 28 47 */ 48 29 49 30 50 … … 138 158 base.Dispose(disposing); 139 159 } 160 161 162 163 140 164 } 141 165 } -
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
rd6040ef r57fc402 78 78 79 79 // GET: Customer/Details/5 80 public ActionResultDetails(int? id)80 public async Task<ActionResult> Details(int? id) 81 81 { 82 82 if (id == null) … … 84 84 return RedirectToAction("NotExist", "Error"); 85 85 } 86 UsersClass customerClass = await getCrrentUser(); 87 ViewBag.isAuthenticated = customerClass; 86 88 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 87 89 if (peClass == null) … … 178 180 var vetCenters = await db.VetCentersObj.ToListAsync(); 179 181 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name", peClass.vetcentersid); 180 182 // dodadeno na 22.08 183 ViewBag.isAuthenticated = await getCrrentUser(); 181 184 return View(peClass); 182 185 } … … 196 199 return RedirectToAction("AccessDenied", "Error"); 197 200 } 201 ViewBag.isAuthenticated = await getCrrentUser(); 198 202 199 203 if (ModelState.IsValid) … … 214 218 215 219 // GET: Customer/Delete/5 216 public ActionResultDelete(int? id)220 public async Task<ActionResult> Delete(int? id) 217 221 { 218 222 if (id == null) … … 220 224 return RedirectToAction("NotExist", "Error"); 221 225 } 226 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 227 ViewBag.isAuthenticated = customerClass; 222 228 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 223 229 if (peClass == null) -
PostgreSqlDotnetCore/Controllers/PetsController.cs
rd6040ef r57fc402 45 45 46 46 // GET: Customer/Details/5 47 public ActionResult Details(int? id) 47 /* public ActionResult Details(int? id) 48 { 49 if (id == null) 50 { 51 return RedirectToAction("NotExist", "Error"); 52 } 53 PetsClass peClass = db.PetsObj.Find(id); 54 if (peClass == null) 55 { 56 return RedirectToAction("NotExist", "Error"); 57 } 58 return View(peClass); 59 }*/ 60 61 public async Task<ActionResult> Details(int? id) 48 62 { 49 63 if (id == null) … … 51 65 return RedirectToAction("NotExist", "Error"); 52 66 } 53 PetsClass peClass = db.PetsObj.Find(id); 67 68 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 69 ViewBag.isAuthenticated = customerClass; 70 71 PetsClass peClass = await db.PetsObj.FindAsync(id); 54 72 if (peClass == null) 55 73 { 56 74 return RedirectToAction("NotExist", "Error"); 57 75 } 76 58 77 return View(peClass); 59 78 } … … 110 129 111 130 // GET: Customer/Edit/5 112 public ActionResult Edit(int? id) 131 // public ActionResult Edit(int? id) 132 public async Task<ActionResult> Edit(int? id) 113 133 { 114 134 if (id == null) … … 121 141 return RedirectToAction("NotExist", "Error"); 122 142 } 143 // додадено на 21.08 144 ViewBag.isAuthenticated = await getCrrentUser(); 123 145 return View(peClass); 124 146 } … … 132 154 { 133 155 bool isAuthenticated = User.Identity.IsAuthenticated; 156 ViewBag.isAuthenticated = await getCrrentUser(); 157 134 158 if (!isAuthenticated) 135 159 { … … 140 164 141 165 // set if is authenticated 142 ViewBag.isAuthenticated = new UsersClass(); 166 // додадено и избришено 167 ViewBag.isAuthenticated = await getCrrentUser(); 168 //ViewBag.isAuthenticated = new UsersClass(); 143 169 144 170 … … 158 184 159 185 // GET: Customer/Delete/5 160 public ActionResult Delete(int? id) 186 /* public ActionResult Delete(int? id) 187 { 188 if (id == null) 189 { 190 return RedirectToAction("NotExist", "Error"); 191 } 192 PetsClass peClass = db.PetsObj.Find(id); 193 if (peClass == null) 194 { 195 return RedirectToAction("NotExist", "Error"); 196 } 197 return View(peClass); 198 }*/ 199 200 public async Task<ActionResult> Delete(int? id) 161 201 { 162 202 if (id == null) … … 164 204 return RedirectToAction("NotExist", "Error"); 165 205 } 166 PetsClass peClass = db.PetsObj.Find(id); 206 207 UsersClass customerClass = await getCrrentUser(); // Добијте ја тековната улога на корисникот 208 ViewBag.isAuthenticated = customerClass; 209 210 PetsClass peClass = await db.PetsObj.FindAsync(id); 167 211 if (peClass == null) 168 212 { 169 213 return RedirectToAction("NotExist", "Error"); 170 214 } 215 171 216 return View(peClass); 172 217 } -
PostgreSqlDotnetCore/Controllers/ProductsController.cs
rd6040ef r57fc402 46 46 47 47 // GET: Customer/Details/5 48 public ActionResultDetails(int? id)48 public async Task<ActionResult> Details(int? id) 49 49 { 50 50 if (id == null) … … 52 52 return RedirectToAction("NotExist", "Error"); 53 53 } 54 UsersClass customerClass = await getCrrentUser(); 55 ViewBag.isAuthenticated = customerClass; 54 56 ProductsClass prodClass = db.ProductObj.Find(id); 55 57 if (prodClass == null) -
PostgreSqlDotnetCore/Controllers/VetCenterController.cs
rd6040ef r57fc402 4 4 using PostgreSqlDotnetCore.Models; 5 5 using Microsoft.AspNetCore.Mvc.Rendering; 6 using System.Data; 7 using System.Net; 6 using System.Threading.Tasks; 8 7 9 8 namespace PostgreSqlDotnetCore.Controllers … … 15 14 } 16 15 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(); 16 public async Task<ActionResult> Create() 17 { 18 // Set if user is authenticated 19 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 20 ViewBag.isAuthenticated = await getCrrentUser(); 21 if (customerClass == null) 22 { 23 return RedirectToAction("AccessDenied", "Error"); 24 } 25 25 26 ViewBag.Citiess = new SelectList(citiess, "id", "name"); 26 // Fetch cities for dropdown 27 var citiess = await db.CitiesObj.ToListAsync(); 28 ViewBag.Citiess = new SelectList(citiess, "id", "name"); 27 29 28 29 30 return View(); 31 } 30 32 31 // GET: Customer 32 /* public ActionResult Index() 33 { 34 return View(db.VetCentersObj.ToList()); 35 }*/ 33 public async Task<ActionResult> Index() 34 { 35 var vetCenters = await db.VetCentersObj.ToListAsync(); 36 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 36 37 37 public ActionResult Index() 38 { 39 var vetCenters = db.VetCentersObj.ToList(); 40 41 // Составување на списокот на ветеринарни центри и проверка на автентикацијата 42 ViewBag.isAuthenticated = User.Identity.IsAuthenticated; 38 // Check if the user is an admin 39 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 40 ViewBag.hasAccess = customerClass != null; 43 41 44 42 return View(vetCenters); 45 43 } 46 44 47 48 // GET: Customer/Details/5 49 public ActionResult Details(int? id) 45 public async Task<ActionResult> Details(int? id) 50 46 { 51 47 if (id == null) … … 53 49 return RedirectToAction("NotExist", "Error"); 54 50 } 55 VetCenter vetClass = db.VetCentersObj.Find(id); 51 52 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 56 53 if (vetClass == null) 57 54 { 58 55 return RedirectToAction("NotExist", "Error"); 59 }60 return View(vetClass);61 }62 63 // GET: Customer/Create64 /* public async Task<ActionResult> CreateAsync()65 {66 // check for permission67 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);68 if (customerClass == null)69 {70 return RedirectToAction("AccessDenied", "Error");71 }72 return View();73 }*/74 75 // POST: Customer/Create76 // To protect from overposting attacks, enable the specific properties you want to bind to, for77 // more details see https://go.microsoft.com/fwlink/?LinkId=317598.78 [HttpPost]79 [ValidateAntiForgeryToken]80 81 82 public ActionResult Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)83 {84 if (ModelState.IsValid)85 {86 db.VetCentersObj.Add(vetClass);87 db.SaveChanges();88 return RedirectToAction("Index");89 56 } 90 57 … … 92 59 } 93 60 94 // GET: Customer/Edit/5 95 public async Task<ActionResult> EditAsync(int? id) 61 [HttpPost] 62 [ValidateAntiForgeryToken] 63 public async Task<ActionResult> Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass) 64 { 65 if (ModelState.IsValid) 66 { 67 db.VetCentersObj.Add(vetClass); 68 await db.SaveChangesAsync(); 69 return RedirectToAction("Index"); 70 } 71 72 // If model is invalid, repopulate the cities for dropdown 73 var citiess = await db.CitiesObj.ToListAsync(); 74 ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid); 75 76 return View(vetClass); 77 } 78 79 public async Task<ActionResult> Edit(int? id) 96 80 { 97 81 if (id == null) … … 99 83 return RedirectToAction("NotExist", "Error"); 100 84 } 101 VetCenter vetClass = db.VetCentersObj.Find(id); 85 86 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 102 87 if (vetClass == null) 103 88 { 104 89 return RedirectToAction("NotExist", "Error"); 105 90 } 106 // check for permission 91 92 // Check for permission 107 93 UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin); 94 //UsersClass customerClass = await checkAuthorizationAsync(); 95 ViewBag.isAuthenticated = await getCrrentUser(); 108 96 if (customerClass == null) 109 97 { 110 98 return RedirectToAction("AccessDenied", "Error"); 111 99 } 100 101 // Fetch cities for dropdown 112 102 var citiess = await db.CitiesObj.ToListAsync(); 113 103 ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid); 104 114 105 return View(vetClass); 115 106 } 116 107 117 // POST: Customer/Edit/5118 // To protect from overposting attacks, enable the specific properties you want to bind to, for119 // more details see https://go.microsoft.com/fwlink/?LinkId=317598.120 108 [HttpPost] 121 109 [ValidateAntiForgeryToken] 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/5135 136 110 public async Task<ActionResult> Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass) 137 111 { … … 143 117 } 144 118 119 // If model is invalid, repopulate the cities for dropdown 145 120 var citiess = await db.CitiesObj.ToListAsync(); 146 121 ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid); … … 149 124 } 150 125 151 152 153 // GET: Customer/Delete/5 154 public ActionResult Delete(int? id) 126 public async Task<ActionResult> Delete(int? id) 155 127 { 156 128 if (id == null) … … 158 130 return RedirectToAction("NotExist", "Error"); 159 131 } 160 VetCenter vetClass = db.VetCentersObj.Find(id); 132 133 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 161 134 if (vetClass == null) 162 135 { 163 136 return RedirectToAction("NotExist", "Error"); 164 137 } 138 165 139 return View(vetClass); 166 140 } 167 141 168 // POST: Customer/Delete/5169 142 [HttpPost, ActionName("Delete")] 170 143 [ValidateAntiForgeryToken] 171 public ActionResultDeleteConfirmed(int id)144 public async Task<ActionResult> DeleteConfirmed(int id) 172 145 { 173 VetCenter vetClass = db.VetCentersObj.Find(id);146 VetCenter vetClass = await db.VetCentersObj.FindAsync(id); 174 147 db.VetCentersObj.Remove(vetClass); 175 db.SaveChanges();148 await db.SaveChangesAsync(); 176 149 return RedirectToAction("Index"); 177 150 } … … 186 159 } 187 160 188 189 // GET: VetCenter/Search 190 public ActionResult IndexWithSearch(string searchTerm) 161 public async Task<ActionResult> IndexWithSearch(string searchTerm) 191 162 { 192 163 if (string.IsNullOrEmpty(searchTerm)) 193 164 { 194 var vetCenters = db.VetCentersObj.ToList();165 var vetCenters = await db.VetCentersObj.ToListAsync(); 195 166 return View(vetCenters); 196 167 } 197 168 else 198 169 { 199 var searchResults = db.VetCentersObj.Where(vc => vc.name.Contains(searchTerm)).ToList();170 var searchResults = await db.VetCentersObj.Where(vc => vc.name.Contains(searchTerm)).ToListAsync(); 200 171 return View(searchResults); 201 172 } 202 173 } 203 204 205 206 174 } 207 175 } -
PostgreSqlDotnetCore/Models/BlogPostConsultation.cs
rd6040ef r57fc402 15 15 //public DateTime date_askes { get; set; } 16 16 //public DateTime date_askes { get; set; } = DateTime.UtcNow.Date; 17 public DateOnly date_askes { get; set; } = DateOnly.FromDateTime(DateTime. UtcNow);18 17 public DateOnly date_askes { get; set; } = DateOnly.FromDateTime(DateTime.Now); 18 19 19 public string title { get; set; } 20 20 -
PostgreSqlDotnetCore/Views/Blog/Create.cshtml
rd6040ef r57fc402 17 17 @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 18 18 19 <div class="form-group">19 @* <div class="form-group"> 20 20 @Html.LabelFor(model => model.date_askes, htmlAttributes: new { @class = "control-label col-md-2" }) 21 21 <div class="col-md-10"> … … 24 24 </div> 25 25 </div> 26 *@ 27 @* <div class="form-group"> 28 @Html.LabelFor(model => model.date_askes, htmlAttributes: new { @class = "control-label col-md-2" }) 29 <div class="col-md-10"> 30 @Html.EditorFor(model => model.date_askes, new { htmlAttributes = new { @class = "form-control", @type = "date", value = DateTime.UtcNow.ToString("yyyy-MM-dd") } }) 31 @Html.ValidationMessageFor(model => model.date_askes, "", new { @class = "text-danger" }) 32 </div> 33 </div> 34 *@ 35 36 37 38 39 26 40 27 41 <div class="form-group"> -
PostgreSqlDotnetCore/Views/City/Index.cshtml
rd6040ef r57fc402 16 16 @Html.DisplayNameFor(model => model.name) 17 17 </th> 18 18 19 19 <th></th> 20 20 21 21 </tr> 22 22 23 @foreach (var item in Model) { 24 <tr>25 <t d>26 @Html.DisplayFor(modelItem => item.name)27 </td>28 23 @foreach (var item in Model) 24 { 25 <tr> 26 <td> 27 @Html.DisplayFor(modelItem => item.name) 28 </td> 29 29 30 <td> 31 @Html.ActionLink("Edit", "Edit", new { id = item.id }) | 32 @Html.ActionLink("Details", "Details", new { id = item.id }) | 33 @Html.ActionLink("Delete", "Delete", new { id = item.id }) 34 </td> 35 </tr> 36 } 30 31 <td> 32 @Html.ActionLink("Edit", "Edit", new { id = item.id }) | 33 @Html.ActionLink("Details", "Details", new { id = item.id }) | 34 @Html.ActionLink("Delete", "Delete", new { id = item.id }) 35 </td> 36 </tr> 37 } 37 38 38 39 </table> -
PostgreSqlDotnetCore/Views/Shared/_Layout.cshtml
rd6040ef r57fc402 50 50 <a class="nav-link text-dark" asp-area="" asp-controller="City" asp-action="Index">Manage Cities</a> 51 51 </li> 52 52 53 <li class="nav-item"> 53 54 <a class="nav-link text-dark" asp-area="" asp-controller="Blog" asp-action="Index">BlogPost</a> 54 55 </li> 55 56 } 57 58 56 59 } 60 61 62 63 64 65 57 66 <li class="nav-item"> 58 67 <a class="nav-link text-dark" asp-area="" asp-controller="VetCenter" asp-action="Index">VetCenters</a> -
PostgreSqlDotnetCore/Views/VetCenter/Index.cshtml
rd6040ef r57fc402 9 9 <h2>Vet Center</h2> 10 10 11 <p>11 @*<p> 12 12 @Html.ActionLink("Create New", "Create") 13 13 </p> 14 *@ 15 @if (ViewBag.hasAccess != null && ViewBag.hasAccess == true) 16 { 17 <p> 18 @Html.ActionLink("Create New", "Create") 19 </p> 20 } 21 14 22 <table class="table"> 15 23 <tr>
Note:
See TracChangeset
for help on using the changeset viewer.