Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create debts page #226

Merged
merged 13 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CheckDrive.Web/CheckDrive.Web/CheckDrive.Web.csproj
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
<Compile Include="Controllers\AuthController.cs" />
<Compile Include="Controllers\CarsController.cs" />
<Compile Include="Controllers\DashboardController.cs" />
<Compile Include="Controllers\DebtsController.cs" />
<Compile Include="Controllers\DispatcherReviewsController.cs" />
<Compile Include="Controllers\DoctorReviewsController.cs" />
<Compile Include="Controllers\DoctorsController.cs" />
12 changes: 10 additions & 2 deletions CheckDrive.Web/CheckDrive.Web/Controllers/DashboardController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CheckDrive.Web.Stores.Accounts;
using CheckDrive.Web.Stores.Dashbord;
using CheckDrive.Web.Stores.Debts;
using CheckDrive.Web.Stores.MockDashboard;
using CheckDrive.Web.ViewModels.Dashboard;
using Microsoft.AspNetCore.Mvc;
@@ -13,11 +14,16 @@ public class DashboardController : Controller
private readonly IDashboardStore _store;
private readonly IAccountDataStore _accountDataStore;
private readonly IMockDashboardStore _mockDashboardStore;
public DashboardController(IDashboardStore store, IAccountDataStore accountDataStore,IMockDashboardStore mockDashboardStore)
private readonly IDebtsStore _debtsStore;
public DashboardController(IDashboardStore store,
IAccountDataStore accountDataStore,
IMockDashboardStore mockDashboardStore,
IDebtsStore debtsStore)
{
_store = store;
_accountDataStore = accountDataStore;
_mockDashboardStore = mockDashboardStore;
_debtsStore = debtsStore;
}

public async Task<IActionResult> Index()
@@ -41,8 +47,10 @@ public async Task<IActionResult> Index()

var dashboard = await _store.GetDashboard();
var mockDashboard = await _mockDashboardStore.GetDashboard();
var debts = _debtsStore.GetAll("" , "");

dashboard.Debts=mockDashboard.Debts;

dashboard.Debts=debts;
dashboard.OilAmount=mockDashboard.OilAmount;

if (dashboard is null)
22 changes: 22 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/Controllers/DebtsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CheckDrive.Web.Stores.Debts;
using Microsoft.AspNetCore.Mvc;

namespace CheckDrive.Web.Controllers;

public class DebtsController : Controller
{
private readonly IDebtsStore _store;
public DebtsController(IDebtsStore debtsStore)
{
_store = debtsStore ?? throw new ArgumentNullException(nameof(debtsStore));
}
public ActionResult Index(string? searchText, string? status)
{
var debts = _store.GetAll(searchText,status);

ViewBag.Status = _store.GetEnum();
ViewBag.SearchText = searchText;
ViewBag.SelectedStatus = status;
return View(debts);
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using CheckDrive.Web.Stores.Accounts;
using CheckDrive.Web.Stores.Cars;
using CheckDrive.Web.Stores.Dashbord;
using CheckDrive.Web.Stores.Debts;
using CheckDrive.Web.Stores.DispatcherReviews;
using CheckDrive.Web.Stores.Dispatchers;
using CheckDrive.Web.Stores.DoctorReviews;
@@ -42,7 +43,9 @@ public static IServiceCollection ConfigureDataStores(this IServiceCollection ser
services.AddScoped<ITechnicianDataStore, MockTechnicianDataStore>();
services.AddScoped<IDashboardStore, DashboardStore>();
services.AddScoped<IMockDashboardStore, MockDashboardStore>();
services.AddScoped<IDebtsStore, DebtsStore>();
services.AddScoped<IUserDataStore, UserDataStore>();

services.AddScoped<IMenuService, MenuService>();
services.AddScoped<ICurrentUserService, CurrentUserService>();
return services;
3 changes: 1 addition & 2 deletions CheckDrive.Web/CheckDrive.Web/Models/Enums/DebtStatus.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,5 @@
public enum DebtStatus
{
Paid,
Unpaid,
PartiallyPaid
Unpaid
}
168 changes: 168 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/Stores/Debts/DebtsStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using CheckDrive.Web.Models.Enums;
using CheckDrive.Web.ViewModels.Debt;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace CheckDrive.Web.Stores.Debts;

public class DebtsStore : IDebtsStore
{
public List<DebtViewModel> GetAll(string? searchText, string? status)
{
var debts = new List<DebtViewModel>()
{
new DebtViewModel()
{
Id = 1,
Driver = "Qodir Salomov",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 2,
Driver = "Steve Jobs",
DebtAmount = 40,
Oil = OilType.Ai92,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 3,
Driver = "Shohruh Fozilov",
DebtAmount = 20,
Oil = OilType.Ai91,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 4,
Driver = "John Doe",
DebtAmount = 50,
Oil = OilType.Ai92,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 5,
Driver = "Dilshod Ravshanov",
DebtAmount = 40,
Oil = OilType.Diesel,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 6,
Driver = "Sardor Jo'rayev",
DebtAmount = 30,
Oil = OilType.Ai92,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 7,
Driver = "Rustam Ilhomov",
DebtAmount = 10,
Oil = OilType.Diesel,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 8,
Driver = "Jahongir Qobilov",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 9,
Driver = "Feruz Amirov",
DebtAmount = 10,
Oil = OilType.Ai91,
Status = DebtStatus.Unpaid,
},
new DebtViewModel()
{
Id = 10,
Driver = "Albert Sims",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 10,
Driver = "Albert Sims",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 10,
Driver = "Albert Sims",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 10,
Driver = "Albert Sims",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 10,
Driver = "Albert Sims",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
},
new DebtViewModel()
{
Id = 10,
Driver = "Albert Sims",
DebtAmount = 40,
Oil = OilType.Ai80,
Status = DebtStatus.Paid,
}
};

var result = new List<DebtViewModel>();

if(!string.IsNullOrEmpty(searchText))
{
result.AddRange(debts.Where(d => d.Driver.ToLower().Contains(searchText.ToLower())|| d.OilTypeText.ToLower().Contains(searchText.ToLower())).ToList());
}
if(!string.IsNullOrEmpty(status))
{
result.AddRange(debts.Where(d=>d.Status.ToString()==status));
}

if(string.IsNullOrEmpty(status) && string.IsNullOrEmpty(searchText))
return debts;

return result;
}

public List<SelectListItem> GetEnum()
{
return Enum.GetValues(typeof(DebtStatus))
.Cast<DebtStatus>()
.Select(s => new SelectListItem
{
Value = s.ToString(),
Text = s switch
{
DebtStatus.Paid => "Toʻlangan",
DebtStatus.Unpaid => "Toʻlanmagan",
_ => s.ToString()
}
})
.ToList();
}
}
10 changes: 10 additions & 0 deletions CheckDrive.Web/CheckDrive.Web/Stores/Debts/IDebtsStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CheckDrive.Web.ViewModels.Debt;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace CheckDrive.Web.Stores.Debts;

public interface IDebtsStore
{
List<DebtViewModel> GetAll(string? searchText, string? status );
List<SelectListItem> GetEnum();
}
2 changes: 1 addition & 1 deletion CheckDrive.Web/CheckDrive.Web/Stores/Menu/MenuService.cs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public List<Object> GetMenuItems(string role)
{
text = "Qarzlar",
iconCss = "fa-solid fa-file-invoice-dollar",
url = "/#",
url = "/debts",
});

menuItems.Add(new
Loading