diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/DoctorController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/DoctorController.cs new file mode 100644 index 0000000..5be904f --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Controllers/DoctorController.cs @@ -0,0 +1,64 @@ +using Microsoft.AspNetCore.Mvc; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.ViewModels; + +namespace VeterinaryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class DoctorController : Controller + { + private readonly ILogger _logger; + private readonly IDoctorLogic _logic; + public DoctorController(IDoctorLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + [HttpGet] + public DoctorViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new DoctorSearchModel + { + Login = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(DoctorBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(DoctorBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs new file mode 100644 index 0000000..31964eb --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Controllers/DrugController.cs @@ -0,0 +1,95 @@ +using Microsoft.AspNetCore.Mvc; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.ViewModels; + +namespace VeterinaryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class DrugController : Controller + { + private readonly ILogger _logger; + private readonly IDrugLogic _drug; + public DrugController(ILogger logger, IDrugLogic drug) + { + _logger = logger; + _drug = drug; + } + + [HttpGet] + public Tuple>>? GetDrug(int drugId) + { + try + { + var elem = _drug.ReadElement(new DrugSearchModel { Id = drugId }); + if (elem == null) + return null; + return Tuple.Create(elem, elem.DrugMedications.Select(x => Tuple.Create(x.Value.Item1.MedicationName, x.Value.Item2)).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения услуги по id={Id}", drugId); + throw; + } + } + [HttpGet] + public List GetDrugs(int purchaseId) + { + try + { + return _drug.ReadList(new DrugSearchModel { DoctorId = purchaseId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка услуг"); + throw; + } + } + [HttpPost] + public bool CreateDrug(DrugBindingModel model) + { + try + { + return _drug.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать услугу"); + throw; + } + } + + [HttpPost] + public bool UpdateDrug(DrugBindingModel model) + { + try + { + model.DrugMedications = null!; + return _drug.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить услугу"); + throw; + } + } + + [HttpPost] + public bool DeleteDrug(DrugBindingModel model) + { + try + { + return _drug.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления услуги"); + throw; + } + } + + + } +} diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs new file mode 100644 index 0000000..1c2e3df --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Controllers/MedicationController.cs @@ -0,0 +1,92 @@ +using Microsoft.AspNetCore.Mvc; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.ViewModels; + +namespace VeterinaryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MedicationController : Controller + { + private readonly ILogger _logger; + private readonly IMedicationLogic _medication; + public MedicationController(ILogger logger, IMedicationLogic medication) + { + _logger = logger; + _medication = medication; + } + // а нужен ли он нам вообще + [HttpGet] + public Tuple>? GetMedication(int medicationId) + { + try + { + var elem = _medication.ReadElement(new MedicationSearchModel { Id = medicationId }); + if (elem == null) + return null; + return Tuple.Create(elem, elem.MedicationAnimals.Select(x => x.Value.AnimalName).ToList()); // возврат модели медикамента и всех животных, у которых есть этот медикамент + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения медикамента по id={Id}", medicationId); + throw; + } + } + [HttpGet] + public List GetMedications(int doctorId) + { + try + { + return _medication.ReadList(new MedicationSearchModel { DoctorId = doctorId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка медикаментов"); + throw; + } + } + [HttpPost] + public bool CreateMedication(MedicationBindingModel model) + { + try + { + return _medication.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать медикамент"); + throw; + } + } + + [HttpPost] + public bool UpdateMedication(MedicationBindingModel model) + { + try + { + return _medication.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить магазин"); + throw; + } + } + + [HttpPost] + public bool DeleteMedication(MedicationBindingModel model) + { + try + { + return _medication.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + } +} diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs new file mode 100644 index 0000000..f9807ee --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Controllers/ServiceController.cs @@ -0,0 +1,95 @@ +using Microsoft.AspNetCore.Mvc; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.SearchModels; +using VeterinaryContracts.ViewModels; + +namespace VeterinaryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ServiceController : Controller + { + private readonly ILogger _logger; + private readonly IServiceLogic _service; + public ServiceController(ILogger logger, IServiceLogic service) + { + _logger = logger; + _service = service; + } + + [HttpGet] + public Tuple>>? GetService(int serviceId) + { + try + { + var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId }); + if (elem == null) + return null; + return Tuple.Create(elem, elem.ServiceMedications.Select(x => Tuple.Create(x.Value.Item1.MedicationName, x.Value.Item2)).ToList()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения услуги по id={Id}", serviceId); + throw; + } + } + [HttpGet] + public List GetServices(int doctorId) + { + try + { + return _service.ReadList(new ServiceSearchModel { DoctorId = doctorId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка услуг"); + throw; + } + } + [HttpPost] + public bool CreateService(ServiceBindingModel model) + { + try + { + return _service.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать услугу"); + throw; + } + } + + [HttpPost] + public bool UpdateService(ServiceBindingModel model) + { + try + { + model.ServiceMedications = null!; + return _service.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить услугу"); + throw; + } + } + + [HttpPost] + public bool DeleteService(ServiceBindingModel model) + { + try + { + return _service.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления услуги"); + throw; + } + } + + + } +} diff --git a/VeterinaryView/VeterinaryRestApi/Program.cs b/VeterinaryView/VeterinaryRestApi/Program.cs new file mode 100644 index 0000000..d7a851e --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/VeterinaryView/VeterinaryRestApi/Properties/launchSettings.json b/VeterinaryView/VeterinaryRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..aaba8a8 --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:43797", + "sslPort": 44312 + } + }, + "profiles": { + "VeterinaryRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7031;http://localhost:5156", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/VeterinaryView/VeterinaryRestApi/VeterinaryRestApi.csproj b/VeterinaryView/VeterinaryRestApi/VeterinaryRestApi.csproj new file mode 100644 index 0000000..f0ac1f1 --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/VeterinaryRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/VeterinaryView/VeterinaryRestApi/WeatherForecast.cs b/VeterinaryView/VeterinaryRestApi/WeatherForecast.cs new file mode 100644 index 0000000..4fb5494 --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace VeterinaryRestApi +{ + 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 diff --git a/VeterinaryView/VeterinaryRestApi/appsettings.Development.json b/VeterinaryView/VeterinaryRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/VeterinaryView/VeterinaryRestApi/appsettings.json b/VeterinaryView/VeterinaryRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateMedication.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateMedication.cshtml new file mode 100644 index 0000000..1347720 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/CreateMedication.cshtml @@ -0,0 +1,27 @@ +@{ + ViewData["Title"] = "CreateMedication"; +} + +
+

Создание медикамента

+
+
+
+
Название:
+
+ +
+
+
+
Цена:
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteMedication.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteMedication.cshtml new file mode 100644 index 0000000..5ce5ac0 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/DeleteMedication.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "DeleteMedication"; +} +
+

Удаление медикамента

+
+
+
+
Медикамент:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Enter.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..af951e7 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Enter.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "Enter"; +} +
+

Вход в приложение

+
+
+
+
Email:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Index.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Index.cshtml index d2d19bd..9ca8cd4 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Index.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Index.cshtml @@ -1,8 +1,56 @@ -@{ - ViewData["Title"] = "Home Page"; +@using VeterinaryContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Home Page"; } -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Медикаменты

+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать медикамент + Обновить медикамент + Удалить медикамент +

+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Название + + Цена +
+ @Html.DisplayFor(modelItem => + item.Id) + + @Html.DisplayFor(modelItem => + item.MedicationName) + + @Html.DisplayFor(modelItem => + item.Price) +
+ } +
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Privacy.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Privacy.cshtml index af4fb19..7dabde2 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Privacy.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Privacy.cshtml @@ -1,6 +1,28 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

+@using VeterinaryContracts.ViewModels -

Use this page to detail your site's privacy policy.

+@model DoctorViewModel + +@{ + ViewData["Title"] = "Privacy Policy"; +} +
+

Личные данные

+
+
+
+
Login:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Register.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..e340961 --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/Register.cshtml @@ -0,0 +1,28 @@ +@{ + ViewData["Title"] = "Register"; +} + +
+

Регистрация

+
+
+
+
Login:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml new file mode 100644 index 0000000..b389ecb --- /dev/null +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Home/UpdateMedication.cshtml @@ -0,0 +1,69 @@ +@using VetClinicContracts.ViewModels; + +@{ + ViewData["Title"] = "UpdateMedicine"; +} + +
+

Редактирование медикамента

+
+
+
+
Медикамент:
+
+ +
+
+ +
+
+
+
Название:
+
+
+
+
Цена:
+
+
+ + + + + + + + + +
+ Животное +
+
+
+
+
+
+ +@section Scripts +{ + +} \ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml b/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml index 4edd457..5b718f1 100644 --- a/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml +++ b/VeterinaryView/VeterinaryShowDoctorApp/Views/Shared/_Layout.cshtml @@ -20,10 +20,16 @@ diff --git a/VeterinaryView/VeterinaryView.sln b/VeterinaryView/VeterinaryView.sln index 6b77051..7aca40b 100644 --- a/VeterinaryView/VeterinaryView.sln +++ b/VeterinaryView/VeterinaryView.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VeterinaryShowOwnerApp", "V EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryShowDoctorApp", "VeterinaryShowDoctorApp\VeterinaryShowDoctorApp.csproj", "{98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryRestApi", "VeterinaryRestApi\VeterinaryRestApi.csproj", "{F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}.Debug|Any CPU.Build.0 = Debug|Any CPU {98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}.Release|Any CPU.ActiveCfg = Release|Any CPU {98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}.Release|Any CPU.Build.0 = Release|Any CPU + {F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE