- Timestamp:
- 08/23/24 03:03:32 (3 months ago)
- Branches:
- main
- Children:
- 118e414
- Parents:
- 57fc402
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.