diff --git a/CheckDrive.Web/CheckDrive.Web/Controllers/CarsController.cs b/CheckDrive.Web/CheckDrive.Web/Controllers/CarsController.cs index 3c3e21a8..d21a721e 100644 --- a/CheckDrive.Web/CheckDrive.Web/Controllers/CarsController.cs +++ b/CheckDrive.Web/CheckDrive.Web/Controllers/CarsController.cs @@ -1,85 +1,32 @@ -using CheckDrive.ApiContracts; -using CheckDrive.ApiContracts.Car; +using CheckDrive.Web.Mappings; +using CheckDrive.Web.Requests.Cars; using CheckDrive.Web.Stores.Cars; +using CheckDrive.Web.Stores.OilMarks; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; namespace CheckDrive.Web.Controllers; -public class CarsController : Controller +public class CarsController(ICarStore carStore, IOilMarkStore oilMarkStore) : Controller { - private readonly ICarDataStore _carDataStore; - - public CarsController(ICarDataStore carDataStore) + public async Task Index() { - _carDataStore = carDataStore; - } - - public async Task Index(string? searchString, int? pageNumber) - { - var cars = await _carDataStore.GetCarsAsync(searchString, pageNumber); - - ViewBag.SearchString = searchString; + var cars = await carStore.GetAsync(); - ViewBag.PageSize = cars.PageSize; - ViewBag.PageCount = cars.TotalPages; - ViewBag.TotalCount = cars.TotalCount; - ViewBag.CurrentPage = cars.PageNumber; - ViewBag.HasPreviousPage = cars.HasPreviousPage; - ViewBag.HasNextPage = cars.HasNextPage; - - var _cars = cars.Data.Select(c => new - { - c.Id, - c.Model, - c.Number, - c.Mileage, - c.Color, - c.RemainingFuel, - c.MeduimFuelConsumption, - c.FuelTankCapacity, - c.ManufacturedYear, - Status = ((CarStatusDto)c.CarStatus) switch - { - CarStatusDto.Free => "Bo'sh", - CarStatusDto.Busy => "Band", - CarStatusDto.Limited => "Limit tugagan", - _ => "No`malum holat" - } - }).ToList(); - - ViewBag.Cars = _cars; - return View(); - } - - public async Task CarHistoryIndex(string? searchString, int? pageNumber, int? year, int? month) - { - var cars = await _carDataStore.GetCarsHistoryAsync(searchString, pageNumber, year, month); - - ViewBag.SearchString = searchString; - ViewBag.Cars = cars.Data; - - ViewBag.PageSize = cars.PageSize; - ViewBag.PageCount = cars.TotalPages; - ViewBag.TotalCount = cars.TotalCount; - ViewBag.CurrentPage = cars.PageNumber; - ViewBag.HasPreviousPage = cars.HasPreviousPage; - ViewBag.HasNextPage = cars.HasNextPage; + ViewBag.Cars = cars; return View(); } public async Task Details(int id) { - var car = await _carDataStore.GetCarAsync(id); - if (car == null) - { - return NotFound(); - } + var car = await carStore.GetByIdAsync(id); + return View(car); } public async Task DetailsForMechanicAcceptance(int id) { - var car = await _carDataStore.GetCarAsync(id); + var car = await carStore.GetByIdAsync(id); if (car == null) { return NotFound(); @@ -89,7 +36,7 @@ public async Task DetailsForMechanicAcceptance(int id) public async Task DetailsForMechanicHandover(int id) { - var car = await _carDataStore.GetCarAsync(id); + var car = await carStore.GetByIdAsync(id); if (car == null) { return NotFound(); @@ -97,48 +44,55 @@ public async Task DetailsForMechanicHandover(int id) return PartialView("_CarDetailsForMechanicHandover", car); } - public IActionResult Create() + public async Task Create() { + var oilMarks = await GetOilMarkAsync(); + ViewBag.OilMarks = oilMarks; + return View(); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Create([Bind("Model,Color,Number,RemainingFuel,Mileage, MeduimFuelConsumption,FuelTankCapacity,ManufacturedYear, OneYearMediumDistance")] CarForCreateDto car) + public async Task Create([FromForm] CreateCarRequest request) { if (ModelState.IsValid) { - var newCar = await _carDataStore.CreateCarAsync(car); + var newCar = await carStore.CreateAsync(request); return RedirectToAction(nameof(Index)); } - return View(car); + return BadRequest(ModelState); } public async Task Edit(int id) { - var car = await _carDataStore.GetCarAsync(id); - if (car == null) - { - return NotFound(); - } - return View(car); + var car = await carStore.GetByIdAsync(id); + var oilMarks = await GetOilMarkAsync(); + + ViewBag.OilMarks = oilMarks; + var carRequest = car.ToUpdateViewModel(); + + return View(carRequest); } [HttpPost] [ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("Id,Model,Color,Number,RemainingFuel,Mileage, MeduimFuelConsumption,FuelTankCapacity,ManufacturedYear, OneYearMediumDistance")] CarForUpdateDto car) + public async Task Edit([FromForm] UpdateCarRequest request) { - if (ModelState.IsValid) + try { - var newCar = await _carDataStore.UpdateCarAsync(id, car); + await carStore.UpdateAsync(request); return RedirectToAction(nameof(Index)); } - return View(car); + catch(Exception ex) + { + return BadRequest(); + } } public async Task Delete(int id) { - var car = await _carDataStore.GetCarAsync(id); + var car = await carStore.GetByIdAsync(id); if (car == null) { return NotFound(); @@ -150,7 +104,20 @@ public async Task Delete(int id) [ValidateAntiForgeryToken] public async Task DeleteConfirmed(int id) { - await _carDataStore.DeleteCarAsync(id); + await carStore.DeleteAsync(id); return RedirectToAction(nameof(Index)); } -} + + private async Task> GetOilMarkAsync() + { + var oilMarks = await oilMarkStore.GetAsync(); + + return oilMarks + .Select(e => new SelectListItem() + { + Value = e.Id.ToString(), + Text = e.Name.ToString() + }) + .ToList(); + } +} \ No newline at end of file diff --git a/CheckDrive.Web/CheckDrive.Web/Controllers/EmployeesController.cs b/CheckDrive.Web/CheckDrive.Web/Controllers/EmployeesController.cs index 1c10bacc..ab302c67 100644 --- a/CheckDrive.Web/CheckDrive.Web/Controllers/EmployeesController.cs +++ b/CheckDrive.Web/CheckDrive.Web/Controllers/EmployeesController.cs @@ -10,20 +10,11 @@ namespace CheckDrive.Web.Controllers; -public class EmployeesController : Controller +public class EmployeesController(IEmployeeStore employeeStore, ICarStore carStore) : Controller { - private readonly IEmployeeStore _employeeStore; - private readonly ICarDataStore _carStore; - - public EmployeesController(IEmployeeStore employeeStore, ICarDataStore carStore) - { - _employeeStore = employeeStore ?? throw new ArgumentNullException(nameof(employeeStore)); - _carStore = carStore ?? throw new ArgumentNullException(nameof(carStore)); - } - public async Task Index() { - var employees = await _employeeStore.GetAsync(); + var employees = await employeeStore.GetAsync(); ViewBag.Positions = GetPositions(); return View(employees); @@ -31,7 +22,7 @@ public async Task Index() public async Task Details(int id) { - var employee = await _employeeStore.GetByIdAsync(id); + var employee = await employeeStore.GetByIdAsync(id); return View(employee); } @@ -50,9 +41,9 @@ public async Task Create(CreateEmployeeRequest request) { try { - var createdEmployee = await _employeeStore.CreateAsync(request); - - return RedirectToAction(nameof(Details), new { id = createdEmployee.Id }); + var createdEmployee = await employeeStore.CreateAsync(request); + + return RedirectToAction(nameof(Index)); } catch { @@ -62,7 +53,7 @@ public async Task Create(CreateEmployeeRequest request) public async Task Edit(int id) { - var employee = await _employeeStore.GetByIdAsync(id); + var employee = await employeeStore.GetByIdAsync(id); ViewBag.Positions = GetPositions(); ViewBag.Cars = await GetCarsAsync(); @@ -77,8 +68,7 @@ public async Task Edit(UpdateEmployeeRequest request) { try { - await _employeeStore.UpdateAsync(request); - + await employeeStore.UpdateAsync(request); return RedirectToAction(nameof(Index)); } catch @@ -89,7 +79,7 @@ public async Task Edit(UpdateEmployeeRequest request) public async Task Delete(int id) { - var employee = await _employeeStore.GetByIdAsync(id); + var employee = await employeeStore.GetByIdAsync(id); return View(employee); } @@ -100,7 +90,7 @@ public async Task Delete(int id, IFormCollection _) { try { - await _employeeStore.DeleteAsync(id); + await employeeStore.DeleteAsync(id); return RedirectToAction(nameof(Index)); } catch @@ -127,7 +117,7 @@ private static List GetPositions() private async Task> GetCarsAsync() { - var cars = await _carStore.GetAsync(); + var cars = await carStore.GetAsync(); return cars .Select(e => new SelectListItem() diff --git a/CheckDrive.Web/CheckDrive.Web/Controllers/OilMarksController.cs b/CheckDrive.Web/CheckDrive.Web/Controllers/OilMarksController.cs index f1eaf329..573135b8 100644 --- a/CheckDrive.Web/CheckDrive.Web/Controllers/OilMarksController.cs +++ b/CheckDrive.Web/CheckDrive.Web/Controllers/OilMarksController.cs @@ -1,76 +1,73 @@ -using CheckDrive.ApiContracts.OilMark; +using CheckDrive.Web.Requests.OilMark; using CheckDrive.Web.Stores.OilMarks; using Microsoft.AspNetCore.Mvc; -namespace CheckDrive.Web.Controllers +namespace CheckDrive.Web.Controllers; + +public class OilMarksController(IOilMarkStore oilMarkDataStore) : Controller { - public class OilMarksController(IOilMarkDataStore oilMarkDataStore) : Controller + public async Task Index() { - private readonly IOilMarkDataStore _oilMarkDataStore = oilMarkDataStore; + var oilMarks = await oilMarkDataStore.GetAsync(); - public async Task Index() - { - var oilMarks = await _oilMarkDataStore.GetOilMarksAsync(); - var oilMarkss = oilMarks.Data.ToList(); - return View(oilMarkss); - } + return View(oilMarks); + } - public async Task Details(int id) - { - var oilMark = await _oilMarkDataStore.GetOilMarkByIdAsync(id); + public async Task Details(int id) + { + var oilMark = await oilMarkDataStore.GetByIdAsync(id); - return View(oilMark); - } + return View(oilMark); + } - public IActionResult Create() - { - return View(); - } + public IActionResult Create() + { + return View(); + } - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Create([Bind("OilMark")] OilMarkForCreateDto _oilmark) + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create([FromForm] CreateOilMarkRequest request) + { + if (ModelState.IsValid) { - if (ModelState.IsValid) - { - await _oilMarkDataStore.CreateOilMarkAsync(_oilmark); - return RedirectToAction(nameof(Index)); - } - return View(_oilmark); + await oilMarkDataStore.CreateAsync(request); + return RedirectToAction(nameof(Index)); } + return View(request); + } - public async Task Edit(int id) - { - var oilMark = await _oilMarkDataStore.GetOilMarkByIdAsync(id); + public async Task Edit(int id) + { + var oilMark = await oilMarkDataStore.GetByIdAsync(id); - return View(oilMark); - } + return View(oilMark); + } - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("Id,OilMark")] OilMarkForUpdateDto _oilMark) + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit([FromForm] UpdateOilMarkRequest request) + { + if (ModelState.IsValid) { - if (ModelState.IsValid) - { - await _oilMarkDataStore.UpdateOilMarkAsync(id, _oilMark); - return RedirectToAction(nameof(Index)); - } - return View(_oilMark); + await oilMarkDataStore.UpdateAsync(request); + return RedirectToAction(nameof(Index)); } + return View(request); + } - public async Task Delete(int id) - { - var oilMark = await _oilMarkDataStore.GetOilMarkByIdAsync(id); - - return View(oilMark); - } + public async Task Delete(int id) + { + var oilMark = await oilMarkDataStore.GetByIdAsync(id); - [HttpPost, ActionName("Delete")] - [ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - await _oilMarkDataStore.DeleteOilMarkAsync(id); - return RedirectToAction(nameof(Index)); - } + return View(oilMark); + } + + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + await oilMarkDataStore.DeleteAsync(id); + return RedirectToAction(nameof(Index)); } } diff --git a/CheckDrive.Web/CheckDrive.Web/Extensions/DependencyInjection.cs b/CheckDrive.Web/CheckDrive.Web/Extensions/DependencyInjection.cs index 2cdb85d6..8b324f60 100644 --- a/CheckDrive.Web/CheckDrive.Web/Extensions/DependencyInjection.cs +++ b/CheckDrive.Web/CheckDrive.Web/Extensions/DependencyInjection.cs @@ -59,7 +59,7 @@ private static void AddConfigurations(IServiceCollection services, IConfiguratio private static void AddStores(IServiceCollection services) { services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -68,7 +68,7 @@ private static void AddStores(IServiceCollection services) services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/CheckDrive.Web/CheckDrive.Web/Mappings/CarMappings.cs b/CheckDrive.Web/CheckDrive.Web/Mappings/CarMappings.cs new file mode 100644 index 00000000..9d24ff56 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Mappings/CarMappings.cs @@ -0,0 +1,30 @@ +using CheckDrive.Web.Requests.Cars; +using CheckDrive.Web.ViewModels.Car; + +namespace CheckDrive.Web.Mappings; + +public static class CarMappings +{ + public static UpdateCarRequest ToUpdateViewModel(this CarViewModel car) => + new() + { + Id = car.Id, + OilMarkId = car.OilMarkId, + Model = car.Model, + Number = car.Number, + ManufacturedYear = car.ManufacturedYear, + Mileage = car.Mileage, + CurrentMonthMileage = car.CurrentMonthMileage, + CurrentYearMileage = car.CurrentYearMileage, + MonthlyDistanceLimit = car.MonthlyDistanceLimit, + YearlyDistanceLimit = car.YearlyDistanceLimit, + CurrentMonthFuelConsumption = car.CurrentMonthFuelConsumption, + CurrentYearFuelConsumption = car.CurrentYearFuelConsumption, + MonthlyFuelConsumptionLimit = car.MonthlyFuelConsumptionLimit, + YearlyFuelConsumptionLimit = car.YearlyFuelConsumptionLimit, + AverageFuelConsumption = car.AverageFuelConsumption, + FuelCapacity = car.FuelCapacity, + RemainingFuel = car.RemainingFuel, + Status = car.Status + }; +} diff --git a/CheckDrive.Web/CheckDrive.Web/Requests/Cars/CreateCarRequest.cs b/CheckDrive.Web/CheckDrive.Web/Requests/Cars/CreateCarRequest.cs new file mode 100644 index 00000000..1ecfe239 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Requests/Cars/CreateCarRequest.cs @@ -0,0 +1,24 @@ +using CheckDrive.Web.Models.Enums; + +namespace CheckDrive.Web.Requests.Cars; + +public class CreateCarRequest +{ + public int OilMarkId { get; set; } + public required string Model { get; set; } + public required string Number { get; set; } + public int ManufacturedYear { get; set; } + public decimal Mileage { get; set; } + public decimal CurrentMonthMileage { get; set; } + public decimal CurrentYearMileage { get; set; } + public decimal YearlyDistanceLimit { get; set; } + public decimal MonthlyDistanceLimit { get; set; } + public decimal CurrentMonthFuelConsumption { get; set; } + public decimal CurrentYearFuelConsumption { get; set; } + public decimal MonthlyFuelConsumptionLimit { get; set; } + public decimal YearlyFuelConsumptionLimit { get; set; } + public decimal AverageFuelConsumption { get; set; } + public decimal FuelCapacity { get; set; } + public decimal RemainingFuel { get; set; } + public CarStatus Status { get; set; } +} diff --git a/CheckDrive.Web/CheckDrive.Web/Requests/Cars/UpdateCarRequest.cs b/CheckDrive.Web/CheckDrive.Web/Requests/Cars/UpdateCarRequest.cs new file mode 100644 index 00000000..87de0df9 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Requests/Cars/UpdateCarRequest.cs @@ -0,0 +1,6 @@ +namespace CheckDrive.Web.Requests.Cars; + +public class UpdateCarRequest : CreateCarRequest +{ + public int Id { get; set; } +} \ No newline at end of file diff --git a/CheckDrive.Web/CheckDrive.Web/Requests/OilMark/CreateOilMarkRequest.cs b/CheckDrive.Web/CheckDrive.Web/Requests/OilMark/CreateOilMarkRequest.cs new file mode 100644 index 00000000..38b85248 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Requests/OilMark/CreateOilMarkRequest.cs @@ -0,0 +1,6 @@ +namespace CheckDrive.Web.Requests.OilMark; + +public class CreateOilMarkRequest +{ + public required string Name { get; set; } +} diff --git a/CheckDrive.Web/CheckDrive.Web/Requests/OilMark/UpdateOilMarkRequest.cs b/CheckDrive.Web/CheckDrive.Web/Requests/OilMark/UpdateOilMarkRequest.cs new file mode 100644 index 00000000..cdd9852e --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Requests/OilMark/UpdateOilMarkRequest.cs @@ -0,0 +1,6 @@ +namespace CheckDrive.Web.Requests.OilMark; + +public class UpdateOilMarkRequest : CreateOilMarkRequest +{ + public int Id { get; set; } +} diff --git a/CheckDrive.Web/CheckDrive.Web/Services/CheckDriveApi.cs b/CheckDrive.Web/CheckDrive.Web/Services/CheckDriveApi.cs index 331a1f3f..4499d45b 100644 --- a/CheckDrive.Web/CheckDrive.Web/Services/CheckDriveApi.cs +++ b/CheckDrive.Web/CheckDrive.Web/Services/CheckDriveApi.cs @@ -2,20 +2,11 @@ namespace CheckDrive.Web.Services; -public class CheckDriveApi +public class CheckDriveApi(HttpClient client, ILogger logger) { - private readonly HttpClient _client; - private readonly ILogger _logger; - - public CheckDriveApi(HttpClient client, ILogger logger) - { - _client = client ?? throw new ArgumentNullException(nameof(client)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - public async Task GetAsync(string url) { - var response = await _client.GetAsync(url); + var response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); @@ -23,7 +14,7 @@ public async Task GetAsync(string url) if (result is null) { - _logger.LogWarning( + logger.LogWarning( "Response deserialization returned null for type {Type} from resource {Url} and method GET", typeof(TResult), url); @@ -36,7 +27,7 @@ public async Task GetAsync(string url) public async Task PostAsync(string url, TBody data) { - var response = await _client.PostAsJsonAsync(url, data); + var response = await client.PostAsJsonAsync(url, data); response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); @@ -44,7 +35,7 @@ public async Task PostAsync(string url, TBody data) if (result is null) { - _logger.LogWarning( + logger.LogWarning( "Response deserialization returned null for type {Type} from resource {Url} and method POST", typeof(TResult), url); @@ -57,13 +48,13 @@ public async Task PostAsync(string url, TBody data) public async Task PutAsync(string url, TBody data) { - var response = await _client.PutAsJsonAsync(url, data); + var response = await client.PutAsJsonAsync(url, data); response.EnsureSuccessStatusCode(); } public async Task DeleteAsync(string url) { - var response = await _client.DeleteAsync(url); + var response = await client.DeleteAsync(url); response.EnsureSuccessStatusCode(); } } diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/Cars/CarDataStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/Cars/CarDataStore.cs deleted file mode 100644 index f2614353..00000000 --- a/CheckDrive.Web/CheckDrive.Web/Stores/Cars/CarDataStore.cs +++ /dev/null @@ -1,64 +0,0 @@ -using CheckDrive.ApiContracts.Car; -using CheckDrive.Web.Models; -using CheckDrive.Web.Responses; -using CheckDrive.Web.Services; - -namespace CheckDrive.Web.Stores.Cars; - -public class CarDataStore : ICarDataStore -{ - private readonly CheckDriveApi _apiClient; - - public CarDataStore(CheckDriveApi apiClient) - { - _apiClient = apiClient; - } - - public Task> GetAsync() - => _apiClient.GetAsync>("cars"); - - public Task CreateCarAsync(CarForCreateDto carForCreate) - { - throw new NotImplementedException(); - } - - public Task DeleteCarAsync(int id) - { - throw new NotImplementedException(); - } - - public Task GetCarAsync(int id) - { - throw new NotImplementedException(); - } - - public Task GetCarsAsync(string? searchString, int? pageNumber) - { - throw new NotImplementedException(); - } - - public Task GetCarsAsync(int? roleId, bool? isBusy) - { - throw new NotImplementedException(); - } - - public Task GetCarsHistoryAsync(string? searchString, int? pageNumber, int? year, int? month) - { - throw new NotImplementedException(); - } - - public Task UpdateCarAsync(int id, CarForUpdateDto car) - { - throw new NotImplementedException(); - } - - public Task CreateCarAsync(DTOs.Car.CarForCreateDto carForCreate) - { - throw new NotImplementedException(); - } - - public Task UpdateCarAsync(int id, DTOs.Car.CarForUpdateDto car) - { - throw new NotImplementedException(); - } -} diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/Cars/CarStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/Cars/CarStore.cs new file mode 100644 index 00000000..1da88691 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Stores/Cars/CarStore.cs @@ -0,0 +1,25 @@ +using CheckDrive.Web.Requests.Cars; +using CheckDrive.Web.Services; +using CheckDrive.Web.ViewModels.Car; + +namespace CheckDrive.Web.Stores.Cars; + +internal sealed class CarStore(CheckDriveApi apiClient) : ICarStore +{ + private static readonly string resourceUrl = "cars"; + + public Task> GetAsync() + => apiClient.GetAsync>(resourceUrl); + + public Task GetByIdAsync(int id) + => apiClient.GetAsync($"{resourceUrl}/{id}"); + + public Task CreateAsync(CreateCarRequest request) + => apiClient.PostAsync(resourceUrl, request); + + public Task UpdateAsync(UpdateCarRequest request) + => apiClient.PutAsync($"{resourceUrl}/{request.Id}", request); + + public Task DeleteAsync(int id) + => apiClient.DeleteAsync($"{resourceUrl}/{id}"); +} \ No newline at end of file diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/Cars/ICarDataStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/Cars/ICarDataStore.cs deleted file mode 100644 index c774dc82..00000000 --- a/CheckDrive.Web/CheckDrive.Web/Stores/Cars/ICarDataStore.cs +++ /dev/null @@ -1,17 +0,0 @@ -using CheckDrive.ApiContracts.Car; -using CheckDrive.Web.Models; -using CheckDrive.Web.Responses; - -namespace CheckDrive.Web.Stores.Cars; - -public interface ICarDataStore -{ - Task> GetAsync(); - Task GetCarsAsync(string? searchString, int? pageNumber); - Task GetCarsAsync(int? roleId, bool? isBusy); - Task GetCarAsync(int id); - Task GetCarsHistoryAsync(string? searchString, int? pageNumber, int? year, int? month); - Task CreateCarAsync(CarForCreateDto carForCreate); - Task UpdateCarAsync(int id, CarForUpdateDto car); - Task DeleteCarAsync(int id); -} diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/Cars/ICarStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/Cars/ICarStore.cs new file mode 100644 index 00000000..f69bb1d0 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Stores/Cars/ICarStore.cs @@ -0,0 +1,13 @@ +using CheckDrive.Web.Requests.Cars; +using CheckDrive.Web.ViewModels.Car; + +namespace CheckDrive.Web.Stores.Cars; + +public interface ICarStore +{ + Task> GetAsync(); + Task GetByIdAsync(int id); + Task CreateAsync(CreateCarRequest request); + Task UpdateAsync(UpdateCarRequest request); + Task DeleteAsync(int id); +} diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/Employee/EmployeeStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/Employee/EmployeeStore.cs index 292bec7f..d6e14b96 100644 --- a/CheckDrive.Web/CheckDrive.Web/Stores/Employee/EmployeeStore.cs +++ b/CheckDrive.Web/CheckDrive.Web/Stores/Employee/EmployeeStore.cs @@ -4,28 +4,22 @@ namespace CheckDrive.Web.Stores.Employee; -internal sealed class EmployeeStore : IEmployeeStore +internal sealed class EmployeeStore(CheckDriveApi apiClient) : IEmployeeStore { private static readonly string resourceUrl = "employees"; - private readonly CheckDriveApi _apiClient; - - public EmployeeStore(CheckDriveApi apiClient) - { - _apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); - } public Task> GetAsync() - => _apiClient.GetAsync>(resourceUrl); + => apiClient.GetAsync>(resourceUrl); public Task GetByIdAsync(int id) - => _apiClient.GetAsync($"{resourceUrl}/{id}"); + => apiClient.GetAsync($"{resourceUrl}/{id}"); public Task CreateAsync(CreateEmployeeRequest request) - => _apiClient.PostAsync(resourceUrl, request); + => apiClient.PostAsync(resourceUrl, request); public Task UpdateAsync(UpdateEmployeeRequest request) - => _apiClient.PutAsync($"{resourceUrl}/{request.Id}", request); + => apiClient.PutAsync($"{resourceUrl}/{request.Id}", request); public Task DeleteAsync(int id) - => _apiClient.DeleteAsync($"{resourceUrl}/{id}"); + => apiClient.DeleteAsync($"{resourceUrl}/{id}"); } diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/IOilMarkDataStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/IOilMarkDataStore.cs deleted file mode 100644 index 4adf0de9..00000000 --- a/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/IOilMarkDataStore.cs +++ /dev/null @@ -1,15 +0,0 @@ -using CheckDrive.ApiContracts.OilMark; -using CheckDrive.Web.Responses; -using Microsoft.AspNetCore.Mvc; - -namespace CheckDrive.Web.Stores.OilMarks -{ - public interface IOilMarkDataStore - { - Task GetOilMarksAsync(); - Task GetOilMarkByIdAsync(int id); - Task CreateOilMarkAsync(OilMarkForCreateDto review); - Task UpdateOilMarkAsync(int id, OilMarkForUpdateDto review); - Task DeleteOilMarkAsync(int id); - } -} diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/IOilMarkStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/IOilMarkStore.cs new file mode 100644 index 00000000..d347c297 --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/IOilMarkStore.cs @@ -0,0 +1,13 @@ +using CheckDrive.Web.Requests.OilMark; +using CheckDrive.Web.ViewModels.OilMark; + +namespace CheckDrive.Web.Stores.OilMarks; + +public interface IOilMarkStore +{ + Task> GetAsync(); + Task GetByIdAsync(int id); + Task CreateAsync(CreateOilMarkRequest request); + Task UpdateAsync(UpdateOilMarkRequest request); + Task DeleteAsync(int id); +} diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/OilMarkDataStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/OilMarkDataStore.cs deleted file mode 100644 index ddd5dc96..00000000 --- a/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/OilMarkDataStore.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CheckDrive.ApiContracts.OilMark; -using CheckDrive.Web.Responses; -using CheckDrive.Web.Services; - -namespace CheckDrive.Web.Stores.OilMarks; - -public class OilMarkDataStore : IOilMarkDataStore -{ - private readonly CheckDriveApi _apiClient; - - public OilMarkDataStore(CheckDriveApi apiClient) - { - _apiClient = apiClient; - } - - public Task CreateOilMarkAsync(OilMarkForCreateDto review) - { - throw new NotImplementedException(); - } - - public Task DeleteOilMarkAsync(int id) - { - throw new NotImplementedException(); - } - - public Task GetOilMarkByIdAsync(int id) - { - throw new NotImplementedException(); - } - - public Task GetOilMarksAsync() - { - throw new NotImplementedException(); - } - - public Task UpdateOilMarkAsync(int id, OilMarkForUpdateDto review) - { - throw new NotImplementedException(); - } -} diff --git a/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/OilMarkStore.cs b/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/OilMarkStore.cs new file mode 100644 index 00000000..a7bac00d --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/Stores/OilMarks/OilMarkStore.cs @@ -0,0 +1,25 @@ +using CheckDrive.Web.Requests.OilMark; +using CheckDrive.Web.Services; +using CheckDrive.Web.ViewModels.OilMark; + +namespace CheckDrive.Web.Stores.OilMarks; + +public class OilMarkStore(CheckDriveApi apiClient) : IOilMarkStore +{ + private static readonly string resourceUrl = "oilMarks"; + + public Task> GetAsync() + => apiClient.GetAsync>(resourceUrl); + + public Task GetByIdAsync(int id) + => apiClient.GetAsync($"{resourceUrl}/{id}"); + + public Task CreateAsync(CreateOilMarkRequest request) + => apiClient.PostAsync(resourceUrl, request); + + public Task UpdateAsync(UpdateOilMarkRequest request) + => apiClient.PutAsync($"{resourceUrl}/{request.Id}", request); + + public Task DeleteAsync(int id) + => apiClient.DeleteAsync($"{resourceUrl}/{id}"); +} diff --git a/CheckDrive.Web/CheckDrive.Web/ViewModels/Car/CarViewModel.cs b/CheckDrive.Web/CheckDrive.Web/ViewModels/Car/CarViewModel.cs new file mode 100644 index 00000000..5cae826c --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/ViewModels/Car/CarViewModel.cs @@ -0,0 +1,25 @@ +using CheckDrive.Web.Models.Enums; + +namespace CheckDrive.Web.ViewModels.Car; + +public class CarViewModel +{ + public int Id { get; set; } + public int OilMarkId { get; set; } + public required string Model { get; set; } + public required string Number { get; set; } + public int ManufacturedYear { get; set; } + public decimal Mileage { get; set; } + public decimal CurrentMonthMileage { get; set; } + public decimal CurrentYearMileage { get; set; } + public decimal MonthlyDistanceLimit { get; set; } + public decimal YearlyDistanceLimit { get; set; } + public decimal CurrentMonthFuelConsumption { get; set; } + public decimal CurrentYearFuelConsumption { get; set; } + public decimal MonthlyFuelConsumptionLimit { get; set; } + public decimal YearlyFuelConsumptionLimit { get; set; } + public decimal AverageFuelConsumption { get; set; } + public decimal FuelCapacity { get; set; } + public decimal RemainingFuel { get; set; } + public CarStatus Status { get; set; } +} diff --git a/CheckDrive.Web/CheckDrive.Web/ViewModels/OilMark/OilMarkViewModel.cs b/CheckDrive.Web/CheckDrive.Web/ViewModels/OilMark/OilMarkViewModel.cs new file mode 100644 index 00000000..eca8aa9b --- /dev/null +++ b/CheckDrive.Web/CheckDrive.Web/ViewModels/OilMark/OilMarkViewModel.cs @@ -0,0 +1,7 @@ +namespace CheckDrive.Web.ViewModels.OilMark; + +public class OilMarkViewModel +{ + public int Id { get; set; } + public required string Name { get; set; } +} diff --git a/CheckDrive.Web/CheckDrive.Web/Views/Cars/Create.cshtml b/CheckDrive.Web/CheckDrive.Web/Views/Cars/Create.cshtml index 3905a3d9..368eb606 100644 --- a/CheckDrive.Web/CheckDrive.Web/Views/Cars/Create.cshtml +++ b/CheckDrive.Web/CheckDrive.Web/Views/Cars/Create.cshtml @@ -1,4 +1,5 @@ -@model CheckDrive.ApiContracts.Car.CarForCreateDto +@using CheckDrive.Web.Requests.Cars +@model CreateCarRequest @{ ViewData["Title"] = "Create"; @@ -18,11 +19,6 @@ -
- - - -
@@ -34,14 +30,19 @@
- - - + + + +
+
+ + +
- - - + + +
@@ -49,21 +50,21 @@
- - - + + +
- +
- +
- +
- Rangi + Ishlab chiqarilgan yil
Davlat raqami @@ -22,16 +23,13 @@ @Model.Model
- @Model.Color + @Model.ManufacturedYear
@Model.Number
-
- Ishlab chiqarilgan yil -
Bosib o'tgan masofasi
@@ -40,9 +38,6 @@
-
- @Model.ManufacturedYear -
@Model.Mileage
@@ -60,10 +55,10 @@
- @Model.MeduimFuelConsumption + @Model.AverageFuelConsumption
- @Model.FuelTankCapacity + @Model.FuelCapacity
@@ -76,10 +71,10 @@
- @Model.OneYearMediumDistance + @Model.YearlyDistanceLimit
- @Model.OneMonthMediumDistance + @Model.MonthlyDistanceLimit
@@ -92,124 +87,10 @@
- @Model.OneYearMeduimFuelConsumption + @Model.YearlyFuelConsumptionLimit
- @Model.OneMonthMeduimFuelConsumption -
-
- - - - -@section Scripts { - -} - + \ No newline at end of file diff --git a/CheckDrive.Web/CheckDrive.Web/Views/Cars/Edit.cshtml b/CheckDrive.Web/CheckDrive.Web/Views/Cars/Edit.cshtml index a6d89807..384f87d5 100644 --- a/CheckDrive.Web/CheckDrive.Web/Views/Cars/Edit.cshtml +++ b/CheckDrive.Web/CheckDrive.Web/Views/Cars/Edit.cshtml @@ -1,14 +1,16 @@ -@model CheckDrive.ApiContracts.Car.CarDto +@using CheckDrive.Web.Requests.Cars +@model UpdateCarRequest @{ ViewData["Title"] = "Edit"; Layout = "~/Views/Shared/_LayoutForModal.cshtml"; } -
+ @Html.AntiForgeryToken()
+
-
+
@@ -18,11 +20,6 @@
-
- - - -
@@ -34,14 +31,19 @@
- - - + + + +
+
+ + +
- - - + + +
@@ -49,21 +51,22 @@
- - - + + +
- - + + +
- - + +
- - + +
-@section Scripts { - -} - - diff --git a/CheckDrive.Web/CheckDrive.Web/Views/Cars/Index.cshtml b/CheckDrive.Web/CheckDrive.Web/Views/Cars/Index.cshtml index 936c993a..2b9748e6 100644 --- a/CheckDrive.Web/CheckDrive.Web/Views/Cars/Index.cshtml +++ b/CheckDrive.Web/CheckDrive.Web/Views/Cars/Index.cshtml @@ -1,22 +1,30 @@ -@using CheckDrive.ApiContracts.Car -@model CheckDrive.ApiContracts.Car.CarDto +@using CheckDrive.Web.ViewModels.Car +@model CarViewModel @{ - ViewData["Title"] = "Index"; + ViewData["Title"] = "Cars"; Layout = "~/Views/Shared/_Layout.cshtml"; } +@section Styles { + +} + +@section Scripts { + +} +
-
-
+
+
- + @@ -31,7 +39,7 @@
@@ -49,11 +57,10 @@ - - - + + - + @@ -62,7 +69,7 @@