diff --git a/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs b/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs index 7122c6d..3127700 100644 --- a/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs +++ b/CaseAccounting/CaseAccountingContracts/SearchModels/UserSearchModel.cs @@ -9,5 +9,11 @@ namespace CaseAccountingContracts.SearchModels public class UserSearchModel { public int? Id { get; set; } - } + + public string? Login { get; set; } + + public string? Password { get; set; } + + public int? RoleId { get; set; } + } } diff --git a/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj b/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj index 60bf9ea..de3712e 100644 --- a/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj +++ b/CaseAccounting/CaseAccountingRestApi/CaseAccountingRestApi.csproj @@ -10,4 +10,10 @@ + + + + + + diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs new file mode 100644 index 0000000..e6b030d --- /dev/null +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/CaseController.cs @@ -0,0 +1,111 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace CaseAccountingRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CaseController : Controller + { + private readonly ICaseLogic _logic; + + public CaseController(ICaseLogic logic) + { + _logic = logic; + } + + [HttpGet] + public CaseViewModel? Get(int id) + { + try + { + return _logic.ReadElement(new CaseSearchModel { Id = id }); + } + catch (Exception) + { + throw; + } + } + + [HttpGet] + public List? GetAllByUser(int userId) + { + try + { + return _logic.ReadList(null); + } + catch (Exception) + { + throw; + } + } + + /*[HttpGet] + public List? GetMany(int userId, int page) + { + try + { + return _logic.ReadList(new CaseSearchModel { UserId = userId, PageNumber = page, PageSize = 10 }); + } + catch (Exception) + { + throw; + } + }*/ + + /*[HttpGet] + public int GetNumberOfPages(int userId) + { + try + { + return _studentLogic.GetNumberOfPages(userId); + } + catch (Exception ex) + { + throw; + } + }*/ + + [HttpPost] + public void Create(CaseBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Update(CaseBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Delete(CaseBindingModel model) + { + try + { + _logic.Delete(new() { Id = model.Id }); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs new file mode 100644 index 0000000..f9e8746 --- /dev/null +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/ContractController.cs @@ -0,0 +1,85 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace CaseAccountingRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ContractController : Controller + { + private readonly IContractLogic _logic; + + public ContractController(IContractLogic logic) + { + _logic = logic; + } + + [HttpGet] + public ContractViewModel? Get(int id) + { + try + { + return _logic.ReadElement(new ContractSearchModel { Id = id }); + } + catch (Exception) + { + throw; + } + } + + [HttpGet] + public List? GetAllByUser(int userId) + { + try + { + return _logic.ReadList(null); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Create(ContractBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Update(ContractBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Delete(ContractBindingModel model) + { + try + { + _logic.Delete(new() { Id = model.Id }); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs new file mode 100644 index 0000000..9e2a139 --- /dev/null +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/DealController.cs @@ -0,0 +1,85 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace CaseAccountingRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class DealController : Controller + { + private readonly IDealLogic _logic; + + public DealController(IDealLogic logic) + { + _logic = logic; + } + + [HttpGet] + public DealViewModel? Get(int id) + { + try + { + return _logic.ReadElement(new DealSearchModel { Id = id }); + } + catch (Exception) + { + throw; + } + } + + [HttpGet] + public List? GetAllByUser(int userId) + { + try + { + return _logic.ReadList(null); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Create(DealBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Update(DealBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Delete(DealBindingModel model) + { + try + { + _logic.Delete(new() { Id = model.Id }); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs new file mode 100644 index 0000000..0f7a93e --- /dev/null +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/UserController.cs @@ -0,0 +1,65 @@ +using CaseAccountingContracts.BindingModels; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.SearchModels; +using CaseAccountingContracts.ViewModels; +using CaseAccountingDataBaseImplement.Models; +using Microsoft.AspNetCore.Mvc; + +namespace CaseAccountingRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class UserController : Controller + { + private readonly IUserLogic _logic; + + public UserController(IUserLogic logic) + { + _logic = logic; + } + + [HttpGet] + public UserViewModel? Login(string login, string password, Role role) + { + try + { + return _logic.ReadElement(new UserSearchModel + { + Login = login, + Password = password, + //Role = role + }); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void Register(UserBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception) + { + throw; + } + } + + [HttpPost] + public void UpdateData(UserBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/WeatherForecastController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/WeatherForecastController.cs deleted file mode 100644 index 4427342..0000000 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace CaseAccountingRestApi.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingRestApi/Program.cs b/CaseAccounting/CaseAccountingRestApi/Program.cs index d7a851e..308b4d2 100644 --- a/CaseAccounting/CaseAccountingRestApi/Program.cs +++ b/CaseAccounting/CaseAccountingRestApi/Program.cs @@ -1,11 +1,42 @@ +using CaseAccountingBusinessLogic.BusinessLogics; +using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.StoragesContracts; +using CaseAccountingDataBaseImplement.Implements; +using Microsoft.OpenApi.Models; + var builder = WebApplication.CreateBuilder(args); +//builder.Logging.SetMinimumLevel(LogLevel.Trace); +//builder.Logging.AddLog4Net("log4net.config"); + // Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "CaseAccountingRestApi", + Version = "v1" + }); +}); var app = builder.Build(); @@ -13,7 +44,7 @@ var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CaseAccountingRestApi v1")); } app.UseHttpsRedirection(); diff --git a/CaseAccounting/CaseAccountingRestApi/WeatherForecast.cs b/CaseAccounting/CaseAccountingRestApi/WeatherForecast.cs deleted file mode 100644 index 831d89e..0000000 --- a/CaseAccounting/CaseAccountingRestApi/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CaseAccountingRestApi -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} \ No newline at end of file