feat : create store and repository and interface

This commit is contained in:
2025-11-23 18:25:59 +03:30
parent 41aaef9889
commit 5774d9e204
21 changed files with 601 additions and 1 deletions
@@ -7,4 +7,5 @@
<div class="text-center d-flex flex-column w-25">
<h2 class="text-start">Pages</h2>
<a class="btn btn-secondary my-2" asp-page="Panel/Users/Index">[ Users ]</a>
<a class="btn btn-secondary my-2" asp-page="Panel/Stores/Index">[ Stores ]</a>
</div>
@@ -0,0 +1,42 @@
@page
@model Server.Pages.Panel.Stores.CreateModel
@{
var pageTitle =
$"{Resources.DataDictionary.CreateOf} {Resources.DataDictionary.Store}";
ViewData[Constants.ViewDataKeyName.PageTitle] = pageTitle;
}
<form method="post">
<section-form>
<fieldset>
<section-form-header>
@(pageTitle)
</section-form-header>
<partial name="PartialViews/_DisplayPageMessages" />
<ub-full-input asp-for="CreateViewModel.Name" />
<ub-full-input asp-for="CreateViewModel.Address" />
<ub-full-input asp-for="CreateViewModel.Mobile" />
<ub-full-input asp-for="CreateViewModel.Score" />
<ub-full-checkbox asp-for="CreateViewModel.IsActive" />
</fieldset>
<section-form-buttons>
<button-create />
<button-reset />
</section-form-buttons>
</section-form>
</form>
@@ -0,0 +1,29 @@
using Application.Aggregates.Stores;
using Application.Aggregates.Stores.ViewModels;
using Application.Aggregates.Users.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Server.Pages.Panel.Stores;
public class CreateModel(StoresApplication storesApplication) : PageModel
{
[BindProperty]
public CreateStoreViewModel CreateViewModel { get; set; } = new();
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
await storesApplication.CreateAsync(CreateViewModel);
return RedirectToPage("Index");
}
}
@@ -0,0 +1,43 @@
@page
@model Server.Pages.Panel.Stores.DeleteModel
@{
var pageTitle =
$"{Resources.DataDictionary.DeleteOf} {Resources.DataDictionary.Store}";
ViewData[Constants.ViewDataKeyName.PageTitle] = pageTitle;
}
<form method="post">
<section-form>
<input hidden asp-for="DeleteViewModel.Id" dir="ltr" />
<fieldset disabled>
<section-form-header>
@(pageTitle)
</section-form-header>
<partial name="PartialViews/_DisplayPageMessages" />
<ub-full-input asp-for="DeleteViewModel.Name" />
<ub-full-input asp-for="DeleteViewModel.Address" />
<ub-full-input asp-for="DeleteViewModel.Mobile" />
<ub-full-input asp-for="DeleteViewModel.Score" />
<ub-full-checkbox asp-for="DeleteViewModel.IsActive" />
</fieldset>
<section-form-buttons>
<button-delete />
</section-form-buttons>
</section-form>
</form>
@@ -0,0 +1,38 @@
using Application.Aggregates.Stores;
using Application.Aggregates.Stores.ViewModels;
using Application.Aggregates.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Server.Pages.Panel.Stores;
public class DeleteModel(StoresApplication storesApplication) : PageModel
{
[BindProperty]
public StoreViewModel DeleteViewModel { get; set; } = new();
public async Task<IActionResult> OnGetAsync(Guid id)
{
if (id == Guid.Empty)
{
return RedirectToPage("Index");
}
DeleteViewModel =
await storesApplication.GetAsync(id);
if (DeleteViewModel == null)
{
return RedirectToPage("Index");
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
await storesApplication.DeleteAsync(DeleteViewModel.Id);
return RedirectToPage("Index");
}
}
@@ -0,0 +1,38 @@
@page
@model Server.Pages.Panel.Stores.IndexModel
@{
}
<div class="my-2 float-end">
<a class="btn btn-primary" asp-page="Create">@(Resources.ButtonCaptions.Create)</a>
</div>
<table class="table table-hover">
<thead>
<tr>
@(Html.Ub_DisplayStringWithTh(Resources.DataDictionary.Name))
@(Html.Ub_DisplayStringWithTh(Resources.DataDictionary.Address))
@(Html.Ub_DisplayStringWithTh(Resources.DataDictionary.Mobile))
@(Html.Ub_DisplayStringWithTh(Resources.DataDictionary.Score))
@(Html.Ub_DisplayStringWithTh(Resources.DataDictionary.IsActive))
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.store)
{
<tr>
@(Html.Ub_DisplayStringWithTd(item.Name))
@(Html.Ub_DisplayStringWithTd(item.Address))
@(Html.Ub_DisplayStringWithTd(item.Mobile))
@(Html.Ub_DisplayInteger(item.Score))
@(Html.Ub_DisplayBooleanWithTd(item.IsActive))
<td>
<div class="btn-group" role="group" aria-label="Basic example">
<a asp-page="Update" asp-route-Id="@(item.Id)" class="btn btn-warning">@(Resources.ButtonCaptions.Edit)</a>
<a asp-page="Delete" asp-route-Id="@(item.Id)" class="btn btn-danger">@(Resources.ButtonCaptions.Delete)</a>
</div>
</td>
</tr>
}
</tbody>
</table>
@@ -0,0 +1,16 @@
using Application.Aggregates.Stores;
using Application.Aggregates.Stores.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Server.Pages.Panel.Stores;
public class IndexModel(StoresApplication storesApplication) : PageModel
{
public List<StoreViewModel> store { get; set; } = new();
public async Task OnGetAsync()
{
store = await storesApplication.GetStors();
}
}
@@ -0,0 +1,43 @@
@page
@model Server.Pages.Panel.Stores.UpdateModel
@{
var pageTitle =
$"{Resources.DataDictionary.UpdateOf} {Resources.DataDictionary.Store}";
ViewData[Constants.ViewDataKeyName.PageTitle] = pageTitle;
}
<form method="post">
<section-form>
<fieldset>
<section-form-header>
@(pageTitle)
</section-form-header>
<partial name="PartialViews/_DisplayPageMessages" />
<input hidden asp-for="UpdateViewModel.Id" />
<ub-full-input asp-for="UpdateViewModel.Name" />
<ub-full-input asp-for="UpdateViewModel.Address" />
<ub-full-input asp-for="UpdateViewModel.Mobile" />
<ub-full-input asp-for="UpdateViewModel.Score" />
<ub-full-checkbox asp-for="UpdateViewModel.IsActive" />
</fieldset>
<section-form-buttons>
<button-save />
<button-reset />
</section-form-buttons>
</section-form>
</form>
@@ -0,0 +1,40 @@
using Application.Aggregates.Stores;
using Application.Aggregates.Stores.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Server.Pages.Panel.Stores;
public class UpdateModel(StoresApplication storesApplication) : PageModel
{
[BindProperty]
public StoreViewModel UpdateViewModel { get; set; }
public async Task<IActionResult> OnGetAsync(Guid id)
{
if(id==Guid.Empty)
{
return RedirectToPage("Index");
}
UpdateViewModel=
await storesApplication.GetAsync(id);
if(UpdateViewModel==null)
{
return RedirectToPage("Index");
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
if(ModelState.IsValid)
{
await storesApplication.UpdateAsync(UpdateViewModel);
}
return RedirectToPage("Index");
}
}
+6
View File
@@ -1,7 +1,10 @@
using Application.Aggregates.Stores;
using Application.Aggregates.Users;
using Domain.Aggregates.Stores.Data;
using Domain.Aggregates.Users.Data;
using Microsoft.EntityFrameworkCore;
using Persistence;
using Persistence.Repositories.Aggregates.Stores;
using Persistence.Repositories.Aggregates.Users;
using Server.Infrastructure.Extensions.ServiceCollections;
@@ -28,6 +31,9 @@ public class Program
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<UsersApplication>();
builder.Services.AddScoped<IStoreRepository, StoreRepository>();
builder.Services.AddScoped<StoresApplication>();
var app = builder.Build();
if (!app.Environment.IsDevelopment())