Ignore:
Timestamp:
08/20/24 23:14:03 (6 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
57fc402
Parents:
63bd770
Message:

Аccess permission

Location:
PostgreSqlDotnetCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/BlogController.cs

    r63bd770 rd6040ef  
    1111    {
    1212        public BlogController(UserManager<IdentityUser> userManager) : base(userManager)
    13         {
     13
     14        {
     15           
    1416        }
    1517
    1618        // GET: Customer
    17         public async Task<ActionResult> IndexAsync()
    18         {
    19             // check for permission
     19        /* public async Task<ActionResult> IndexAsync()
     20         {
     21             // check for permission
     22             bool isAuthenticated = User.Identity.IsAuthenticated;
     23             if (!isAuthenticated)
     24             {
     25                 return RedirectToAction("AccessDenied", "Error");
     26             }
     27             //return View(Enumerable.Empty<UsersClass>());
     28             return View(db.BlogPostControllerObj.ToList());
     29         }
     30        */
     31
     32        public async Task<ActionResult> Index()
     33        {
     34            // Проверка за автентикација
    2035            bool isAuthenticated = User.Identity.IsAuthenticated;
     36
    2137            if (!isAuthenticated)
    2238            {
    2339                return RedirectToAction("AccessDenied", "Error");
    2440            }
    25             //return View(Enumerable.Empty<UsersClass>());
    26             return View(db.BlogPostControllerObj.ToList());
    27         }
    28 
     41
     42            // Список на блог постови
     43            var blogPosts = await db.BlogPostControllerObj.ToListAsync();
     44
     45            // Предавање на ViewBag за проверка на автентикација
     46            ViewBag.isAuthenticated = isAuthenticated;
     47
     48            return View(blogPosts);
     49        }
    2950        // GET: Customer/Details/5
    3051        public async Task<ActionResult> DetailsAsync(int? id)
  • PostgreSqlDotnetCore/Controllers/CityController.cs

    r63bd770 rd6040ef  
    1616        // GET: Customer
    1717        public async Task<ActionResult> IndexAsync()
    18         {
    19             // check for permission
    20             UsersClass customerClass = await checkAuthorizationAsync();
    21             if (customerClass == null)
    22             {
    23                 return RedirectToAction("AccessDenied", "Error");
    24             }
    25             //return View(Enumerable.Empty<UsersClass>());
    26             return View(db.CitiesObj.ToList());
    27         }
     18         {
     19             // check for permission
     20             UsersClass customerClass = await checkAuthorizationAsync();
     21             if (customerClass == null)
     22             {
     23                 return RedirectToAction("AccessDenied", "Error");
     24             }
     25             //return View(Enumerable.Empty<UsersClass>());
     26             return View(db.CitiesObj.ToList());
     27         }
     28       
     29
    2830
    2931        // GET: Customer/Details/5
  • PostgreSqlDotnetCore/Controllers/ProductsController.cs

    r63bd770 rd6040ef  
    3030            // set if is authenticated
    3131            ViewBag.isAuthenticated = await getCrrentUser();
     32            ViewBag.hasAccess = await checkAuthorizationAsync();
    3233            if (!String.IsNullOrEmpty(searchString))
    3334            {
  • PostgreSqlDotnetCore/Controllers/VetCenterController.cs

    r63bd770 rd6040ef  
    33using Microsoft.EntityFrameworkCore;
    44using PostgreSqlDotnetCore.Models;
     5using Microsoft.AspNetCore.Mvc.Rendering;
    56using System.Data;
    67using System.Net;
     
    1213        public VetCenterController(UserManager<IdentityUser> userManager) : base(userManager)
    1314        {
    14 
    15             // set if is authenticated
    16             ViewBag.isAuthenticated = new UsersClass();
    17         }
     15        }
     16
     17         public async Task<ActionResult> Create()
     18         {
     19             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
     20             if (customerClass == null)
     21             {
     22                 return RedirectToAction("AccessDenied", "Error");
     23             }
     24             var citiess = await db.CitiesObj.ToListAsync();
     25
     26             ViewBag.Citiess = new SelectList(citiess, "id", "name");
     27
     28             return View();
     29         }
    1830
    1931        // GET: Customer
     32        /* public ActionResult Index()
     33         {
     34             return View(db.VetCentersObj.ToList());
     35         }*/
     36
    2037        public ActionResult Index()
    2138        {
    22             return View(db.VetCentersObj.ToList());
    23         }
     39            var vetCenters = db.VetCentersObj.ToList();
     40
     41            // Составување на списокот на ветеринарни центри и проверка на автентикацијата
     42            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
     43
     44            return View(vetCenters);
     45        }
     46
    2447
    2548        // GET: Customer/Details/5
     
    3962
    4063        // GET: Customer/Create
    41         public async Task<ActionResult> CreateAsync()
    42         {
    43             // check for permission
    44             UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
    45             if (customerClass == null)
    46             {
    47                 return RedirectToAction("AccessDenied", "Error");
    48             }
    49             return View();
    50         }
     64        /*  public async Task<ActionResult> CreateAsync()
     65          {
     66              // check for permission
     67              UsersClass customerClass = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin);
     68              if (customerClass == null)
     69              {
     70                  return RedirectToAction("AccessDenied", "Error");
     71              }
     72              return View();
     73          }*/
    5174
    5275        // POST: Customer/Create
     
    5578        [HttpPost]
    5679        [ValidateAntiForgeryToken]
     80 
     81
    5782        public ActionResult Create([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
    5883        {
     
    85110                return RedirectToAction("AccessDenied", "Error");
    86111            }
     112            var citiess = await db.CitiesObj.ToListAsync();
     113            ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid);
    87114            return View(vetClass);
    88115        }
     
    93120        [HttpPost]
    94121        [ValidateAntiForgeryToken]
    95         public ActionResult Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
     122        /*
     123         public  ActionResult Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
     124         {
     125             if (ModelState.IsValid)
     126             {
     127                 db.Entry(vetClass).State = EntityState.Modified;
     128                 db.SaveChanges();
     129                 return RedirectToAction("Index");
     130             }
     131             return View(vetClass);
     132         }*/
     133
     134        // POST: VetCenter/Edit/5
     135
     136        public async Task<ActionResult> Edit([Bind(include: "id,name,adress,description,workinghours,phonenumber,latitude,longitude,citiesid")] VetCenter vetClass)
    96137        {
    97138            if (ModelState.IsValid)
    98139            {
    99140                db.Entry(vetClass).State = EntityState.Modified;
    100                 db.SaveChanges();
     141                await db.SaveChangesAsync();
    101142                return RedirectToAction("Index");
    102143            }
    103             return View(vetClass);
    104         }
     144
     145            var citiess = await db.CitiesObj.ToListAsync();
     146            ViewBag.Citiess = new SelectList(citiess, "id", "name", vetClass.citiesid);
     147
     148            return View(vetClass);
     149        }
     150
     151
    105152
    106153        // GET: Customer/Delete/5
  • PostgreSqlDotnetCore/Views/Blog/Details.cshtml

    r63bd770 rd6040ef  
    55}
    66
    7 <h2>Details</h2>
    8 
     7@*<h2>Одговори</h2>*@
     8@*
    99<div>
    10     <h4>Blog post for consultations</h4>
     10   <h4>Blog post for consultations</h4>
    1111    <hr />
    1212    <dl class="dl-horizontal">
     
    3333            @Html.DisplayFor(model => model.description)
    3434        </dd>
     35       
    3536        <dt>
    3637            @Html.DisplayNameFor(model => model.users_id)
     
    4142        </dd>
    4243
     44
    4345    </dl>
    4446</div>
     47*@
     48
    4549<hr/>
    4650<div>
    47     <h4>Blog post anwers</h4>
     51    <h2>Answers</h2>
    4852    <hr />
    4953
  • PostgreSqlDotnetCore/Views/Blog/Index.cshtml

    r63bd770 rd6040ef  
    4747        <td>
    4848            @Html.ActionLink("Edit", "Edit", new { id = item.id }) |
    49             @Html.ActionLink("Details", "Details", new { id = item.id }) |
     49            @Html.ActionLink("Answers", "Details", new { id = item.id }) |
    5050            @Html.ActionLink("Delete", "Delete", new { id = item.id })
    5151        </td>
  • PostgreSqlDotnetCore/Views/Products/Index.cshtml

    r63bd770 rd6040ef  
    6060</style>
    6161<h2>All type of products</h2>
    62 @if (SignInManager.IsSignedIn(User))
     62@if (SignInManager.IsSignedIn(User) && ViewBag.hasAccess != null)
    6363{
    6464    <p>
  • PostgreSqlDotnetCore/Views/VetCenter/Create.cshtml

    r63bd770 rd6040ef  
    88
    99
    10 @using (Html.BeginForm()) 
     10@using (Html.BeginForm())
    1111{
    1212    @Html.AntiForgeryToken()
    13    
    14 <div class="form-horizontal">
    15     <h4>VetCenter</h4>
    16     <hr />
    17     @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    18     <div class="form-group">
    19         @Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
    20         <div class="col-md-10">
    21             @Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control" } })
    22             @Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
     13
     14    <div class="form-horizontal">
     15        <h4>VetCenter</h4>
     16        <hr />
     17        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
     18        <div class="form-group">
     19            @Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
     20            <div class="col-md-10">
     21                @Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control" } })
     22                @Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
     23            </div>
     24        </div>
     25
     26        <div class="form-group">
     27            @Html.LabelFor(model => model.adress, htmlAttributes: new { @class = "control-label col-md-2" })
     28            <div class="col-md-10">
     29                @Html.EditorFor(model => model.adress, new { htmlAttributes = new { @class = "form-control" } })
     30                @Html.ValidationMessageFor(model => model.adress, "", new { @class = "text-danger" })
     31            </div>
     32        </div>
     33        <div class="form-group">
     34            @Html.LabelFor(model => model.description, htmlAttributes: new { @class = "control-label col-md-2" })
     35            <div class="col-md-10">
     36                @Html.EditorFor(model => model.description, new { htmlAttributes = new { @class = "form-control" } })
     37                @Html.ValidationMessageFor(model => model.description, "", new { @class = "text-danger" })
     38            </div>
     39        </div>
     40        <div class="form-group">
     41            @Html.LabelFor(model => model.workinghours, htmlAttributes: new { @class = "control-label col-md-2" })
     42            <div class="col-md-10">
     43                @Html.EditorFor(model => model.workinghours, new { htmlAttributes = new { @class = "form-control" } })
     44                @Html.ValidationMessageFor(model => model.workinghours, "", new { @class = "text-danger" })
     45            </div>
     46        </div>
     47
     48        <div class="form-group">
     49            @Html.LabelFor(model => model.phonenumber, htmlAttributes: new { @class = "control-label col-md-2" })
     50            <div class="col-md-10">
     51                @Html.EditorFor(model => model.phonenumber, new { htmlAttributes = new { @class = "form-control" } })
     52                @Html.ValidationMessageFor(model => model.phonenumber, "", new { @class = "text-danger" })
     53            </div>
     54        </div>
     55        <div class="form-group">
     56            @Html.LabelFor(model => model.latitude, htmlAttributes: new { @class = "control-label col-md-2" })
     57            <div class="col-md-10">
     58                @Html.EditorFor(model => model.latitude, new { htmlAttributes = new { @class = "form-control" } })
     59                @Html.ValidationMessageFor(model => model.latitude, "", new { @class = "text-danger" })
     60            </div>
     61        </div>
     62        <div class="form-group">
     63            @Html.LabelFor(model => model.longitude, htmlAttributes: new { @class = "control-label col-md-2" })
     64            <div class="col-md-10">
     65                @Html.EditorFor(model => model.longitude, new { htmlAttributes = new { @class = "form-control" } })
     66                @Html.ValidationMessageFor(model => model.longitude, "", new { @class = "text-danger" })
     67            </div>
     68        </div>
     69        @*<div class="form-group">
     70    @Html.LabelFor(model => model.citiesid, htmlAttributes: new { @class = "control-label col-md-2" })
     71    <div class="col-md-10">
     72    @Html.EditorFor(model => model.citiesid, new { htmlAttributes = new { @class = "form-control" } })
     73    @Html.ValidationMessageFor(model => model.citiesid, "", new { @class = "text-danger" })
     74    </div>
     75    </div>*@
     76
     77        @*  <div class="form-group">
     78    <label for="citiesid">Citie:</label>
     79    <select class="form-control" id="citiesid" name="citiesid">
     80    <option value="">Select city</option>
     81    <option value="1">Скопје</option>
     82    <option value="1">Охрид</option>
     83    <option value="1">Скопје</option>
     84    <option value="1">Берово</option>
     85    <option value="2">Битола</option>
     86    <option value="3">Богданци</option>
     87    <option value="4">Валандово</option>
     88    <option value="5">Велес</option>
     89    <option value="6">Виница</option>
     90    <option value="7">Гевгелија</option>
     91    <option value="8">Гостивар</option>
     92    <option value="9">Дебар</option>
     93    <option value="10">Делчево</option>
     94    <option value="11">Демир Капија</option>
     95    <option value="12">Демир Хисар</option>
     96    <option value="13">Кавадарци</option>
     97    <option value="14">Кичево</option>
     98    <option value="15">Кочани</option>
     99    <option value="16">Кратово</option>
     100    <option value="17">Крива Паланка</option>
     101    <option value="18">Крушево</option>
     102    <option value="19">Куманово</option>
     103    <option value="20">Македонска Каменица</option>
     104    <option value="21">Македонски Брод</option>
     105    <option value="22">Неготино</option>
     106    <option value="23">Охрид</option>
     107    <option value="24">Пехчево</option>
     108    <option value="25">Прилеп</option>
     109    <option value="26">Пропиштип</option>
     110    <option value="27">Радовиш</option>
     111    <option value="28">Ресен</option>
     112    <option value="29">Свети Николе</option>
     113    <option value="30">Скопје</option>
     114    <option value="31">Струга</option>
     115    <option value="32">Струмица</option>
     116    <option value="33">Тетово</option>
     117    <option value="34">Штип</option>
     118    </select>
     119    </div>
     120    *@
     121
     122        <div class="form-group">
     123            <label asp-for="citiesid" class="control-label"></label>
     124            <select asp-for="citiesid" asp-items="ViewBag.Citiess" class="form-control"></select>
     125            <span asp-validation-for="citiesid" class="text-danger"></span>
     126        </div>
     127        <div class="form-group">
     128            <div class="col-md-offset-2 col-md-10">
     129                <input type="submit" value="Create" class="btn btn-default" />
     130            </div>
    23131        </div>
    24132    </div>
    25 
    26     <div class="form-group">
    27         @Html.LabelFor(model => model.adress, htmlAttributes: new { @class = "control-label col-md-2" })
    28         <div class="col-md-10">
    29             @Html.EditorFor(model => model.adress, new { htmlAttributes = new { @class = "form-control" } })
    30             @Html.ValidationMessageFor(model => model.adress, "", new { @class = "text-danger" })
    31         </div>
    32     </div>
    33     <div class="form-group">
    34         @Html.LabelFor(model => model.description, htmlAttributes: new { @class = "control-label col-md-2" })
    35         <div class="col-md-10">
    36             @Html.EditorFor(model => model.description, new { htmlAttributes = new { @class = "form-control" } })
    37             @Html.ValidationMessageFor(model => model.description, "", new { @class = "text-danger" })
    38         </div>
    39     </div>
    40     <div class="form-group">
    41         @Html.LabelFor(model => model.workinghours, htmlAttributes: new { @class = "control-label col-md-2" })
    42         <div class="col-md-10">
    43             @Html.EditorFor(model => model.workinghours, new { htmlAttributes = new { @class = "form-control" } })
    44             @Html.ValidationMessageFor(model => model.workinghours, "", new { @class = "text-danger" })
    45         </div>
    46     </div>
    47 
    48     <div class="form-group">
    49         @Html.LabelFor(model => model.phonenumber, htmlAttributes: new { @class = "control-label col-md-2" })
    50         <div class="col-md-10">
    51             @Html.EditorFor(model => model.phonenumber, new { htmlAttributes = new { @class = "form-control" } })
    52             @Html.ValidationMessageFor(model => model.phonenumber, "", new { @class = "text-danger" })
    53         </div>
    54     </div>
    55     <div class="form-group">
    56         @Html.LabelFor(model => model.latitude, htmlAttributes: new { @class = "control-label col-md-2" })
    57         <div class="col-md-10">
    58             @Html.EditorFor(model => model.latitude, new { htmlAttributes = new { @class = "form-control" } })
    59             @Html.ValidationMessageFor(model => model.latitude, "", new { @class = "text-danger" })
    60         </div>
    61     </div>
    62     <div class="form-group">
    63         @Html.LabelFor(model => model.longitude, htmlAttributes: new { @class = "control-label col-md-2" })
    64         <div class="col-md-10">
    65             @Html.EditorFor(model => model.longitude, new { htmlAttributes = new { @class = "form-control" } })
    66             @Html.ValidationMessageFor(model => model.longitude, "", new { @class = "text-danger" })
    67         </div>
    68     </div>
    69     @*<div class="form-group">
    70             @Html.LabelFor(model => model.citiesid, htmlAttributes: new { @class = "control-label col-md-2" })
    71             <div class="col-md-10">
    72                 @Html.EditorFor(model => model.citiesid, new { htmlAttributes = new { @class = "form-control" } })
    73                 @Html.ValidationMessageFor(model => model.citiesid, "", new { @class = "text-danger" })
    74             </div>
    75         </div>*@
    76 
    77     <div class="form-group">
    78         <label for="citiesid">Citie:</label>
    79         <select class="form-control" id="citiesid" name="citiesid">
    80             <option value="">Select city</option>
    81             <option value="1">Скопје</option>
    82             <option value="1">Охрид</option>
    83             <option value="1">Скопје</option>
    84            @*  <option value="1">Берово</option>
    85             <option value="2">Битола</option>
    86             <option value="3">Богданци</option>
    87             <option value="4">Валандово</option>
    88             <option value="5">Велес</option>
    89             <option value="6">Виница</option>
    90             <option value="7">Гевгелија</option>
    91             <option value="8">Гостивар</option>
    92             <option value="9">Дебар</option>
    93             <option value="10">Делчево</option>
    94             <option value="11">Демир Капија</option>
    95             <option value="12">Демир Хисар</option>
    96             <option value="13">Кавадарци</option>
    97             <option value="14">Кичево</option>
    98             <option value="15">Кочани</option>
    99             <option value="16">Кратово</option>
    100             <option value="17">Крива Паланка</option>
    101             <option value="18">Крушево</option>
    102             <option value="19">Куманово</option>
    103             <option value="20">Македонска Каменица</option>
    104             <option value="21">Македонски Брод</option>
    105             <option value="22">Неготино</option>
    106             <option value="23">Охрид</option>
    107             <option value="24">Пехчево</option>
    108             <option value="25">Прилеп</option>
    109             <option value="26">Пропиштип</option>
    110             <option value="27">Радовиш</option>
    111             <option value="28">Ресен</option>
    112             <option value="29">Свети Николе</option>
    113             <option value="30">Скопје</option>
    114             <option value="31">Струга</option>
    115             <option value="32">Струмица</option>
    116             <option value="33">Тетово</option>
    117             <option value="34">Штип</option> *@
    118         </select>
    119     </div>
    120 
    121     <div class="form-group">
    122         <div class="col-md-offset-2 col-md-10">
    123             <input type="submit" value="Create" class="btn btn-default" />
    124         </div>
    125     </div>
    126 </div>
    127133}
    128134
  • PostgreSqlDotnetCore/Views/VetCenter/Edit.cshtml

    r63bd770 rd6040ef  
    7575        </div>
    7676    </div> *@
    77         <div class="form-group">
     77      @*  <div class="form-group">
    7878            <label for="citiesid">Citie:</label>
    7979            <select class="form-control" id="citiesid" name="citiesid">
     
    8484            </select>
    8585        </div>
    86 
     86        *@
     87        <div class="form-group">
     88            <label asp-for="citiesid" class="control-label"></label>
     89            <select asp-for="citiesid" asp-items="ViewBag.Citiess" class="form-control"></select>
     90            <span asp-validation-for="citiesid" class="text-danger"></span>
     91        </div>
    8792
    8893    <div class="form-group">
Note: See TracChangeset for help on using the changeset viewer.