Changeset 57fc402 for PostgreSqlDotnetCore/Controllers/BlogController.cs
- Timestamp:
- 08/22/24 01:46:17 (3 months ago)
- Branches:
- main
- Children:
- 72b1da2
- Parents:
- d6040ef
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.