Changeset 118e414


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

Location:
PostgreSqlDotnetCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/BlogController.cs

    r72b1da2 r118e414  
    1313
    1414        {
    15            
     15
    1616        }
    1717
     
    4949         }*/
    5050
    51           public async Task<ActionResult> Index()
    52           {
    53               // Проверка за автентикација
    54               bool isAuthenticated = User.Identity.IsAuthenticated;
    55 
    56               if (!isAuthenticated)
    57               {
    58                   return RedirectToAction("AccessDenied", "Error");
    59               }
    60 
    61               // Список на блог постови
    62               var blogPosts = await db.BlogPostControllerObj.ToListAsync();
    63 
    64               // Вземи тековниот корисник
    65               var currentUser = await _userManager.GetUserAsync(User);
    66               var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email);
    67 
    68               // Предавање на ViewBag за проверка на автентикација и корисничкиот ID
    69               ViewBag.isAuthenticated = isAuthenticated;
    70               ViewBag.CurrentUserId = customerClass?.id;
    71 
    72               return View(blogPosts);
    73           }
    74        
    75 
    76        
     51        public async Task<ActionResult> Index()
     52        {
     53            // Проверка за автентикација
     54            bool isAuthenticated = User.Identity.IsAuthenticated;
     55
     56            if (!isAuthenticated)
     57            {
     58                return RedirectToAction("AccessDenied", "Error");
     59            }
     60
     61            // Список на блог постови
     62            var blogPosts = await db.BlogPostControllerObj.ToListAsync();
     63
     64            // Вземи тековниот корисник
     65            var currentUser = await _userManager.GetUserAsync(User);
     66            var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email);
     67
     68            // Предавање на ViewBag за проверка на автентикација и корисничкиот ID
     69            ViewBag.isAuthenticated = isAuthenticated;
     70            // no access for standard user
     71            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     72
     73            ViewBag.CurrentUserId = customerClass?.id;
     74
     75            return View(blogPosts);
     76        }
     77
     78
     79
    7780
    7881
     
    121124            // set if is authenticated
    122125            ViewBag.isAuthenticated = customerClass;
     126            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     127
    123128            return View();
    124129        }
     
    197202                }
    198203            }
     204            // no access for standard user
     205            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     206
    199207
    200208            return View(blogClass);
     
    217225         }*/
    218226
    219        
     227
    220228        public async Task<ActionResult> EditAsync(int id, [Bind(include: "id,date_askes,title,description")] BlogPostConsultation blogClass)
    221229        {
     
    239247
    240248        // GET: Customer/Delete/5
    241         public async Task<ActionResult> DeleteAsync(int? id) {
    242           //  UsersClass customerClass = await checkAuthorizationAsync();
    243 
    244         ViewBag.isAuthenticated = await getCrrentUser();
    245        
     249        public async Task<ActionResult> DeleteAsync(int? id)
     250        {
     251            //  UsersClass customerClass = await checkAuthorizationAsync();
     252
     253            ViewBag.isAuthenticated = await getCrrentUser();
     254
    246255            if (id == null)
    247            {
    248                return View(null);
    249               //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    250             }
    251            BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id);
     256            {
     257                return View(null);
     258                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     259            }
     260            BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id);
    252261            if (blogClass == null)
    253262            {
    254263                return View(null);
    255                //return HttpNotFound();
     264                //return HttpNotFound();
    256265            }
    257266            // check for permission
     
    271280                }
    272281            }
     282            // no access for standard user
     283            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     284
    273285            return View(blogClass);
    274286        }
    275287
    276288        // POST: Customer/Delete/5
    277      
     289
    278290
    279291        [HttpPost, ActionName("Delete")]
  • PostgreSqlDotnetCore/Controllers/BlogPostAnswersController.cs

    r72b1da2 r118e414  
    5858        [HttpPost]
    5959        [ValidateAntiForgeryToken]
    60         public ActionResult Create([Bind(include: "id,parent_id,reply,root_post,usersID")] BlogPostAnswers answerClass)
     60        public async Task<ActionResult> CreateAsync(int? id, int? parentId, [Bind(include: "reply")] BlogPostAnswers answerClass)
    6161        {
    62             if (ModelState.IsValid)
     62
     63            //string id = Request.Query["BlogId"];
     64            if (id == null && id > 0)
    6365            {
     66                return RedirectToAction("NotExist", "Error");
     67            }
     68            //string id = Request.Query["BlogId"];
     69            if (parentId== null && parentId > 0)
     70            {
     71                return RedirectToAction("NotExist", "Error");
     72            }
     73            if (answerClass != null && answerClass.reply.Length > 0)
     74            {
     75
     76                var user = await _userManager.GetUserAsync(User);
     77                if (user == null)
     78                {
     79                    return RedirectToAction("AccessDenied", "Error");
     80                }
     81
     82
     83                var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);
     84                answerClass.usersid = customerClass.id;
     85                answerClass.BlogPostConsultationid = (int)id;
     86                answerClass.parent_id = (int)parentId;
    6487                db.BlogPostAnswersObj.Add(answerClass);
    6588                db.SaveChanges();
    66                 return RedirectToAction("Index");
     89                //return RedirectToAction("Index");
     90                return RedirectToAction("Details", "Blog", new { id });
    6791            }
    6892
  • PostgreSqlDotnetCore/Controllers/CityController.cs

    r72b1da2 r118e414  
    1616        // GET: Customer
    1717        public async Task<ActionResult> IndexAsync()
    18          {
    19            // check for permission
    20           UsersClass customerClass = await checkAuthorizationAsync();
     18        {
     19            // check for permission
     20            UsersClass customerClass = await checkAuthorizationAsync();
     21            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
    2122
    22 
    23            if (customerClass == null)
    24              {
    25                  return RedirectToAction("AccessDenied", "Error");
    26              }
     23            if (customerClass == null)
     24            {
     25                return RedirectToAction("AccessDenied", "Error");
     26            }
    2727
    2828            var citiess = await db.CitiesObj.ToListAsync();
     29            // проба на 23.08
     30            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    2931
    3032            return View(citiess);
    3133        }
    32        
     34
    3335
    3436
     
    5052
    5153        // GET: Customer/Details/5
    52         public ActionResult Details(int? id)
     54        //public ActionResult Details(int? id)
     55        public async Task<ActionResult> Details(int? id)
    5356        {
    5457            if (id == null)
     
    5760            }
    5861            CitiesClass cityClass = db.CitiesObj.Find(id);
     62            UsersClass customerClass = await getCrrentUser();
     63            ViewBag.isAuthenticated = customerClass;
    5964            if (cityClass == null)
    6065            {
    6166                return RedirectToAction("NotExist", "Error");
    6267            }
     68            // no access for standard user
     69            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     70
    6371            return View(cityClass);
    6472        }
     
    7078        //}
    7179
    72         public ActionResult Create()
     80        //public ActionResult Create()
     81        public async Task<ActionResult> CreateAsync()
    7382        {
    74            
     83            UsersClass customerClass = await getCrrentUser();
     84            // set if is authenticated
     85            ViewBag.isAuthenticated = customerClass;
     86            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    7587            return View();
    7688        }
     
    8395        public ActionResult Create([Bind(include: "id,name")] CitiesClass cityClass)
    8496        {
     97
    8598            if (ModelState.IsValid)
    8699            {
     
    94107
    95108        // GET: Customer/Edit/5
    96         public ActionResult Edit(int? id)
     109        //  public ActionResult Edit(int? id)
     110        public async Task<ActionResult> Edit(int? id)
    97111        {
    98112            if (id == null)
     
    101115            }
    102116            CitiesClass cityClass = db.CitiesObj.Find(id);
     117            //22.08
     118            ViewBag.isAuthenticated = await getCrrentUser();
    103119            if (cityClass == null)
    104120            {
    105121                return RedirectToAction("NotExist", "Error");
    106122            }
     123            // no access for standard user
     124            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     125
    107126            return View(cityClass);
    108127        }
     
    125144
    126145        // GET: Customer/Delete/5
    127         public ActionResult Delete(int? id)
     146        // public ActionResult Delete(int? id)
     147        public async Task<ActionResult> Delete(int? id)
    128148        {
     149
     150            UsersClass customerClass = await checkAuthorizationAsync();
     151
     152            ViewBag.isAuthenticated = await getCrrentUser();
    129153            if (id == null)
    130154            {
     
    136160                return RedirectToAction("NotExist", "Error");
    137161            }
     162            // no access for standard user
     163            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     164
    138165            return View(cityClass);
    139166        }
     
    161188
    162189
    163        
     190
    164191    }
    165192}
  • PostgreSqlDotnetCore/Controllers/CustomerController.cs

    r72b1da2 r118e414  
    1919        public async Task<ActionResult> IndexAsync()
    2020        {
    21             UsersClass customerClass = await getCrrentUser();
     21           UsersClass customerClass = await getCrrentUser();
     22           
     23            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
     24            ViewBag.CanCreate = customerClass.role_id == RoleConstants.Admin || customerClass.role_id == RoleConstants.Manager;
     25            // no access for standard user
     26            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     27
    2228            if (customerClass == null)
    2329            {
     
    4147                return View(db.CustomerObj.ToList());
    4248            }
    43          
     49
     50
    4451        }
    4552
     
    5764            // check for permission
    5865            UsersClass customerClass = await getCrrentUser();
     66            ViewBag.isAuthenticated = customerClass;
    5967            if (customerClass == null)
    6068            {
     
    6775                return RedirectToAction("NotExist", "Error");
    6876            }
     77            // no access for standard user
     78            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     79
    6980            return View(customerClass);
    7081        }
     
    7384        public async Task<ActionResult> CreateAsync()
    7485        {
     86            //ViewBag.CanCreate = customerClass.role_id == RoleConstants.Admin || customerClass.role_id == RoleConstants.Manager;
     87
    7588            // check for permission
    76             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
    77             if (customerClass == null)
    78             {
    79                 return RedirectToAction("AccessDenied", "Error");
    80             }
     89            UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     90            //dodano na 23.08
     91            ViewBag.isAuthenticated = await getCrrentUser();
     92            if (customerClass == null)
     93            {
     94                return RedirectToAction("AccessDenied", "Error");
     95            }
     96            // no access for standard user
     97            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     98
    8199
    82100            return View();
     
    125143
    126144            customerClass = db.CustomerObj.Find(id);
     145            ViewBag.isAuthenticated = await getCrrentUser();
    127146            if (customerClass == null)
    128147            {
     
    130149                //return HttpNotFound();
    131150            }
     151            // no access for standard user
     152            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     153
    132154            return View(customerClass);
    133155        }
     
    159181            }
    160182            UsersClass customerClass = await getCrrentUser();
    161             if (customerClass == null)
    162             {
    163                 return RedirectToAction("AccessDenied", "Error");
    164             }
     183            ViewBag.isAuthenticated = await getCrrentUser();
     184            if (customerClass == null)
     185            {
     186                return RedirectToAction("AccessDenied", "Error");
     187            }
     188           
     189            // no access for standard user
     190            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    165191            return View(customerClass);
    166192        }
  • PostgreSqlDotnetCore/Controllers/ErrorController.cs

    r72b1da2 r118e414  
    44    using Microsoft.AspNetCore.Identity;
    55    using Microsoft.AspNetCore.Mvc;
     6    using PostgreSqlDotnetCore.Models;
    67    using System.Threading.Tasks;
    78
     
    1718            // set if is authenticated
    1819            ViewBag.isAuthenticated = await getCrrentUser();
     20            // no access for standard user
     21            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     22
    1923            return View();
    2024        }
     
    2428            // set if is authenticated
    2529            ViewBag.isAuthenticated = await getCrrentUser();
     30            // no access for standard user
     31            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     32
    2633            return View();
    2734        }
  • PostgreSqlDotnetCore/Controllers/HomeController.cs

    r72b1da2 r118e414  
    5959                    // set if is authenticated
    6060                    ViewBag.isAuthenticated = await getCrrentUser();
     61                    // проба на 23.08
     62                    // no access for standard user
     63                    ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     64
    6165                }
    6266
     
    7579            // set if is authenticated
    7680            ViewBag.isAuthenticated = await getCrrentUser();
     81            // no access for standard user
     82            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     83
    7784            return View();
    7885        }
     
    8188            // set if is authenticated
    8289            ViewBag.isAuthenticated = await getCrrentUser();
     90            // no access for standard user
     91            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     92
    8393            return View();
    8494        }
  • PostgreSqlDotnetCore/Controllers/PetCaresController.cs

    r72b1da2 r118e414  
    2626              return View();
    2727          }*/
    28          public async Task<ActionResult> Create()
    29          {
    30              
    31              
     28        public async Task<ActionResult> Create()
     29        {
     30
     31
    3232            UsersClass customerClass = await getCrrentUser();
    33            
     33
    3434            ViewBag.isAuthenticated = customerClass;
    3535            var vetCenters = await db.VetCentersObj.ToListAsync();
    36              ViewBag.VetCenters = new SelectList(vetCenters, "id", "name");
    37 
    38              return View();
    39          }
    40 
    41        
     36            ViewBag.VetCenters = new SelectList(vetCenters, "id", "name");
     37
     38            return View();
     39        }
     40
     41
    4242
    4343
     
    5353                return RedirectToAction("AccessDenied", "Error");
    5454            }
     55            // no access for standard user
     56            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     57
    5558            if (customerClass.role_id == RoleConstants.Standard)
    5659            {
    5760                // query
    58                             var query = from st in db.PetCaresObj
     61                var query = from st in db.PetCaresObj
    5962                            where st.usersid == customerClass.id
    6063                            select st;
     
    7275                // query
    7376                var queryVetCenters = from kk in db.VetCentersObj
    74                             select kk;
     77                                      select kk;
    7578
    7679                // query
     
    8588
    8689                return View(petCareAllData);
    87             } else
     90            }
     91            else
    8892            {
    8993                return View(db.PetCaresObj.ToList());
     
    99103                return RedirectToAction("NotExist", "Error");
    100104            }
    101             UsersClass customerClass = await getCrrentUser(); 
     105            UsersClass customerClass = await getCrrentUser();
    102106            ViewBag.isAuthenticated = customerClass;
    103107            Pet_CaresClass peClass = db.PetCaresObj.Find(id);
     
    106110                return RedirectToAction("NotExist", "Error");
    107111            }
     112            // no access for standard user
     113            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     114
    108115            return View(peClass);
    109116        }
     
    126133        [HttpPost]
    127134        [ValidateAntiForgeryToken]
    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        public async Task<ActionResult> CreateAsync([Bind(include: "id,title,description,dateending, start_date, usersid, vetcentersid")] Pet_CaresClass peClass)
     136        {
     137            bool isAuthenticated = User.Identity.IsAuthenticated;
     138            if (!isAuthenticated)
     139            {
     140                return RedirectToAction("AccessDenied", "Error");
     141            }
    135142            ViewBag.isAuthenticated = new UsersClass();
     143            // no access for standard user
     144            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    136145
    137146            if (ModelState.IsValid)
    138               {
     147            {
    139148                ViewBag.isAuthenticated = new UsersClass();
    140149                peClass.dateending = DateTime.SpecifyKind(peClass.dateending, DateTimeKind.Utc);
    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        
     150                peClass.start_date = DateTime.SpecifyKind(peClass.start_date, DateTimeKind.Utc);
     151                var user = await _userManager.GetUserAsync(User);
     152                var customerClass = db.CustomerObj.SingleOrDefault(x => x.email == user.Email);
     153                peClass.usersid = customerClass.id;
     154                db.PetCaresObj.Add(peClass);
     155                db.SaveChanges();
     156                return RedirectToAction("Index");
     157            }
     158            var vetCenters = await db.VetCentersObj.ToListAsync();
     159            ViewBag.VetCenters = new SelectList(vetCenters, "id", "name");
     160
     161            return View(peClass);
     162        }
     163
     164
     165
     166
     167
    159168
    160169
     
    229238            }
    230239            ViewBag.isAuthenticated = await getCrrentUser();
     240            // no access for standard user
     241            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    231242
    232243            if (ModelState.IsValid)
     
    260271                return RedirectToAction("NotExist", "Error");
    261272            }
     273            // no access for standard user
     274            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     275
    262276            return View(peClass);
    263277        }
  • 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);
  • PostgreSqlDotnetCore/Controllers/ProductsController.cs

    r72b1da2 r118e414  
    3131            ViewBag.isAuthenticated = await getCrrentUser();
    3232            ViewBag.hasAccess = await checkAuthorizationAsync();
     33            // no access for standard user
     34            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     35
    3336            if (!String.IsNullOrEmpty(searchString))
    3437            {
     
    5962                return RedirectToAction("NotExist", "Error");
    6063            }
     64            // no access for standard user
     65            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     66
    6167            return View(prodClass);
    6268        }
     
    7985                return RedirectToAction("AccessDenied", "Error");
    8086            }
     87            // no access for standard user
     88            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     89
    8190            var model = new ProductsClass
    8291            {
  • PostgreSqlDotnetCore/Controllers/VetCenterController.cs

    r72b1da2 r118e414  
    2323                return RedirectToAction("AccessDenied", "Error");
    2424            }
     25            // no access for standard user
     26            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    2527
    2628            // Fetch cities for dropdown
     
    4749            var vetCenters = await db.VetCentersObj.ToListAsync();
    4850            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
     51            // no access for standard user
     52            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    4953
    5054            // Проверете дали корисникот е администратор или менаџер
     
    6670
    6771            VetCenter vetClass = await db.VetCentersObj.FindAsync(id);
     72            UsersClass customerClass = await getCrrentUser();
     73            ViewBag.isAuthenticated = customerClass;
    6874            if (vetClass == null)
    6975            {
    7076                return RedirectToAction("NotExist", "Error");
    7177            }
     78            // no access for standard user
     79            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    7280
    7381            return View(vetClass);
     
    113121                return RedirectToAction("AccessDenied", "Error");
    114122            }
     123            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     124
    115125
    116126            // Fetch cities for dropdown
     
    154164                return RedirectToAction("NotExist", "Error");
    155165            }
     166            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     167
    156168
    157169            return View(vetClass);
  • PostgreSqlDotnetCore/Views/Blog/Details.cshtml

    r72b1da2 r118e414  
    8080                    @Html.ActionLink("Details", "Details", "BlogPostAnswers", new { id = item.id }) |
    8181                    @Html.ActionLink("Delete", "Delete", "BlogPostAnswers", new { id = item.id })
     82
     83                    @Html.ActionLink("Create an Answer", "Create", "BlogPostAnswers", new { id = item.BlogPostConsultationid, parentId = item.id })
    8284                </td>
    8385            </tr>
     
    8789</div>
    8890<p>
     91    @Html.ActionLink("Create an Answer", "Create", "BlogPostAnswers", new { id = Model.id, parentId = Model.id })
    8992    @Html.ActionLink("Edit", "Edit", new { id = Model.id }) |
    9093    @Html.ActionLink("Back to List", "Index")
  • PostgreSqlDotnetCore/Views/Blog/Index.cshtml

    r72b1da2 r118e414  
    2929    </tr>
    3030
    31 @foreach (var item in Model) {
    32     <tr>
    33         <td>
    34             @Html.DisplayFor(modelItem => item.date_askes)
    35         </td>
    36         <td>
    37             @Html.DisplayFor(modelItem => item.title)
    38         </td>
     31    @foreach (var item in Model)
     32    {
     33        <tr>
     34            <td>
     35                @Html.DisplayFor(modelItem => item.date_askes)
     36            </td>
     37            <td>
     38                @Html.DisplayFor(modelItem => item.title)
     39            </td>
    3940
    40         <td>
    41             @Html.DisplayFor(modelItem => item.description)
    42         </td>
    43         <th>
    44             @Html.DisplayFor(model => item.users_id)
    45         </th>
     41            <td>
     42                @Html.DisplayFor(modelItem => item.description)
     43            </td>
     44            <th>
     45                @Html.DisplayFor(model => item.users_id)
     46            </th>
    4647
    47        @*<td>
    48             @Html.ActionLink("Edit", "Edit", new { id = item.id }) |
    49             @Html.ActionLink("Answers", "Details", new { id = item.id }) |
    50             @Html.ActionLink("Delete", "Delete", new { id = item.id })
     48            @*<td>
     49        @Html.ActionLink("Edit", "Edit", new { id = item.id }) |
     50        @Html.ActionLink("Answers", "Details", new { id = item.id }) |
     51        @Html.ActionLink("Delete", "Delete", new { id = item.id })
    5152        </td>
    5253        *@
    53            
    5454
    5555
    5656
    57               @if (item.users_id == ViewBag.CurrentUserId)
    58               {
    59               <td>
    60             @Html.ActionLink("Edit", "Edit", new { id = item.id })
    61             @Html.ActionLink("Delete", "Delete", new { id = item.id })
    62              
    63         </td>
     57
     58            @if (item.users_id == ViewBag.CurrentUserId)
     59            {
     60                <td>
     61                    @Html.ActionLink("Edit", "Edit", new { id = item.id })
     62                    @Html.ActionLink("Delete", "Delete", new { id = item.id })
     63
     64                </td>
    6465            }
    6566
    66            
    6767
    6868            @if (item.users_id == ViewBag.CurrentUserId || item.users_id != ViewBag.CurrentUserId)
    6969            {
    7070                <td>
    71                    
    72                     @Html.ActionLink("Answers", "Details", new { id = item.id }) 
    73                    
     71
     72                    @Html.ActionLink("Answers", "Details", new { id = item.id })
     73
    7474
    7575                </td>
    7676            }
    77            
    7877
    7978
    80            
    81        
    82            
    83     </tr>
    84 }
     79
     80
     81
     82
     83        </tr>
     84    }
    8585
    8686</table>
  • PostgreSqlDotnetCore/Views/BlogPostAnswers/Create.cshtml

    r72b1da2 r118e414  
    1717    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    1818
    19     <div class="form-group">
     19   @* <div class="form-group">
    2020        @Html.LabelFor(model => model.parent_id, htmlAttributes: new { @class = "control-label col-md-2" })
    2121        <div class="col-md-10">
     
    2424        </div>
    2525    </div>
    26 
     26 *@
    2727    <div class="form-group">
    2828        @Html.LabelFor(model => model.reply, htmlAttributes: new { @class = "control-label col-md-2" })
  • PostgreSqlDotnetCore/Views/BlogPostAnswers/Details.cshtml

    r72b1da2 r118e414  
    3131<p>
    3232    @Html.ActionLink("Edit", "Edit", new { id = Model.id }) |
    33     @Html.ActionLink("Back to List", "Index")
     33    @* @Html.ActionLink("Back to List", "Index") *@
     34    <a href="javascript:void(0);" onclick="history.go(-1);">Back to List</a>
    3435</p>
  • PostgreSqlDotnetCore/Views/Customer/Index.cshtml

    r72b1da2 r118e414  
    1717    {
    1818
    19         <p>
     19       /* <p>
    2020            @Html.ActionLink("Create New", "Create")
    2121        </p>
     22        */
     23
     24        @if (ViewBag.CanCreate)
     25        {
     26            <p>
     27                @Html.ActionLink("Create New", "Create")
     28            </p>
     29        }
    2230        <table class="table">
    2331            <tr>
  • PostgreSqlDotnetCore/Views/Shared/_Layout.cshtml

    r72b1da2 r118e414  
    1313</head>
    1414<body>
    15     <h1>@(ViewBag.isAuthenticated == null ? "krij" : "prikazi")</h1>
     15    @* <h1>@(ViewBag.isAuthenticated == null ? "krij" : "prikazi")</h1> *@
    1616    <header>
    1717        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
     
    4747                                    <a class="nav-link text-dark" asp-area="" asp-controller="Customer" asp-action="Index">Manage Customers</a>
    4848                                </li>
    49                                 <li class="nav-item">
     49                               @* <li class="nav-item">
    5050                                    <a class="nav-link text-dark" asp-area="" asp-controller="City" asp-action="Index">Manage Cities</a>
    5151                                </li>
    52                                
     52                               *@
    5353                                <li class="nav-item">
    5454                                    <a class="nav-link text-dark" asp-area="" asp-controller="Blog" asp-action="Index">BlogPost</a>
     
    5656                            }
    5757
     58                         
     59
    5860                           
    5961                        }
     62                        @if (ViewBag.OnlyAdminManager != null)
     63                        {
     64                            <li class="nav-item">
     65                                <a class="nav-link text-dark" asp-area="" asp-controller="City" asp-action="Index">Manage Cities</a>
     66                            </li>
     67                        }
     68
    6069
    6170                       
Note: See TracChangeset for help on using the changeset viewer.