Ignore:
Timestamp:
08/23/24 15:40:14 (5 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
e9bb9d1
Parents:
72b1da2
Message:

fix access

implement multiple access pages with different roles
optimize present three structure of BlogPost and Answer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/PetsController.cs

    r72b1da2 r118e414  
    2626                return RedirectToAction("AccessDenied", "Error");
    2727            }
     28            // no access for standard user
     29            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     30
    2831            if (customerClass.role_id == RoleConstants.Standard)
    2932            {
    3033                // kco
    31                             var query = from st in db.PetsObj
     34                var query = from st in db.PetsObj
    3235                            where st.usersid == customerClass.id
    3336                            select st;
     
    3740                    await query.ToListAsync<PetsClass>();
    3841                return View(userPets);
    39             } else
     42            }
     43            else
    4044            {
    4145                return View(db.PetsObj.ToList());
     
    7478                return RedirectToAction("NotExist", "Error");
    7579            }
     80            // no access for standard user
     81            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     82
    7683
    7784            return View(peClass);
     
    109116            }
    110117            ViewBag.isAuthenticated = new UsersClass();
     118            // no access for standard user
     119            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    111120
    112121            if (ModelState.IsValid)
     
    119128                peClass.usersid = customerClass.id;
    120129                // voa go pisav tuka na 18.02
    121                // PetsClass.dateofbirthday = DateOnly.FromDateTime(DateTime.UtcNow);
     130                // PetsClass.dateofbirthday = DateOnly.FromDateTime(DateTime.UtcNow);
    122131                db.PetsObj.Add(peClass);
    123132                db.SaveChanges();
     
    143152            // додадено на 21.08
    144153            ViewBag.isAuthenticated = await getCrrentUser();
     154            // no access for standard user
     155            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     156
    145157            return View(peClass);
    146158        }
     
    167179            ViewBag.isAuthenticated = await getCrrentUser();
    168180            //ViewBag.isAuthenticated = new UsersClass();
    169            
    170              
     181            // no access for standard user
     182            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     183
     184
    171185            if (ModelState.IsValid)
    172186            {
    173187                //peClass.dateofbirthday = DateTime.SpecifyKind(peClass.dateofbirthday, DateTimeKind.Utc);
    174                
     188
    175189                var user = await _userManager.GetUserAsync(User);
    176190                var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);
     
    213227                return RedirectToAction("NotExist", "Error");
    214228            }
     229            // no access for standard user
     230            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     231
    215232
    216233            return View(peClass);
Note: See TracChangeset for help on using the changeset viewer.