Changeset e90ba32 for PostgreSqlDotnetCore
- Timestamp:
- 08/29/24 20:27:21 (3 months ago)
- Branches:
- main
- Children:
- 99d0ecc
- Parents:
- a850333
- Location:
- PostgreSqlDotnetCore
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/BlogController.cs
ra850333 re90ba32 60 60 61 61 // Список на блог постови 62 var blogPosts = await db.Blog PostControllerObj.ToListAsync();62 var blogPosts = await db.BlogUsers.ToListAsync(); 63 63 64 64 // Вземи тековниот корисник … … 105 105 blogClass.BlogPostAnswers = blogAnswers; 106 106 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 107 ViewBag.CurrentUserId = customerClass?.id; 107 108 return View(blogClass); 108 109 } … … 301 302 // POST: Customer/Delete/5 302 303 304 /* 305 [HttpPost, ActionName("Delete")] 306 [ValidateAntiForgeryToken] 307 public ActionResult DeleteConfirmed(int id) 308 { 309 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id); 310 db.BlogPostControllerObj.Remove(blogClass); 311 db.SaveChanges(); 312 return RedirectToAction("Index"); 313 } 314 */ 303 315 304 316 [HttpPost, ActionName("Delete")] … … 306 318 public ActionResult DeleteConfirmed(int id) 307 319 { 320 // Наоѓање на објектот по ID 308 321 BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id); 322 323 // Проверка дали објектот е пронајден 324 if (blogClass == null) 325 { 326 // Ако објектот не е пронајден, враќаме 404 Not Found или друга соодветна акција 327 return View(null); 328 } 329 // prvo izbrisi gi site odgovori po sot BlogId e primaren kluc vo drugata tabela 330 331 // query 332 var query = from st in db.BlogPostAnswersObj 333 where st.BlogPostConsultationid == blogClass.id 334 select st; 335 //elenaaa 336 var blogAnswers = query.ToList(); 337 foreach (BlogPostAnswers answerClass in blogAnswers) 338 { 339 db.BlogPostAnswersObj.Remove(answerClass); 340 db.SaveChanges(); 341 342 } 343 344 // Отстранување на објектот ако е пронајден 309 345 db.BlogPostControllerObj.Remove(blogClass); 310 346 db.SaveChanges(); 347 348 // Пренасочување на корисникот кон Index страницата 311 349 return RedirectToAction("Index"); 312 350 } 313 351 314 352 // GET: Customer/Delete/5 315 353 // GET: Customer/Delete/5 316 354 // GET: Customer/Delete/5 317 355 318 356 319 357 -
PostgreSqlDotnetCore/Controllers/BlogPostAnswersController.cs
ra850333 re90ba32 155 155 public ActionResult Edit([Bind(include: "id,parent_id,reply,root_post,usersID")] BlogPostAnswers answerClass) 156 156 { 157 if (ModelState.IsValid) 158 { 159 db.Entry(answerClass).State = EntityState.Modified; 157 158 BlogPostAnswers answerClassDB = db.BlogPostAnswersObj.Find(answerClass.id); 159 if (answerClassDB != null && !answerClassDB.reply.Equals(answerClass.reply)) 160 { 161 answerClassDB.reply = answerClass.reply; 162 answerClassDB.parent_id = answerClass.parent_id; 163 db.Entry(answerClassDB).State = EntityState.Modified; 160 164 db.SaveChanges(); 161 return RedirectToAction("Index"); 162 } 163 return View(answerClass); 165 //return RedirectToAction("Index"); 166 int id = answerClassDB.BlogPostConsultationid; 167 return RedirectToAction("Details", "Blog", new { id }); 168 } 169 return View(answerClassDB); 164 170 } 165 171 -
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
ra850333 re90ba32 57 57 { 58 58 // check for permission 59 bool isAuthenticated = User.Identity.IsAuthenticated; 59 60 UsersClass customerClass = await getCrrentUser(); 60 61 // set if is authenticated … … 75 76 76 77 var userPetCares = 77 await query. ToListAsync<Pet_CaresClass>();78 await query.Include(n => n.PetsClass).ToListAsync<Pet_CaresClass>(); 78 79 79 80 return View(userPetCares); … … 81 82 else 82 83 { 83 return View(db.PetCaresObj. ToList());84 return View(db.PetCaresObj.Include(n => n.PetsClass).ToList()); 84 85 } 85 86 … … 280 281 281 282 // POST: Customer/Delete/5 283 /* [HttpPost, ActionName("Delete")] 284 [ValidateAntiForgeryToken] 285 public ActionResult DeleteConfirmed(int id) 286 { 287 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 288 db.PetCaresObj.Remove(peClass); 289 db.SaveChanges(); 290 return RedirectToAction("Index"); 291 } 292 */ 293 282 294 [HttpPost, ActionName("Delete")] 283 295 [ValidateAntiForgeryToken] 284 public ActionResult DeleteConfirmed(int id) 285 { 286 Pet_CaresClass peClass = db.PetCaresObj.Find(id); 296 public async Task<ActionResult> DeleteConfirmed(int id) 297 { 298 Pet_CaresClass peClass = await db.PetCaresObj.FindAsync(id); 299 if (peClass == null) 300 { 301 return RedirectToAction("NotExist", "Error"); 302 } 287 303 db.PetCaresObj.Remove(peClass); 288 db.SaveChanges();304 await db.SaveChangesAsync(); 289 305 return RedirectToAction("Index"); 290 306 } -
PostgreSqlDotnetCore/Data/ApplicationDbContext.cs
ra850333 re90ba32 60 60 base.OnModelCreating(modelBuilder); 61 61 62 63 modelBuilder.Entity<BlogUsers>().HasNoKey().ToView("view_userss_consultationss"); 64 base.OnModelCreating(modelBuilder); 62 65 // Configure the relationship between VetCenter and CitiesClass 63 64 66 65 67 68 66 69 // ... model definition ... 67 70 } … … 73 76 public virtual DbSet<VetCenterWithCity> VetCentersWithCity { get; set; } 74 77 78 public virtual DbSet<BlogUsers> BlogUsers { get; set; } 75 79 public virtual DbSet<BlogPostConsultation> BlogPostControllerObj { get; set; } 76 80 public virtual DbSet<RolesClass> RoleControllerObj { get; set; } -
PostgreSqlDotnetCore/Models/Pet_CaresClass.cs
ra850333 re90ba32 22 22 public DateTime start_date { get; set; } 23 23 24 //[ForeignKey("PetsClass")]25 // [Column("petid")]24 [ForeignKey("PetsClass")] 25 [Column("pet_id")] 26 26 public int pet_id { get; set; } 27 //public PetsClass PetsClass { get; set; }27 public PetsClass PetsClass { get; set; } 28 28 29 29 -
PostgreSqlDotnetCore/Views/Blog/Details.cshtml
ra850333 re90ba32 77 77 78 78 <td> 79 @Html.ActionLink("Edit", "Edit", "BlogPostAnswers", new { id = item.id }) | 80 @Html.ActionLink("Details", "Details", "BlogPostAnswers", new { id = item.id }) | 81 @Html.ActionLink("Delete", "Delete", "BlogPostAnswers", new { id = item.id }) 82 79 80 @Html.ActionLink("Details", "Details", "BlogPostAnswers", new { id = item.id }) 83 81 @Html.ActionLink("Create an Answer", "Create", "BlogPostAnswers", new { id = item.BlogPostConsultationid, parentId = item.id }) 84 82 </td> 83 84 @if (item.usersid == ViewBag.CurrentUserId) 85 86 { 87 <td> 88 89 @Html.ActionLink("Edit", "Edit", "BlogPostAnswers", new { id = item.id }) 90 @Html.ActionLink("Delete", "Delete", "BlogPostAnswers", new { id = item.id }) 91 92 93 </td> 94 } 95 96 85 97 </tr> 86 98 } … … 90 102 <p> 91 103 @Html.ActionLink("Create an Answer", "Create", "BlogPostAnswers", new { id = Model.id, parentId = Model.id }) 92 @Html.ActionLink("Edit", "Edit", new { id = Model.id }) |93 104 @Html.ActionLink("Back to List", "Index") 94 105 </p> 106 107 108 @if (Model.users_id == ViewBag.CurrentUserId) 109 110 { 111 <p> 112 @Html.ActionLink("Edit", "Edit", new { id = Model.id }) 113 114 115 </p> 116 } -
PostgreSqlDotnetCore/Views/Blog/Index.cshtml
ra850333 re90ba32 1 @model IEnumerable<PostgreSqlDotnetCore.Models.Blog PostConsultation>1 @model IEnumerable<PostgreSqlDotnetCore.Models.BlogUsers> 2 2 3 3 @{ … … 14 14 15 15 <th> 16 @Html.DisplayNameFor(model => model. date_askes)16 @Html.DisplayNameFor(model => model.id) 17 17 </th> 18 18 <th> 19 @Html.DisplayNameFor(model => model. title)19 @Html.DisplayNameFor(model => model.user_name) 20 20 </th> 21 21 <th> 22 @Html.DisplayNameFor(model => model. description)22 @Html.DisplayNameFor(model => model.user_email) 23 23 </th> 24 24 <th> 25 @Html.DisplayNameFor(model => model.users_id) 25 @Html.DisplayNameFor(model => model.consultation_title) 26 </th> 27 <th> 28 @Html.DisplayNameFor(model => model.consultation_description) 29 </th> 30 <th> 31 @Html.DisplayNameFor(model => model.consultation_date) 26 32 </th> 27 33 <th></th> … … 33 39 <tr> 34 40 <td> 35 @Html.DisplayFor(modelItem => item. date_askes)41 @Html.DisplayFor(modelItem => item.id) 36 42 </td> 37 43 <td> 38 @Html.DisplayFor(modelItem => item. title)44 @Html.DisplayFor(modelItem => item.user_name) 39 45 </td> 40 41 46 <td> 42 @Html.DisplayFor(model Item => item.description)47 @Html.DisplayFor(model => item.user_email) 43 48 </td> 44 <th> 45 @Html.DisplayFor(model => item.users_id) 46 </th> 49 <td> 50 @Html.DisplayFor(modelItem => item.consultation_title) 51 </td> 52 <td> 53 @Html.DisplayFor(modelItem => item.consultation_description) 54 </td> 55 <td> 56 @Html.DisplayFor(modelItem => item.consultation_date) 57 </td> 47 58 48 59 @*<td> -
PostgreSqlDotnetCore/Views/PetCares/Index.cshtml
ra850333 re90ba32 31 31 @Html.DisplayNameFor(model => model.vetcentersid) 32 32 </th> 33 <th> 34 @Html.DisplayNameFor(model => model.PetsClass.name) 35 </th> 33 36 34 37 <th></th> … … 36 39 </tr> 37 40 38 @foreach (var item in Model) { 39 <tr> 40 <td> 41 @Html.DisplayFor(modelItem => item.title) 42 </td> 43 <td> 44 @Html.DisplayFor(modelItem => item.description) 45 </td> 46 <td> 47 @Html.DisplayFor(modelItem => item.dateending) 48 </td> 41 @foreach (var item in Model) 42 { 43 <tr> 44 <td> 45 @Html.DisplayFor(modelItem => item.title) 46 </td> 47 <td> 48 @Html.DisplayFor(modelItem => item.description) 49 </td> 50 <td> 51 @Html.DisplayFor(modelItem => item.dateending) 52 </td> 49 53 <td> 50 54 @Html.DisplayFor(modelItem => item.start_date) 51 55 </td> 52 <td> 53 @Html.DisplayFor(modelItem => item.usersid) 54 </td> 55 <td> 56 @Html.DisplayFor(modelItem => item.vetcentersid) 57 </td> 56 <td> 57 @Html.DisplayFor(modelItem => item.usersid) 58 </td> 59 <td> 60 @Html.DisplayFor(modelItem => item.vetcentersid) 61 </td> 62 <td> 63 @Html.DisplayFor(modelItem => item.PetsClass.name) 64 </td> 58 65 59 66 60 67 61 <td>62 @Html.ActionLink("Edit", "Edit", new { id = item.id }) |63 @Html.ActionLink("Details", "Details", new { id = item.id }) |64 @Html.ActionLink("Delete", "Delete", new { id = item.id })65 </td>66 </tr>67 }68 <td> 69 @Html.ActionLink("Edit", "Edit", new { id = item.id }) | 70 @Html.ActionLink("Details", "Details", new { id = item.id }) | 71 @Html.ActionLink("Delete", "Delete", new { id = item.id }) 72 </td> 73 </tr> 74 } 68 75 69 76 </table>
Note:
See TracChangeset
for help on using the changeset viewer.