- Timestamp:
- 08/28/24 21:41:13 (3 months ago)
- Branches:
- main
- Children:
- a850333
- Parents:
- 118e414
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PostgreSqlDotnetCore/Controllers/PetCaresController.cs
r118e414 re9bb9d1 36 36 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 37 37 38 39 // check if the user is authenticated so we can take only his pets 40 if (customerClass != null) 41 { 42 var queryPetsByUser = from st in db.PetsObj 43 where st.usersid == customerClass.id 44 select st; 45 var userPets = await queryPetsByUser.ToListAsync<PetsClass>(); 46 ViewBag.Pets = new SelectList(userPets, "id", "name"); 47 48 } 38 49 return View(); 39 50 } … … 63 74 select st; 64 75 65 var userPets = 66 //db.PetCaresObj.FromSql($"SELECT * FROM pets where usersid={customerClass.id}").ToListAsync(); 76 var userPetCares = 67 77 await query.ToListAsync<Pet_CaresClass>(); 68 78 69 return View(userPets); 70 71 PetCareAllData petCareAllData = new PetCareAllData(); 72 petCareAllData.PetCares = userPets; 73 74 75 // query 76 var queryVetCenters = from kk in db.VetCentersObj 77 select kk; 78 79 // query 80 var queryUsers = from st in db.CustomerObj 81 select st; 82 83 var users = await queryUsers.ToListAsync<UsersClass>(); 84 petCareAllData.Users = users; 85 86 //var vetCenters = await queryVetCenters.ToListAsync<VetCenter>(); 87 //petCareAllData.VetCenters = vetCenters; 88 89 return View(petCareAllData); 79 return View(userPetCares); 90 80 } 91 81 else … … 133 123 [HttpPost] 134 124 [ValidateAntiForgeryToken] 135 public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid ")] Pet_CaresClass peClass)125 public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid, pet_id")] Pet_CaresClass peClass) 136 126 { 137 127 bool isAuthenticated = User.Identity.IsAuthenticated; … … 143 133 // no access for standard user 144 134 ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager); 145 135 UsersClass customerClass = null; 146 136 if (ModelState.IsValid) 147 137 { … … 150 140 peClass.start_date = DateTime.SpecifyKind(peClass.start_date, DateTimeKind.Utc); 151 141 var user = await _userManager.GetUserAsync(User); 152 varcustomerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);142 customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email); 153 143 peClass.usersid = customerClass.id; 154 144 db.PetCaresObj.Add(peClass); … … 159 149 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name"); 160 150 161 return View(peClass); 162 } 163 164 165 166 167 168 169 151 152 var queryPetsByUser = from st in db.PetsObj 153 where st.usersid == customerClass.id 154 select st; 155 var userPets =await queryPetsByUser.ToListAsync<PetsClass>(); 156 ViewBag.Pets= new SelectList(userPets, "id", "name"); 157 158 159 return View(peClass); 160 } 170 161 171 162 … … 219 210 ViewBag.VetCenters = new SelectList(vetCenters, "id", "name", peClass.vetcentersid); 220 211 // dodadeno na 22.08 221 ViewBag.isAuthenticated = await getCrrentUser(); 212 UsersClass customerClass = await getCrrentUser(); 213 // check if the user is authenticated so we can take only his pets 214 if (customerClass != null) 215 { 216 var queryPetsByUser = from st in db.PetsObj 217 where st.usersid == customerClass.id 218 select st; 219 var userPets = await queryPetsByUser.ToListAsync<PetsClass>(); 220 ViewBag.Pets = new SelectList(userPets, "id", "name"); 221 222 } 223 ViewBag.isAuthenticated = customerClass; 222 224 return View(peClass); 223 225 } … … 230 232 [HttpPost] 231 233 [ValidateAntiForgeryToken] 232 public async Task<ActionResult> EditAsync([Bind(include: "id,title,description,dateending, vetcentersid ")] Pet_CaresClass peClass)234 public async Task<ActionResult> EditAsync([Bind(include: "id,title,description,dateending, vetcentersid, pet_id")] Pet_CaresClass peClass) 233 235 { 234 236 bool isAuthenticated = User.Identity.IsAuthenticated;
Note:
See TracChangeset
for help on using the changeset viewer.