Ignore:
Timestamp:
08/28/24 21:41:13 (3 months ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
a850333
Parents:
118e414
Message:

Use of views

  1. Use of views in VetCenters.
  2. Ability to provide a response to a given response.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/PetCaresController.cs

    r118e414 re9bb9d1  
    3636            ViewBag.VetCenters = new SelectList(vetCenters, "id", "name");
    3737
     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            }
    3849            return View();
    3950        }
     
    6374                            select st;
    6475
    65                 var userPets =
    66                     //db.PetCaresObj.FromSql($"SELECT * FROM pets where usersid={customerClass.id}").ToListAsync();
     76                var userPetCares =
    6777                    await query.ToListAsync<Pet_CaresClass>();
    6878
    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);
    9080            }
    9181            else
     
    133123        [HttpPost]
    134124        [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)
    136126        {
    137127            bool isAuthenticated = User.Identity.IsAuthenticated;
     
    143133            // no access for standard user
    144134            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    145 
     135            UsersClass customerClass =  null;
    146136            if (ModelState.IsValid)
    147137            {
     
    150140                peClass.start_date = DateTime.SpecifyKind(peClass.start_date, DateTimeKind.Utc);
    151141                var user = await _userManager.GetUserAsync(User);
    152                 var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);
     142                customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);
    153143                peClass.usersid = customerClass.id;
    154144                db.PetCaresObj.Add(peClass);
     
    159149            ViewBag.VetCenters = new SelectList(vetCenters, "id", "name");
    160150
    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        }
    170161
    171162
     
    219210            ViewBag.VetCenters = new SelectList(vetCenters, "id", "name", peClass.vetcentersid);
    220211            // 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;
    222224            return View(peClass);
    223225        }
     
    230232        [HttpPost]
    231233        [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)
    233235        {
    234236            bool isAuthenticated = User.Identity.IsAuthenticated;
Note: See TracChangeset for help on using the changeset viewer.