From 2919c3a7b2ccedd670c09e19e2a418e7f18b6e56 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Sun, 21 Jul 2024 12:28:23 +0500 Subject: [PATCH 01/10] replace all url addresses to configuration file --- WMS.WebUI/WMS.WebUI/Stores/CategoryStore.cs | 4 ++-- WMS.WebUI/WMS.WebUI/Stores/DashboardStore.cs | 4 ++-- WMS.WebUI/WMS.WebUI/Stores/ProductStore.cs | 4 ++-- WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs | 4 ++-- WMS.WebUI/WMS.WebUI/appsettings.json | 3 ++- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/WMS.WebUI/WMS.WebUI/Stores/CategoryStore.cs b/WMS.WebUI/WMS.WebUI/Stores/CategoryStore.cs index 36b3424..e1d6de8 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/CategoryStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/CategoryStore.cs @@ -10,10 +10,10 @@ public class CategoryStore : ICategoryStore { private readonly HttpClient _client; - public CategoryStore() + public CategoryStore(IConfiguration configuration) { _client = new HttpClient(); - _client.BaseAddress = new Uri("https://localhost:7097/api/"); + _client.BaseAddress = new Uri(configuration["WMSApiUrl"]); } public async Task CreateCategoryAsync(CategoryViewModel category) diff --git a/WMS.WebUI/WMS.WebUI/Stores/DashboardStore.cs b/WMS.WebUI/WMS.WebUI/Stores/DashboardStore.cs index 9a4a232..6165d15 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/DashboardStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/DashboardStore.cs @@ -8,10 +8,10 @@ public class DashboardStore : IDashboardStore { private readonly HttpClient _client; - public DashboardStore() + public DashboardStore(IConfiguration configuration) { _client = new HttpClient(); - _client.BaseAddress = new Uri("https://localhost:7097/api/"); + _client.BaseAddress = new Uri(configuration["WMSApiUrl"]); } public async Task Get() diff --git a/WMS.WebUI/WMS.WebUI/Stores/ProductStore.cs b/WMS.WebUI/WMS.WebUI/Stores/ProductStore.cs index 6c04e6b..99f0f7b 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/ProductStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/ProductStore.cs @@ -10,10 +10,10 @@ public class ProductStore : IProductsStore { private readonly HttpClient _httpClient; - public ProductStore() + public ProductStore(IConfiguration configuration) { _httpClient = new HttpClient(); - _httpClient.BaseAddress = new Uri("https://localhost:7097/api/"); + _httpClient.BaseAddress = new Uri(configuration["WMSApiUrl"]); } public async Task> GetProductsAsync(string? search = null, int? categoryId = null) diff --git a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs index 5e5d73a..8eb8ead 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs @@ -12,10 +12,10 @@ public class TransactionsStore : ITransactionsStore { private readonly HttpClient _client; - public TransactionsStore() + public TransactionsStore(IConfiguration configuration) { _client = new HttpClient(); - _client.BaseAddress = new Uri("https://localhost:7097/api/"); + _client.BaseAddress = new Uri(configuration["WMSApiUrl"]); } public async Task> GetTransactionsAsync(string? search, string? type) diff --git a/WMS.WebUI/WMS.WebUI/appsettings.json b/WMS.WebUI/WMS.WebUI/appsettings.json index 10f68b8..0c3d4b1 100644 --- a/WMS.WebUI/WMS.WebUI/appsettings.json +++ b/WMS.WebUI/WMS.WebUI/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "WMSApiUrl": "https://localhost:7108/api/" } From 949a614c671d73eaad1782288b868b000099a778 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:55:19 +0500 Subject: [PATCH 02/10] Create Partners controller and Index view --- .../Controllers/PartnersController.cs | 72 +++++++++++++++ .../Controllers/TransactionsController.cs | 8 +- .../WMS.WebUI/Mappings/CustomerMappings.cs | 19 ++++ .../{SalesMappings.cs => SaleMappings.cs} | 2 +- .../WMS.WebUI/Mappings/SupplierMappings.cs | 18 ++++ WMS.WebUI/WMS.WebUI/Program.cs | 1 + .../Stores/Interfaces/IPartnerStore.cs | 11 +++ .../Stores/Interfaces/ITransactionsStore.cs | 2 +- WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs | 90 +++++++++++++++++++ .../WMS.WebUI/Stores/TransactionsStore.cs | 15 +--- .../CreatePartnerViewModel.cs | 10 +++ .../PartnerViewModels/CustomerViewModel.cs | 11 +++ .../PartnerViewModel.cs | 5 +- .../PartnerViewModels/SupplierViewModel.cs | 9 ++ .../WMS.WebUI/Views/Partners/Create.cshtml | 19 ++++ .../WMS.WebUI/Views/Partners/Index.cshtml | 66 ++++++++++++++ WMS.WebUI/WMS.WebUI/appsettings.json | 2 +- 17 files changed, 339 insertions(+), 21 deletions(-) create mode 100644 WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs create mode 100644 WMS.WebUI/WMS.WebUI/Mappings/CustomerMappings.cs rename WMS.WebUI/WMS.WebUI/Mappings/{SalesMappings.cs => SaleMappings.cs} (92%) create mode 100644 WMS.WebUI/WMS.WebUI/Mappings/SupplierMappings.cs create mode 100644 WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs create mode 100644 WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs create mode 100644 WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CreatePartnerViewModel.cs create mode 100644 WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CustomerViewModel.cs rename WMS.WebUI/WMS.WebUI/ViewModels/{ => PartnerViewModels}/PartnerViewModel.cs (59%) create mode 100644 WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/SupplierViewModel.cs create mode 100644 WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml create mode 100644 WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml diff --git a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs new file mode 100644 index 0000000..45f42dc --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs @@ -0,0 +1,72 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using WMS.WebUI.Helpers; +using WMS.WebUI.Stores.Interfaces; +using WMS.WebUI.ViewModels; +using WMS.WebUI.ViewModels.PartnerViewModels; + +namespace WMS.WebUI.Controllers; + +public class PartnersController : Controller +{ + private readonly IPartnerStore _partnerStore; + + public PartnersController(IPartnerStore partnersStore, + IProductsStore productsStore, + IPartnerStore partnerStore) + { + _partnerStore=partnerStore; + } + + public async Task Index(string? searchString = null, string? partnerType = null) + { + var partners = await _partnerStore.GetPartnersAsync(searchString, partnerType); + + ViewBag.SelectedType = partnerType ?? "All"; + + return View(partners); + } + + public async Task Create() + { + var partnersTask = await _partnerStore.GetPartnersAsync(); + + + ViewBag.Types = new string[] { "Customer", "Supplier" }; + ViewBag.SelectedType = "Customer"; + ViewBag.Partners = partnersTask; + + return View(); + } + + [HttpPost] + public async Task Create( + [FromBody] CreatePartnerViewModel data) + { + if (!ModelState.IsValid) + { + return BadRequest(); + } + + var createdPartner = await _partnerStore.Create(data); + var result = new + { + redirectToUrl = Url.Action( + "Details", + new + { + id = createdPartner.Id, + type = (int)createdPartner.Type + }) + }; + + return Json(result); + } + + public async Task Details(int id, PartnerType type) + { + var partner = await _partnerStore.GetByIdAndTypeAsync(id, type); + + return View(partner); + } +} diff --git a/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs b/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs index 861be7c..e5826ee 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs @@ -9,11 +9,15 @@ public class TransactionsController : Controller { private readonly ITransactionsStore _transactionsStore; private readonly IProductsStore _productsStore; + private readonly IPartnerStore _partnerStore; - public TransactionsController(ITransactionsStore transactionsStore, IProductsStore productsStore) + public TransactionsController(ITransactionsStore transactionsStore, + IProductsStore productsStore, + IPartnerStore partnerStore) { _transactionsStore = Validator.NotNull(transactionsStore); _productsStore = Validator.NotNull(productsStore); + _partnerStore=partnerStore; } public async Task Index(string? searchString = null, string? transactionType = null) @@ -27,7 +31,7 @@ public async Task Index(string? searchString = null, string? tran public async Task Create() { - var partnersTask = _transactionsStore.GetPartnersAsync(); + var partnersTask = _partnerStore.GetPartnersAsync(); var productsTask = _productsStore.GetProductsAsync(); await Task.WhenAll(partnersTask, productsTask); diff --git a/WMS.WebUI/WMS.WebUI/Mappings/CustomerMappings.cs b/WMS.WebUI/WMS.WebUI/Mappings/CustomerMappings.cs new file mode 100644 index 0000000..adbe748 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Mappings/CustomerMappings.cs @@ -0,0 +1,19 @@ +using WMS.WebUI.ViewModels.PartnerViewModels; + +namespace WMS.WebUI.Mappings; + +public static class CustomerMappings +{ + public static PartnerViewModel ToPartner(this CustomerViewModel viewModel) + { + return new PartnerViewModel() + { + Id = viewModel.Id, + FullName = viewModel.FullName, + PhoneNumber = viewModel.PhoneNumber, + Balance = viewModel.Balance, + Type = PartnerType.Customer, + }; + } +} + diff --git a/WMS.WebUI/WMS.WebUI/Mappings/SalesMappings.cs b/WMS.WebUI/WMS.WebUI/Mappings/SaleMappings.cs similarity index 92% rename from WMS.WebUI/WMS.WebUI/Mappings/SalesMappings.cs rename to WMS.WebUI/WMS.WebUI/Mappings/SaleMappings.cs index 2fa5f54..011fd2c 100644 --- a/WMS.WebUI/WMS.WebUI/Mappings/SalesMappings.cs +++ b/WMS.WebUI/WMS.WebUI/Mappings/SaleMappings.cs @@ -2,7 +2,7 @@ namespace WMS.WebUI.Mappings; -public static class SalesMappings +public static class SaleMappings { public static TransactionView ToTransaction(this SaleViewModel sale) { diff --git a/WMS.WebUI/WMS.WebUI/Mappings/SupplierMappings.cs b/WMS.WebUI/WMS.WebUI/Mappings/SupplierMappings.cs new file mode 100644 index 0000000..021a03b --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Mappings/SupplierMappings.cs @@ -0,0 +1,18 @@ +using WMS.WebUI.ViewModels.PartnerViewModels; + +namespace WMS.WebUI.Mappings; + +public static class SupplierMappings +{ + public static PartnerViewModel ToPartner(this SupplierViewModel viewModel) + { + return new PartnerViewModel() + { + Id = viewModel.Id, + FullName = viewModel.FullName, + PhoneNumber = viewModel.PhoneNumber, + Balance = viewModel.Balance, + Type = PartnerType.Supplier, + }; + } +} diff --git a/WMS.WebUI/WMS.WebUI/Program.cs b/WMS.WebUI/WMS.WebUI/Program.cs index f3530fe..e9276fb 100644 --- a/WMS.WebUI/WMS.WebUI/Program.cs +++ b/WMS.WebUI/WMS.WebUI/Program.cs @@ -11,6 +11,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSyncfusion(builder.Configuration); diff --git a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs new file mode 100644 index 0000000..1550e92 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs @@ -0,0 +1,11 @@ +using WMS.WebUI.ViewModels; +using WMS.WebUI.ViewModels.PartnerViewModels; + +namespace WMS.WebUI.Stores.Interfaces; + +public interface IPartnerStore +{ + Task> GetPartnersAsync(string? search="", string? type = ""); + Task GetByIdAndTypeAsync(int id, PartnerType type); + Task Create(CreatePartnerViewModel partner); +} diff --git a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs index df55aa6..c97000e 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs @@ -1,11 +1,11 @@ using WMS.WebUI.ViewModels; +using WMS.WebUI.ViewModels.PartnerViewModels; namespace WMS.WebUI.Stores.Interfaces; public interface ITransactionsStore { Task> GetTransactionsAsync(string? search, string? type); - Task> GetPartnersAsync(); Task GetByIdAndTypeAsync(int id, TransactionType type); Task Create(CreateTransactionViewModel transaction); } diff --git a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs new file mode 100644 index 0000000..aa334ae --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs @@ -0,0 +1,90 @@ +using Newtonsoft.Json; +using WMS.WebUI.Stores.Interfaces; +using WMS.WebUI.ViewModels; +using WMS.WebUI.ViewModels.PartnerViewModels; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace WMS.WebUI.Stores; + +public class PartnerStore : IPartnerStore +{ + private readonly HttpClient _client; + public PartnerStore(IConfiguration configuration) + { + _client = new HttpClient(); + _client.BaseAddress = new Uri(configuration["WMSApiUrl"]); + } + public async Task> GetPartnersAsync(string? search,string? type) + { + var customersTask = _client.GetFromJsonAsync>($"customers?search={search}"); + var suppliersTask = _client.GetFromJsonAsync>($"suppliers?search={search}"); + + await Task.WhenAll(customersTask, suppliersTask); + + customersTask.Result!.ForEach(el => el.Type = PartnerType.Customer); + suppliersTask.Result!.ForEach(el => el.Type = PartnerType.Supplier); + + return [.. customersTask.Result, .. suppliersTask.Result]; + } + public async Task Create(CreatePartnerViewModel partner) + { + + HttpResponseMessage result; + var endpoint = partner.Type == PartnerType.Customer + ? "customers" + : "suppliers"; + var data = new + { + FirstName = partner.FirstName, + LastName = partner.LastName, + Balance = partner.Balance, + PhoneNumber = partner.PhoneNumber, + }; + + result = await _client.PostAsJsonAsync(endpoint, data); + result.EnsureSuccessStatusCode(); + + var json = await result.Content.ReadAsStringAsync(); + var createdPartner = JsonConvert.DeserializeObject(json); + + if (createdPartner is null) + { + throw new InvalidCastException(); + } + + createdPartner.Type = partner.Type; + return createdPartner; + } + + public async Task GetByIdAndTypeAsync(int id, PartnerType type) + { + PartnerViewModel partner; + + if (type == PartnerType.Customer) + { + var customer = await _client.GetFromJsonAsync($"customers/{id}"); + partner = new PartnerViewModel + { + Id = id, + FullName = customer.FullName, + Balance = customer.Balance, + PhoneNumber = customer.PhoneNumber, + Type = PartnerType.Customer, + }; + } + else + { + var supplier = await _client.GetFromJsonAsync($"suppliers/{id}"); + partner = new PartnerViewModel + { + Id = id, + FullName = supplier.FullName, + Balance = supplier.Balance, + PhoneNumber = supplier.PhoneNumber, + Type = PartnerType.Supplier, + }; + } + + return partner; + } +} diff --git a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs index 8eb8ead..08150a0 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs @@ -5,6 +5,7 @@ using WMS.WebUI.Mappings; using WMS.WebUI.Stores.Interfaces; using WMS.WebUI.ViewModels; +using WMS.WebUI.ViewModels.PartnerViewModels; namespace WMS.WebUI.Stores; @@ -34,20 +35,6 @@ public async Task> GetTransactionsAsync(string? search, st return transactions; } - - public async Task> GetPartnersAsync() - { - var customersTask = _client.GetFromJsonAsync>("customers"); - var suppliersTask = _client.GetFromJsonAsync>("suppliers"); - - await Task.WhenAll(customersTask, suppliersTask); - - customersTask.Result!.ForEach(el => el.Type = PartnerType.Customer); - suppliersTask.Result!.ForEach(el => el.Type = PartnerType.Supplier); - - return [.. customersTask.Result, .. suppliersTask.Result]; - } - public async Task GetByIdAndTypeAsync(int id, TransactionType type) { TransactionView transaction; diff --git a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CreatePartnerViewModel.cs b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CreatePartnerViewModel.cs new file mode 100644 index 0000000..a5a53ea --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CreatePartnerViewModel.cs @@ -0,0 +1,10 @@ +namespace WMS.WebUI.ViewModels.PartnerViewModels; + +public class CreatePartnerViewModel +{ + public string FirstName { get; set; } + public string LastName { get; set; } + public string PhoneNumber { get; set; } + public decimal Balance { get; set; } + public PartnerType Type { get; set; } +} diff --git a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CustomerViewModel.cs b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CustomerViewModel.cs new file mode 100644 index 0000000..99c5cfc --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/CustomerViewModel.cs @@ -0,0 +1,11 @@ +namespace WMS.WebUI.ViewModels.PartnerViewModels; + +public class CustomerViewModel +{ + public int Id { get; set; } + public string FullName { get; init; } + public string PhoneNumber { get; init; } + public string? Address { get; init; } + public decimal Balance { get; init; } + public decimal Discount { get; init; } +} diff --git a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModel.cs b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs similarity index 59% rename from WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModel.cs rename to WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs index 8503c58..6f0abdc 100644 --- a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModel.cs +++ b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs @@ -1,11 +1,12 @@ -namespace WMS.WebUI.ViewModels; +namespace WMS.WebUI.ViewModels.PartnerViewModels; public class PartnerViewModel { public int Id { get; set; } public string FullName { get; set; } + public string? PhoneNumber { get; set; } + public decimal Balance { get; set; } public PartnerType Type { get; set; } - public string PhoneNumber { get; set; } } public enum PartnerType diff --git a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/SupplierViewModel.cs b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/SupplierViewModel.cs new file mode 100644 index 0000000..f648a6b --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/SupplierViewModel.cs @@ -0,0 +1,9 @@ +namespace WMS.WebUI.ViewModels.PartnerViewModels; + +public class SupplierViewModel +{ + public int Id { get; init; } + public string FullName { get; set; } + public string PhoneNumber { get; set; } + public decimal Balance { get; set; } +} diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml new file mode 100644 index 0000000..1c25eae --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml @@ -0,0 +1,19 @@ +@model WMS.WebUI.ViewModels.PartnerViewModels.PartnerViewModel; + +
+
+

Create Partner

+ +
+ +
+
+ +
+
+ +
+ + +
+
\ No newline at end of file diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml new file mode 100644 index 0000000..c62f1e7 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml @@ -0,0 +1,66 @@ +@using WMS.WebUI.ViewModels.PartnerViewModels; +@model IEnumerable; + +@{ + var partnerTypes = new string[] { "All", "Customers", "Suppliers" }; +} + +
+ +
+
+
+ + +
+ +
+
+ + +
+
+ + +
+
+
+ +
+
+ + + + + + + + + +
+
+ + diff --git a/WMS.WebUI/WMS.WebUI/appsettings.json b/WMS.WebUI/WMS.WebUI/appsettings.json index 0c3d4b1..07cfc0c 100644 --- a/WMS.WebUI/WMS.WebUI/appsettings.json +++ b/WMS.WebUI/WMS.WebUI/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "WMSApiUrl": "https://localhost:7108/api/" + "WMSApiUrl": "https://localhost:7097/api/" } From 458bfab69d16ba493190a599ddc0dcba7a401412 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:18:35 +0500 Subject: [PATCH 03/10] 1 --- WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs | 2 +- WMS.WebUI/WMS.WebUI/appsettings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs index aa334ae..55a1207 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs @@ -18,7 +18,7 @@ public async Task> GetPartnersAsync(string? search,string { var customersTask = _client.GetFromJsonAsync>($"customers?search={search}"); var suppliersTask = _client.GetFromJsonAsync>($"suppliers?search={search}"); - + await Task.WhenAll(customersTask, suppliersTask); customersTask.Result!.ForEach(el => el.Type = PartnerType.Customer); diff --git a/WMS.WebUI/WMS.WebUI/appsettings.json b/WMS.WebUI/WMS.WebUI/appsettings.json index 07cfc0c..18439f5 100644 --- a/WMS.WebUI/WMS.WebUI/appsettings.json +++ b/WMS.WebUI/WMS.WebUI/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "WMSApiUrl": "https://localhost:7097/api/" + "WMSApiUrl": "https://w2sc5qx5-7097.inc1.devtunnels.ms/api/" } From cd3bb5216eb0b35627cf141566ce98e0aba3447e Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:07:41 +0500 Subject: [PATCH 04/10] Ishladi --- .../Controllers/PartnersController.cs | 14 ++--- .../WMS.WebUI/Views/Partners/Create.cshtml | 62 ++++++++++++++++--- WMS.WebUI/WMS.WebUI/appsettings.json | 2 +- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs index 45f42dc..7c8411c 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs @@ -29,19 +29,14 @@ public async Task Index(string? searchString = null, string? part public async Task Create() { - var partnersTask = await _partnerStore.GetPartnersAsync(); - - ViewBag.Types = new string[] { "Customer", "Supplier" }; ViewBag.SelectedType = "Customer"; - ViewBag.Partners = partnersTask; return View(); } [HttpPost] - public async Task Create( - [FromBody] CreatePartnerViewModel data) + public async Task Create([FromBody] CreatePartnerViewModel data) { if (!ModelState.IsValid) { @@ -52,7 +47,7 @@ public async Task Create( var result = new { redirectToUrl = Url.Action( - "Details", + "Details", "Partners", new { id = createdPartner.Id, @@ -63,9 +58,10 @@ public async Task Create( return Json(result); } - public async Task Details(int id, PartnerType type) + + public async Task Details(int id, int type) { - var partner = await _partnerStore.GetByIdAndTypeAsync(id, type); + var partner = await _partnerStore.GetByIdAndTypeAsync(id, (PartnerType)type); return View(partner); } diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml index 1c25eae..a0f2870 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Create.cshtml @@ -1,19 +1,65 @@ -@model WMS.WebUI.ViewModels.PartnerViewModels.PartnerViewModel; +@model WMS.WebUI.ViewModels.PartnerViewModels.CreatePartnerViewModel;
-
+

Create Partner

-
- + +
- + +
-
- +
+ +
-
\ No newline at end of file +
+ + diff --git a/WMS.WebUI/WMS.WebUI/appsettings.json b/WMS.WebUI/WMS.WebUI/appsettings.json index 18439f5..07cfc0c 100644 --- a/WMS.WebUI/WMS.WebUI/appsettings.json +++ b/WMS.WebUI/WMS.WebUI/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "WMSApiUrl": "https://w2sc5qx5-7097.inc1.devtunnels.ms/api/" + "WMSApiUrl": "https://localhost:7097/api/" } From 90cd73a01334e8ab6337e5e169c1ecfe943a51f0 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:40:42 +0500 Subject: [PATCH 05/10] Add Details Page for Partners . --- .../WMS.WebUI/Views/Partners/Details.cshtml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml new file mode 100644 index 0000000..3e1dd05 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml @@ -0,0 +1,51 @@ +@model WMS.WebUI.ViewModels.PartnerViewModels.PartnerViewModel; + +
+

Partner details

+
+ +
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+ @Html.DisplayNameFor(model => model.FullName) +
+
+ @Html.DisplayFor(model => model.FullName) +
+
+ @Html.DisplayNameFor(model => model.PhoneNumber) +
+
+ @Html.DisplayFor(model => model.PhoneNumber) +
+
+ @Html.DisplayNameFor(model => model.Balance) +
+
+ @Html.DisplayFor(model => model.Balance) +
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+
+ + From e21988870e6c40819337b30c16d962b2d18ce54c Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:08:13 +0500 Subject: [PATCH 06/10] create Update VIew with issue --- .../Controllers/PartnersController.cs | 47 +++++++++++ .../Stores/Interfaces/IPartnerStore.cs | 2 + WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs | 84 ++++++++++++------- .../PartnerViewModels/EditPartnerViewModel.cs | 11 +++ .../WMS.WebUI/Views/Partners/Edit.cshtml | 30 +++++++ 5 files changed, 146 insertions(+), 28 deletions(-) create mode 100644 WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/EditPartnerViewModel.cs create mode 100644 WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml diff --git a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs index 7c8411c..6667e21 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs @@ -1,6 +1,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Data; +using System.Reflection.Metadata.Ecma335; using WMS.WebUI.Helpers; +using WMS.WebUI.Stores; using WMS.WebUI.Stores.Interfaces; using WMS.WebUI.ViewModels; using WMS.WebUI.ViewModels.PartnerViewModels; @@ -65,4 +68,48 @@ public async Task Details(int id, int type) return View(partner); } + public async Task Edit(int id, int type) + { + var partner = await _partnerStore.GetByIdAndTypeAsync(id, (PartnerType)type); + + return View(partner); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("id, Name, Description")] EditPartnerViewModel partner) + { + try + { + await _partnerStore.UpdateAsync(partner); + + return RedirectToAction(nameof(Details), new { id }); + } + catch + { + return View(partner); + } + } + public async Task Delete(int id, int type) + { + var partner = await _partnerStore.GetByIdAndTypeAsync(id, (PartnerType)type); + + return View(partner); + } + + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task ConfirmDelete(int id, int type) + { + try + { + await _partnerStore.Delete(id, (PartnerType)type); + + return RedirectToAction(nameof(Index)); + } + catch + { + return View(); + } + } } diff --git a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs index 1550e92..61e2c42 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs @@ -8,4 +8,6 @@ public interface IPartnerStore Task> GetPartnersAsync(string? search="", string? type = ""); Task GetByIdAndTypeAsync(int id, PartnerType type); Task Create(CreatePartnerViewModel partner); + Task UpdateAsync(EditPartnerViewModel partner); + Task Delete(int id, PartnerType type); } diff --git a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs index 55a1207..3a4cbc7 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs @@ -26,9 +26,39 @@ public async Task> GetPartnersAsync(string? search,string return [.. customersTask.Result, .. suppliersTask.Result]; } - public async Task Create(CreatePartnerViewModel partner) + public async Task GetByIdAndTypeAsync(int id, PartnerType type) { + PartnerViewModel partner; + if (type == PartnerType.Customer) + { + var customer = await _client.GetFromJsonAsync($"customers/{id}"); + partner = new PartnerViewModel + { + Id = id, + FullName = customer.FullName, + Balance = customer.Balance, + PhoneNumber = customer.PhoneNumber, + Type = PartnerType.Customer, + }; + } + else + { + var supplier = await _client.GetFromJsonAsync($"suppliers/{id}"); + partner = new PartnerViewModel + { + Id = id, + FullName = supplier.FullName, + Balance = supplier.Balance, + PhoneNumber = supplier.PhoneNumber, + Type = PartnerType.Supplier, + }; + } + + return partner; + } + public async Task Create(CreatePartnerViewModel partner) + { HttpResponseMessage result; var endpoint = partner.Type == PartnerType.Customer ? "customers" @@ -55,36 +85,34 @@ public async Task Create(CreatePartnerViewModel partner) createdPartner.Type = partner.Type; return createdPartner; } - - public async Task GetByIdAndTypeAsync(int id, PartnerType type) + public async Task UpdateAsync(EditPartnerViewModel partner) { - PartnerViewModel partner; + HttpResponseMessage result; + var endpoint = partner.Type == PartnerType.Customer + ? "customers" + : "suppliers"; - if (type == PartnerType.Customer) - { - var customer = await _client.GetFromJsonAsync($"customers/{id}"); - partner = new PartnerViewModel - { - Id = id, - FullName = customer.FullName, - Balance = customer.Balance, - PhoneNumber = customer.PhoneNumber, - Type = PartnerType.Customer, - }; - } - else + var data = new { - var supplier = await _client.GetFromJsonAsync($"suppliers/{id}"); - partner = new PartnerViewModel - { - Id = id, - FullName = supplier.FullName, - Balance = supplier.Balance, - PhoneNumber = supplier.PhoneNumber, - Type = PartnerType.Supplier, - }; - } + Id = partner.Id, + FirstName = partner.FirstName, + LastName = partner.LastName, + Balance = partner.Balance, + PhoneNumber = partner.PhoneNumber, + }; - return partner; + result = await _client.PostAsJsonAsync(endpoint + $"/{partner.Id}", data); + result.EnsureSuccessStatusCode(); + } + + public async Task Delete(int id, PartnerType type) + { + HttpResponseMessage result; + var endpoint = type == PartnerType.Customer + ? "customers" + : "suppliers"; + + result = await _client.DeleteAsync(endpoint + $"/{id}"); + result.EnsureSuccessStatusCode(); } } diff --git a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/EditPartnerViewModel.cs b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/EditPartnerViewModel.cs new file mode 100644 index 0000000..1b549cd --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/EditPartnerViewModel.cs @@ -0,0 +1,11 @@ +namespace WMS.WebUI.ViewModels.PartnerViewModels; + +public class EditPartnerViewModel +{ + public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string PhoneNumber { get; set; } + public decimal Balance { get; set; } + public PartnerType Type { get; set; } +} diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml new file mode 100644 index 0000000..0ce08b2 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml @@ -0,0 +1,30 @@ +@model WMS.WebUI.ViewModels.PartnerViewModels.EditPartnerViewModel + +
+
+

Edit Partner

+ +
+ + +
+ +
+ + +
+ +
+ + + +
+ + +
+
From 90ae589b95ef7dcf230e5791caa7aa761ca0eda0 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:27:09 +0500 Subject: [PATCH 07/10] Added Delete View for Partners --- .../Controllers/PartnersController.cs | 24 +++++- WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs | 2 +- .../WMS.WebUI/Views/Partners/Delete.cshtml | 50 +++++++++++++ .../WMS.WebUI/Views/Products/Delete.cshtml | 73 +++++++++++++++++-- .../WMS.WebUI/Views/Shared/_Sidebar.cshtml | 2 +- 5 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 WMS.WebUI/WMS.WebUI/Views/Partners/Delete.cshtml diff --git a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs index 6667e21..2b9ae0b 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs @@ -72,12 +72,14 @@ public async Task Edit(int id, int type) { var partner = await _partnerStore.GetByIdAndTypeAsync(id, (PartnerType)type); - return View(partner); + var editPartner = ParseEditPartner(partner); + + return View(editPartner); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("id, Name, Description")] EditPartnerViewModel partner) + public async Task Edit(int id, EditPartnerViewModel partner) { try { @@ -112,4 +114,22 @@ public async Task ConfirmDelete(int id, int type) return View(); } } + private EditPartnerViewModel ParseEditPartner(PartnerViewModel partner) + { + string[] nameParts = partner.FullName.Split(new char[] { ' ' }, 2); + + string firstName = nameParts[0]; // First part is the first name + + // If there's more than one part, the rest is considered the last name + string lastName = (nameParts.Length > 1) ? nameParts[1] : ""; + + return new EditPartnerViewModel() + { + Id = partner.Id, + FirstName = firstName, + LastName = lastName, + Balance = partner.Balance, + PhoneNumber = partner.PhoneNumber ?? "", + }; + } } diff --git a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs index 3a4cbc7..8742867 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs @@ -101,7 +101,7 @@ public async Task UpdateAsync(EditPartnerViewModel partner) PhoneNumber = partner.PhoneNumber, }; - result = await _client.PostAsJsonAsync(endpoint + $"/{partner.Id}", data); + result = await _client.PutAsJsonAsync(endpoint + $"/{partner.Id}", data); result.EnsureSuccessStatusCode(); } diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Delete.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Delete.cshtml new file mode 100644 index 0000000..2011cb8 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Delete.cshtml @@ -0,0 +1,50 @@ +@model WMS.WebUI.ViewModels.PartnerViewModels.PartnerViewModel; + +
+

Are you sure

+
+ +
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+ @Html.DisplayNameFor(model => model.FullName) +
+
+ @Html.DisplayFor(model => model.FullName) +
+
+ @Html.DisplayNameFor(model => model.PhoneNumber) +
+
+ @Html.DisplayFor(model => model.PhoneNumber) +
+
+ @Html.DisplayNameFor(model => model.Balance) +
+
+ @Html.DisplayFor(model => model.Balance) +
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+
+ +
+
+ + Back + + +
+
\ No newline at end of file diff --git a/WMS.WebUI/WMS.WebUI/Views/Products/Delete.cshtml b/WMS.WebUI/WMS.WebUI/Views/Products/Delete.cshtml index e1dd794..0995516 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Products/Delete.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Products/Delete.cshtml @@ -1,5 +1,68 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ -@{ -} +@model WMS.WebUI.ViewModels.ProductViewModel; + +
+

Are you sure Delete

+
+ +
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.Description) +
+
+ @Html.DisplayFor(model => model.Description) +
+
+ @Html.DisplayNameFor(model => model.Category) +
+
+ @Html.DisplayFor(model => model.Category) +
+
+ @Html.DisplayNameFor(model => model.SupplyPrice) +
+
+ @Html.DisplayFor(model => model.SupplyPrice) +
+
+ @Html.DisplayNameFor(model => model.SalePrice) +
+
+ @Html.DisplayFor(model => model.SalePrice) +
+
+ @Html.DisplayNameFor(model => model.QuantityInStock) +
+
+ @Html.DisplayFor(model => model.QuantityInStock) +
+
+ @Html.DisplayNameFor(model => model.LowQuantityAmount) +
+
+ @Html.DisplayFor(model => model.LowQuantityAmount) +
+
+
+ +
+
+ + Back + + +
+
diff --git a/WMS.WebUI/WMS.WebUI/Views/Shared/_Sidebar.cshtml b/WMS.WebUI/WMS.WebUI/Views/Shared/_Sidebar.cshtml index b0c6fc0..513c710 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Shared/_Sidebar.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Shared/_Sidebar.cshtml @@ -51,7 +51,7 @@ menuItems.Add(new { text = "Partners", - url = "#", + url = "/partners", iconCss = "fa-solid fa-users" }); From 6b85d779d442b7f6f19065e9916a22a0017700f7 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Tue, 23 Jul 2024 13:51:31 +0500 Subject: [PATCH 08/10] Add Delete Transactions --- .../Controllers/PartnersController.cs | 4 +- .../Controllers/TransactionsController.cs | 58 ++++++++++++++++- .../Stores/Interfaces/IPartnerStore.cs | 4 +- .../Stores/Interfaces/ITransactionsStore.cs | 4 +- WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs | 4 +- .../WMS.WebUI/Stores/TransactionsStore.cs | 43 +++++++++++- .../Views/Transactions/Delete.cshtml | 65 +++++++++++++++++++ .../Views/Transactions/Details.cshtml | 2 +- 8 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 WMS.WebUI/WMS.WebUI/Views/Transactions/Delete.cshtml diff --git a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs index 2b9ae0b..201e01e 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/PartnersController.cs @@ -46,7 +46,7 @@ public async Task Create([FromBody] CreatePartnerViewModel data) return BadRequest(); } - var createdPartner = await _partnerStore.Create(data); + var createdPartner = await _partnerStore.CreateAsync(data); var result = new { redirectToUrl = Url.Action( @@ -105,7 +105,7 @@ public async Task ConfirmDelete(int id, int type) { try { - await _partnerStore.Delete(id, (PartnerType)type); + await _partnerStore.DeleteAsync(id, (PartnerType)type); return RedirectToAction(nameof(Index)); } diff --git a/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs b/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs index e5826ee..21ff973 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs @@ -28,6 +28,12 @@ public async Task Index(string? searchString = null, string? tran return View(transactions); } + public async Task Details(int id, TransactionType type) + { + var transaction = await _transactionsStore.GetByIdAndTypeAsync(id, type); + + return View(transaction); + } public async Task Create() { @@ -53,7 +59,7 @@ public async Task Create( return BadRequest(); } - var createdTransaction = await _transactionsStore.Create(data); + var createdTransaction = await _transactionsStore.CreateAsync(data); var result = new { redirectToUrl = Url.Action( @@ -67,11 +73,59 @@ public async Task Create( return Json(result); } + public async Task Edit(int id,TransactionType type) + { + var partnersTask = _partnerStore.GetPartnersAsync(); + var productsTask = _productsStore.GetProductsAsync(); + var transaction = _transactionsStore.GetByIdAndTypeAsync(id, type); - public async Task Details(int id, TransactionType type) + await Task.WhenAll(partnersTask, productsTask,transaction); + + ViewBag.Types = new string[] { "Sale", "Supply" }; + ViewBag.SelectedType = "Sale"; + ViewBag.Partners = partnersTask.Result; + ViewBag.Products= productsTask.Result.Data; + + return View(transaction); + } + + [HttpPost] + public async Task Edit( + [FromBody] TransactionView data) + { + if (!ModelState.IsValid) + { + return View(data); + } + await _transactionsStore.UpdateAsync(data); + + var result = new + { + redirectToUrl = Url.Action( + "Details", + new + { + id = data.Id, + type = (int)data.Type + }) + }; + + return Json(result); + } + public async Task Delete(int id, TransactionType type) { var transaction = await _transactionsStore.GetByIdAndTypeAsync(id, type); return View(transaction); } + [ValidateAntiForgeryToken] + [HttpPost] + [ActionName("Delete")] + public async Task ConfirmDelete(int id, TransactionType type) + { + await _transactionsStore.DeleteAsync(id, type); + + return RedirectToAction(nameof(Index)); + } + } diff --git a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs index 61e2c42..a97157b 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/IPartnerStore.cs @@ -7,7 +7,7 @@ public interface IPartnerStore { Task> GetPartnersAsync(string? search="", string? type = ""); Task GetByIdAndTypeAsync(int id, PartnerType type); - Task Create(CreatePartnerViewModel partner); + Task CreateAsync(CreatePartnerViewModel partner); Task UpdateAsync(EditPartnerViewModel partner); - Task Delete(int id, PartnerType type); + Task DeleteAsync(int id, PartnerType type); } diff --git a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs index c97000e..9bf026f 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/Interfaces/ITransactionsStore.cs @@ -7,5 +7,7 @@ public interface ITransactionsStore { Task> GetTransactionsAsync(string? search, string? type); Task GetByIdAndTypeAsync(int id, TransactionType type); - Task Create(CreateTransactionViewModel transaction); + Task CreateAsync(CreateTransactionViewModel transaction); + Task UpdateAsync(TransactionView transaction); + Task DeleteAsync(int id,TransactionType type); } diff --git a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs index 8742867..83d2c9a 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/PartnerStore.cs @@ -57,7 +57,7 @@ public async Task GetByIdAndTypeAsync(int id, PartnerType type return partner; } - public async Task Create(CreatePartnerViewModel partner) + public async Task CreateAsync(CreatePartnerViewModel partner) { HttpResponseMessage result; var endpoint = partner.Type == PartnerType.Customer @@ -105,7 +105,7 @@ public async Task UpdateAsync(EditPartnerViewModel partner) result.EnsureSuccessStatusCode(); } - public async Task Delete(int id, PartnerType type) + public async Task DeleteAsync(int id, PartnerType type) { HttpResponseMessage result; var endpoint = type == PartnerType.Customer diff --git a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs index 08150a0..e07963f 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs @@ -2,6 +2,7 @@ using Syncfusion.EJ2.Diagrams; using System.Net.Http.Json; using System.Runtime.CompilerServices; +using System.Transactions; using WMS.WebUI.Mappings; using WMS.WebUI.Stores.Interfaces; using WMS.WebUI.ViewModels; @@ -69,7 +70,7 @@ public async Task GetByIdAndTypeAsync(int id, TransactionType t return transaction; } - public async Task Create(CreateTransactionViewModel transaction) + public async Task CreateAsync(CreateTransactionViewModel transaction) { HttpResponseMessage result; var endpoint = transaction.Type == TransactionType.Sale @@ -110,4 +111,44 @@ public async Task Create(CreateTransactionViewModel transaction createdTransaction.Type = transaction.Type; return createdTransaction; } + public async Task UpdateAsync(TransactionView transaction) + { + HttpResponseMessage result; + var endpoint = transaction.Type == TransactionType.Sale + ? "sales" + : "supplies"; + object data; + + if (transaction.Type == TransactionType.Sale) + { + data = new + { + CustomerId = transaction.PartnerId, + Date = transaction.Date, + SaleItems = transaction.Items + }; + } + else + { + data = new + { + SupplierId = transaction.PartnerId, + Date = transaction.Date, + SupplyItems = transaction.Items + }; + } + + result = await _client.PutAsJsonAsync(endpoint + $"/{transaction.Id}", data); + result.EnsureSuccessStatusCode(); + } + public async Task DeleteAsync(int id,TransactionType type) + { + HttpResponseMessage result; + var endpoint = type == TransactionType.Sale + ? "sales" + : "supplies"; + + result = await _client.DeleteAsync(endpoint + $"/{id}"); + result.EnsureSuccessStatusCode(); + } } \ No newline at end of file diff --git a/WMS.WebUI/WMS.WebUI/Views/Transactions/Delete.cshtml b/WMS.WebUI/WMS.WebUI/Views/Transactions/Delete.cshtml new file mode 100644 index 0000000..e3268e9 --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Transactions/Delete.cshtml @@ -0,0 +1,65 @@ +@model WMS.WebUI.ViewModels.TransactionView + +
+

Are you sure delete?

+
+ +
+
+ @Html.DisplayNameFor(model => model.Id) +
+
+ @Html.DisplayFor(model => model.Id) +
+
+ @Html.DisplayNameFor(model => model.Date) +
+
+ @Html.DisplayFor(model => model.Date) +
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+ @Html.DisplayNameFor(model => model.Partner) +
+
+ @Html.DisplayFor(model => model.Partner) +
+
+ @Html.DisplayNameFor(model => model.TotalDue) +
+
+ @Html.DisplayFor(model => model.TotalDue) +
+
+ +
+ + + + + + + + + +
+
+ +
+
+ + Back + + +
+
diff --git a/WMS.WebUI/WMS.WebUI/Views/Transactions/Details.cshtml b/WMS.WebUI/WMS.WebUI/Views/Transactions/Details.cshtml index def4434..ae79ace 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Transactions/Details.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Transactions/Details.cshtml @@ -1,7 +1,7 @@ @model WMS.WebUI.ViewModels.TransactionView
-

Category details

+

Transaction details


From d5222b908351e96df9e38bd689cae01fcfd2f2d0 Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:16:31 +0500 Subject: [PATCH 09/10] Added editing page --- .../Controllers/TransactionsController.cs | 3 +- .../WMS.WebUI/Stores/TransactionsStore.cs | 2 + .../WMS.WebUI/Views/Transactions/Edit.cshtml | 147 ++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 WMS.WebUI/WMS.WebUI/Views/Transactions/Edit.cshtml diff --git a/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs b/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs index 21ff973..0daddb7 100644 --- a/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs +++ b/WMS.WebUI/WMS.WebUI/Controllers/TransactionsController.cs @@ -86,7 +86,7 @@ public async Task Edit(int id,TransactionType type) ViewBag.Partners = partnersTask.Result; ViewBag.Products= productsTask.Result.Data; - return View(transaction); + return View(transaction.Result); } [HttpPost] @@ -118,6 +118,7 @@ public async Task Delete(int id, TransactionType type) return View(transaction); } + [ValidateAntiForgeryToken] [HttpPost] [ActionName("Delete")] diff --git a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs index e07963f..11ed9ab 100644 --- a/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs +++ b/WMS.WebUI/WMS.WebUI/Stores/TransactionsStore.cs @@ -123,6 +123,7 @@ public async Task UpdateAsync(TransactionView transaction) { data = new { + Id = transaction.Id, CustomerId = transaction.PartnerId, Date = transaction.Date, SaleItems = transaction.Items @@ -132,6 +133,7 @@ public async Task UpdateAsync(TransactionView transaction) { data = new { + Id = transaction.Id, SupplierId = transaction.PartnerId, Date = transaction.Date, SupplyItems = transaction.Items diff --git a/WMS.WebUI/WMS.WebUI/Views/Transactions/Edit.cshtml b/WMS.WebUI/WMS.WebUI/Views/Transactions/Edit.cshtml new file mode 100644 index 0000000..6b626aa --- /dev/null +++ b/WMS.WebUI/WMS.WebUI/Views/Transactions/Edit.cshtml @@ -0,0 +1,147 @@ +@model WMS.WebUI.ViewModels.TransactionView +@using System.Collections.Generic + +
+
+

Create Transaction

+
+ + + + + +
+ + + +
+ +
+
+ + + + +
+
+ + + + + + + + + + +
+
+

0

+
+ + +
+
+ + From a70a2b0e50b900a110c6790ea6798bbaccaf8d0a Mon Sep 17 00:00:00 2001 From: FirdavsAX <137472686+FirdavsAX@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:39:48 +0500 Subject: [PATCH 10/10] editing pages view --- .../PartnerViewModels/PartnerViewModel.cs | 8 +++- .../WMS.WebUI/Views/Partners/Details.cshtml | 35 +++++++++-------- .../WMS.WebUI/Views/Partners/Edit.cshtml | 39 +++++++++---------- .../WMS.WebUI/Views/Partners/Index.cshtml | 9 +++-- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs index 6f0abdc..7f3bcc6 100644 --- a/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs +++ b/WMS.WebUI/WMS.WebUI/ViewModels/PartnerViewModels/PartnerViewModel.cs @@ -1,9 +1,15 @@ -namespace WMS.WebUI.ViewModels.PartnerViewModels; +using System.ComponentModel; + +namespace WMS.WebUI.ViewModels.PartnerViewModels; public class PartnerViewModel { public int Id { get; set; } + + [DisplayName("Full name")] public string FullName { get; set; } + + [DisplayName("Phone number")] public string? PhoneNumber { get; set; } public decimal Balance { get; set; } public PartnerType Type { get; set; } diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml index 3e1dd05..62156a7 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Details.cshtml @@ -1,51 +1,52 @@ @model WMS.WebUI.ViewModels.PartnerViewModels.PartnerViewModel; -
-

Partner details

+

Partner Details


-
+
@Html.DisplayNameFor(model => model.Id)
-
+
@Html.DisplayFor(model => model.Id)
-
+ +
@Html.DisplayNameFor(model => model.FullName)
-
+
@Html.DisplayFor(model => model.FullName)
-
+ +
@Html.DisplayNameFor(model => model.PhoneNumber)
-
+
@Html.DisplayFor(model => model.PhoneNumber)
-
+ +
@Html.DisplayNameFor(model => model.Balance)
-
+
@Html.DisplayFor(model => model.Balance)
-
+ +
@Html.DisplayNameFor(model => model.Type)
-
+
@Html.DisplayFor(model => model.Type)
-
- +
\ No newline at end of file diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml index 0ce08b2..180f48d 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Edit.cshtml @@ -1,30 +1,29 @@ @model WMS.WebUI.ViewModels.PartnerViewModels.EditPartnerViewModel -
-
-

Edit Partner

+
+ +

Edit Partner

-
- - +
+
+ @Html.EJS().TextBox("FirstName").Placeholder("First Name").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Value(Model.FirstName).Render() +
+
+ @Html.EJS().TextBox("LastName").Placeholder("Last Name").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Value(Model.LastName).Render() +
-
- - +
+
+ @Html.EJS().TextBox("PhoneNumber").Placeholder("Phone Number").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Value(Model.PhoneNumber).Render() +
+
+ @Html.EJS().NumericTextBox("Balance").Placeholder("Balance").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Value(Model.Balance).Render() +
-
- - - +
+
- -
diff --git a/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml b/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml index c62f1e7..5061680 100644 --- a/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml +++ b/WMS.WebUI/WMS.WebUI/Views/Partners/Index.cshtml @@ -4,7 +4,6 @@ @{ var partnerTypes = new string[] { "All", "Customers", "Suppliers" }; } -
@@ -42,6 +41,7 @@
+
- + - +
@@ -61,6 +61,7 @@ +