ClientApp

This commit is contained in:
artiogf 2023-05-20 01:04:09 +04:00
parent 9d55f25bcc
commit bea9a1b241
44 changed files with 1969 additions and 70 deletions

View File

@ -0,0 +1,104 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.BusinessLogicsContracts;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.StoragesContracts;
using TourCompanyContracts.ViewModels;
namespace TourCompanyBusinessLogic.BusinessLogics
{
public class GidLogic : IGidLogic
{
private readonly ILogger _logger;
private readonly IGidStorage _gidStorage;
public GidLogic(ILogger<GidLogic> logger, IGidStorage gidStorage)
{
_logger = logger;
_gidStorage = gidStorage;
}
public List<GidViewModel>? ReadList(GidSearchModel? model)
{
_logger.LogInformation("ReadList. Id: { Id}", model?.Id);
var list = model == null ? _gidStorage.GetFullList() : _gidStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public GidViewModel? ReadElement(GidSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: { Id}", model.Id);
var element = _gidStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(GidBindingModel model)
{
CheckModel(model);
if (_gidStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(GidBindingModel model)
{
CheckModel(model);
if (_gidStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(GidBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_gidStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(GidBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Gid. Id: { Id}", model.Id);
var element = _gidStorage.GetElement(new GidSearchModel
{
GidFIO = model.GidFIO
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -12,7 +12,7 @@ using TourCompanyContracts.ViewModels;
namespace TourCompanyBusinessLogic.BusinessLogics
{
internal class PlaceVisitLogic : IPlaceVisitLogic
public class PlaceVisitLogic : IPlaceVisitLogic
{
private readonly ILogger _logger;
private readonly IPlaceVisitStorage _placeVisitStorage;

View File

@ -12,7 +12,7 @@ using TourCompanyContracts.ViewModels;
namespace TourCompanyBusinessLogic.BusinessLogics
{
internal class TourGroupLogic : ITourGroupLogic
public class TourGroupLogic : ITourGroupLogic
{
private readonly ILogger _logger;
private readonly ITourGroupStorage _tourGroupStorage;

View File

@ -0,0 +1,106 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.BusinessLogicsContracts;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.StoragesContracts;
using TourCompanyContracts.ViewModels;
namespace TourCompanyBusinessLogic.BusinessLogics
{
public class TripLogic : ITripLogic
{
private readonly ILogger _logger;
private readonly ITripStorage _tripStorage;
public TripLogic(ILogger<TripLogic> logger, ITripStorage tripStorage)
{
_logger = logger;
_tripStorage = tripStorage;
}
public List<TripViewModel>? ReadList(TripSearchModel? model)
{
_logger.LogInformation("ReadList. Id: { Id}", model?.Id);
var list = model == null ? _tripStorage.GetFullList() : _tripStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public TripViewModel? ReadElement(TripSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: { Id}", model.Id);
var element = _tripStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(TripBindingModel model)
{
CheckModel(model);
if (_tripStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(TripBindingModel model)
{
CheckModel(model);
if (_tripStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(TripBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_tripStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(TripBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Trip. GidId:{GidId}. Id: { Id}", model.GidId, model.Id);
var element = _tripStorage.GetElement(new TripSearchModel
{
GidId = model.GidId
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -7,43 +7,7 @@ namespace TourCompanyClientApp
{
public class APIClient
{
private static readonly HttpClient _client = new();
public static UserViewModel? User { get; set; } = null;
public static void Connect(IConfiguration configuration)
{
_client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public static T? GetRequest<T>(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<T>(result);
}
else
{
throw new Exception(result);
}
}
public static void PostRequest<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
}
}

View File

@ -7,6 +7,7 @@ using TourCompanyContracts.BusinessLogicsContracts;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.ViewModels;
using TourCompanyDatabaseImplement.Models;
using TourCompanyDataModels.Enums;
using TourCompanyDataModels.Models;
namespace TourCompanyClientApp.Controllers
@ -16,14 +17,25 @@ namespace TourCompanyClientApp.Controllers
private readonly ILogger<HomeController> _logger;
private readonly IExecurtionLogic _execurtion;
private readonly ITourGroupLogic _tourGroup;
private readonly ITourLogic _tour;
private readonly IUserLogic _user;
public HomeController(ILogger<HomeController> logger , IExecurtionLogic execurtion, ITourLogic tour)
private readonly IPlaceVisitLogic _placeVisitLogic;
private readonly IGidLogic _gid;
private readonly ITripLogic _trip;
public HomeController(ILogger<HomeController> logger , IExecurtionLogic execurtion, ITourLogic tour, IUserLogic user, ITourGroupLogic tourGroup, IPlaceVisitLogic placeVisitLogic, IGidLogic gid, ITripLogic trip)
{
_logger = logger;
_execurtion = execurtion;
_tour = tour;
_user = user;
_tourGroup = tourGroup;
_placeVisitLogic = placeVisitLogic;
_gid = gid;
_trip = trip;
}
[HttpGet]
@ -37,7 +49,7 @@ namespace TourCompanyClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<TourViewModel>>($"api/tour/gettours?userId={APIClient.User.Id}"));
return View(_tour.ReadList(new TourSearchModel { UserId = APIClient.User.Id}));
}
[HttpGet]
@ -61,9 +73,8 @@ namespace TourCompanyClientApp.Controllers
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/user/updatedata", new UserBindingModel
_user.Update(new UserBindingModel
{
Id = APIClient.User.Id,
UserFIO = fio,
Email = login,
Password = password
@ -94,7 +105,7 @@ namespace TourCompanyClientApp.Controllers
{
throw new Exception("Введите логин и пароль");
}
APIClient.User = APIClient.GetRequest<UserViewModel>($"api/user/login?login={login}&password={password}");
APIClient.User = _user.ReadElement(new UserSearchModel { Email = login, Password = password });
if (APIClient.User == null)
{
throw new Exception("Неверный логин/пароль");
@ -115,7 +126,7 @@ namespace TourCompanyClientApp.Controllers
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/user/register", new UserBindingModel
_user.Create(new UserBindingModel
{
UserFIO = fio,
Email = login,
@ -136,7 +147,7 @@ namespace TourCompanyClientApp.Controllers
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/tour/createtour", new TourBindingModel
_tour.Create(new TourBindingModel
{
UserId = APIClient.User.Id,
TourName = tourName,
@ -151,7 +162,7 @@ namespace TourCompanyClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<ExecurtionViewModel>>($"api/execurtion/getexecurtions"));
return View(_execurtion.ReadList(null));
}
[HttpGet]
public IActionResult CreateExecurtion()
@ -183,5 +194,176 @@ namespace TourCompanyClientApp.Controllers
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult TourGroup()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(_tourGroup.ReadList(null));
}
[HttpGet]
public IActionResult CreateTourGroup()
{
var list = _tour.ReadList(new TourSearchModel { UserId = APIClient.User.Id });
var simpTour = list.Select(x => new { TourId = x.Id, TourName = x.TourName });
ViewBag.Tours = new MultiSelectList(simpTour, "TourId", "TourName");
return View();
}
[HttpPost]
public void CreateTourGroup(string tourGroupName, int typekey, int[] tours)
{
if (APIClient.User == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
Dictionary<int, ITourModel> tourGroupTours = new Dictionary<int, ITourModel>();
foreach (int id in tours)
{
tourGroupTours.Add(id, _tour.ReadElement(new TourSearchModel { Id = id }));
}
TourType type = TourType.Гражданский;
if(typekey == 1)
{
type = TourType.Гражданский;
}
else if (typekey == 0)
{
type = TourType.Учебный;
}
_tourGroup.Create(new TourGroupBindingModel
{
TourGroupName = tourGroupName,
Type = type,
TourGroupTours = tourGroupTours
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult PlaceVisit()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(_placeVisitLogic.ReadList(null));
}
[HttpGet]
public IActionResult CreatePlaceVisit()
{
ViewBag.TourGroups = _tourGroup.ReadList(null);
var list = _trip.ReadList(null);
var simpTrip = list.Select(x => new { TripId = x.Id, TripName = x.TripName});
ViewBag.Trips = new MultiSelectList(simpTrip, "TripId", "TripName");
return View();
}
[HttpPost]
public void CreatePlaceVisit(int tourGroup, string placeVisitName, DateTime datePlaceVisit, int[] trips)
{
var prod = _tourGroup.ReadElement(new TourGroupSearchModel { Id = tourGroup });
if (APIClient.User == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
Dictionary<int, ITripModel> placeVisitTrips = new Dictionary<int, ITripModel>();
foreach (int id in trips)
{
placeVisitTrips.Add(id, _trip.ReadElement(new TripSearchModel { Id = id }));
}
_placeVisitLogic.Create(new PlaceVisitBindingModel
{
PlaceVisitName = placeVisitName,
DatePlaceVisit = datePlaceVisit,
TourGroupId = tourGroup,
TourGroupName = prod.TourGroupName,
PlaceVisitTrips = placeVisitTrips
});
Response.Redirect("Index");
}
/// <summary>
/// Gid
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Gid()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(_gid.ReadList(null));
}
[HttpGet]
public IActionResult CreateGid()
{
var list = _execurtion.ReadList(null);
var simpExecurtion = list.Select(x => new { ExecurtionId = x.Id, Purpose = x.Purpose });
ViewBag.Execurtions = new MultiSelectList(simpExecurtion, "ExecurtionId", "Purpose");
return View();
}
[HttpPost]
public void CreateGid(int experion, string GidFio, int[] execurtions)
{
if (APIClient.User == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
Dictionary<int, IExecurtionModel> gidExecurtions = new Dictionary<int, IExecurtionModel>();
foreach (int id in execurtions)
{
gidExecurtions.Add(id, _execurtion.ReadElement(new ExecurtionSearchModel { Id = id }));
}
_gid.Create(new GidBindingModel
{
Experion = experion,
GidFIO = GidFio,
GidExecurtions = gidExecurtions
});
Response.Redirect("Index");
}
/// <summary>
/// Trip
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Trip()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(_trip.ReadList(null));
}
[HttpGet]
public IActionResult CreateTrip()
{
ViewBag.Gids = _gid.ReadList(null);
return View();
}
[HttpPost]
public void CreateTrip(int gid, string tripName, DateTime dateTrip)
{
var prod = _gid.ReadElement(new GidSearchModel { Id = gid });
if (APIClient.User == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
_trip.Create(new TripBindingModel
{
TripName = tripName,
DateTrip = dateTrip,
GidId = gid,
GidFIO = prod.GidFIO
});
Response.Redirect("Index");
}
}
}

View File

@ -3,24 +3,33 @@ using TourCompanyClientApp;
using TourCompanyContracts.BusinessLogicsContracts;
using TourCompanyContracts.StoragesContracts;
using TourCompanyDatabaseImplement.Implements;
using TourCompanyDatabaseImplement.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<ITourStorage, TourStorage>();
builder.Services.AddTransient<IExecurtionStorage, ExecurtionStorage>();
builder.Services.AddTransient<ITourGroupStorage, TourGroupStorage>();
builder.Services.AddTransient<IPlaceVisitStorage, PlaceVisitStorage>();
builder.Services.AddTransient<IGidStorage, GidStorage>();
builder.Services.AddTransient<ITripStorage, TripStorage>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<ITourLogic, TourLogic>();
builder.Services.AddTransient<IExecurtionLogic, ExecurtionLogic>();
builder.Services.AddTransient<ITourGroupLogic, TourGroupLogic>();
builder.Services.AddTransient<IPlaceVisitLogic, PlaceVisitLogic>();
builder.Services.AddTransient<IGidLogic, GidLogic>();
builder.Services.AddTransient<ITripLogic,TripLogic>();
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();

View File

@ -0,0 +1,26 @@
@{
ViewData["Title"] = "CreateGid";
}
<div class="text-center">
<h2 class="display-4">Создание Гида</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Опыт:</div>
<div class="col-8"><input type="number" name="experion" /></div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="GidFio" /></div>
</div>
<div class="row">
<div class="col-4">экускурсии:</div>
<div class="col-8">
@Html.ListBox("execurtions", (MultiSelectList)ViewBag.Execurtions)
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,32 @@
@{
ViewData["Title"] = "CreatePlaceVisit";
}
<div class="text-center">
<h2 class="display-4">Создание мест посещения</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Тур Группа:</div>
<div class="col-8">
<select id="tourGroup" name="tourGroup" class="form-control" asp-items="@(new SelectList(@ViewBag.TourGroups,"Id", "TourGroupName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Место посещения:</div>
<div class="col-8"><input type="text" name="placeVisitName" id="placeVisitName" /></div>
</div>
<div class="row">
<div class="col-4">Дата посещения:</div>
<div class="col-8"><input type="datetime-local" id="datePlaceVisit" name="datePlaceVisit" /></div>
</div>
<div class="row">
<div class="col-4">поездки:</div>
<div class="col-8">
@Html.ListBox("trips", (MultiSelectList)ViewBag.Trips)
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,26 @@
@{
ViewData["Title"] = "CreateTourGroup";
}
<div class="text-center">
<h2 class="display-4">Создание тур группы</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Название группы:</div>
<div class="col-8"><input type="text" name="tourGroupName" /></div>
</div>
<div class="row">
<div class="col-4">Тип группы:</div>
<div class="col-8"><input type="number" name="type" min="0" max="1"/></div>
</div>
<div class="row">
<div class="col-4">туры:</div>
<div class="col-8">
@Html.ListBox("tours", (MultiSelectList)ViewBag.Tours)
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,26 @@
@{
ViewData["Title"] = "CreateTrip";
}
<div class="text-center">
<h2 class="display-4">Создание Поездки</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Гид:</div>
<div class="col-8">
<select id="gid" name="gid" class="form-control" asp-items="@(new SelectList(@ViewBag.Gids,"Id", "GidFIO"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Место посещения:</div>
<div class="col-8"><input type="text" name="tripName" id="tripName" /></div>
</div>
<div class="row">
<div class="col-4">Дата посещения:</div>
<div class="col-8"><input type="datetime-local" id="dateTrip" name="dateTrip" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,66 @@
@using TourCompanyContracts.ViewModels
@model List<GidViewModel>
@{
ViewData["Title"] = "Gid";
}
<div class="text-center">
<h1 class="display-4">Гиды</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateGid">Создать Гида</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Цель экскурсии
</th>
<th>
Дата экскурсии
</th>
<th>
длительность экскурсии
</th>
<th>
Туры
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Experion)
</td>
<td>
@Html.DisplayFor(modelItem => item.GidFIO)
</td>
<td>
<select asp-items="@(new SelectList(item.GidExecurtions,"Key", "Value.Purpose"))"></select>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,70 @@
@using TourCompanyContracts.ViewModels
@model List<PlaceVisitViewModel>
@{
ViewData["Title"] = "PlaceVisit";
}
<div class="text-center">
<h1 class="display-4">Места посещения</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreatePlaceVisit">Создать Места посещения</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Место посещения
</th>
<th>
Дата посещения
</th>
<th>
Тур Группа
</th>
<th>
Поездка
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.PlaceVisitName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DatePlaceVisit)
</td>
<td>
@Html.DisplayFor(modelItem => item.TourGroupName)
</td>
<td>
<select asp-items="@(new SelectList(item.PlaceVisitTrips,"Key", "Value.TripName"))"></select>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,64 @@
@using TourCompanyContracts.ViewModels
@model List<TourGroupViewModel>
@{
ViewData["Title"] = "TourGroup";
}
<div class="text-center">
<h1 class="display-4">Тур группа</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateTourGroup">Создать Тур группу</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название тур группы
</th>
<th>
Дата экскурсии
</th>
<th>
Туры
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.TourGroupName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
<select asp-items="@(new SelectList(item.TourGroupTours,"Key", "Value.TourName"))"></select>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,60 @@
@using TourCompanyContracts.ViewModels
@model List<TripViewModel>
@{
ViewData["Title"] = "Trip";
}
<div class="text-center">
<h1 class="display-4">Поездка</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateTrip">Создать поездку</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Поездка
</th>
<th>
Дата Поездки
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.TripName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateTrip)
</td>
<td>
@Html.DisplayFor(modelItem => item.GidFIO)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -31,6 +31,18 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Execurtion">Экскурсия</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TourGroup">ТурГруппа</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="PlaceVisit">PlaceVisit</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Gid">Gid</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Trip">Trip</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyDataModels.Models;
namespace TourCompanyContracts.BindingModels
{
public class GidBindingModel : IGidModel
{
public int Id { get; set; }
public string GidFIO { get; set; } = string.Empty;
public int Experion { get; set; }
public Dictionary<int, IExecurtionModel> GidExecurtions { get; set; } = new();
}
}

View File

@ -19,5 +19,6 @@ namespace TourCompanyContracts.BindingModels
public int TourGroupId { get; set; }
public string TourGroupName { get; set; } = string.Empty;
}
public Dictionary<int, ITripModel> PlaceVisitTrips { get; set; } = new();
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyDataModels.Models;
namespace TourCompanyContracts.BindingModels
{
public class TripBindingModel : ITripModel
{
public int Id { get; set; }
public string TripName { get; set; }
public DateTime DateTrip { get; set; }
public int GidId { get; set; }
public string GidFIO { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.ViewModels;
namespace TourCompanyContracts.BusinessLogicsContracts
{
public interface IGidLogic
{
List<GidViewModel>? ReadList(GidSearchModel? model);
GidViewModel? ReadElement(GidSearchModel model);
bool Create(GidBindingModel model);
bool Update(GidBindingModel model);
bool Delete(GidBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.ViewModels;
namespace TourCompanyContracts.BusinessLogicsContracts
{
public interface ITripLogic
{
List<TripViewModel>? ReadList(TripSearchModel? model);
TripViewModel? ReadElement(TripSearchModel model);
bool Create(TripBindingModel model);
bool Update(TripBindingModel model);
bool Delete(TripBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TourCompanyContracts.SearchModels
{
public class GidSearchModel
{
public int? Id { get; set; }
public string? GidFIO { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TourCompanyContracts.SearchModels
{
public class TripSearchModel
{
public int? Id { get; set; }
public int? GidId { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.ViewModels;
namespace TourCompanyContracts.StoragesContracts
{
public interface IGidStorage
{
List<GidViewModel> GetFullList();
List<GidViewModel> GetFilteredList(GidSearchModel model);
GidViewModel? GetElement(GidSearchModel model);
GidViewModel? Insert(GidBindingModel model);
GidViewModel? Update(GidBindingModel model);
GidViewModel? Delete(GidBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.ViewModels;
namespace TourCompanyContracts.StoragesContracts
{
public interface ITripStorage
{
List<TripViewModel> GetFullList();
List<TripViewModel> GetFilteredList(TripSearchModel model);
TripViewModel? GetElement(TripSearchModel model);
TripViewModel? Insert(TripBindingModel model);
TripViewModel? Update(TripBindingModel model);
TripViewModel? Delete(TripBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyDataModels.Models;
namespace TourCompanyContracts.ViewModels
{
public class GidViewModel : IGidModel
{
public int Id { get; set; }
public string GidFIO { get; set; } = string.Empty;
public int Experion { get; set; }
public Dictionary<int, IExecurtionModel> GidExecurtions { get; set; } = new();
}
}

View File

@ -19,5 +19,6 @@ namespace TourCompanyContracts.ViewModels
public int TourGroupId { get; set; }
public string TourGroupName { get; set; } = string.Empty;
}
public Dictionary<int, ITripModel> PlaceVisitTrips { get; set; } = new();
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyDataModels.Models;
namespace TourCompanyContracts.ViewModels
{
public class TripViewModel : ITripModel
{
public int Id { get; set; }
public string TripName { get; set; }
public DateTime DateTrip { get; set; }
public int GidId { get; set; }
public string GidFIO { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace TourCompanyDataModels.Models
{
public interface IGidModel : IId
{
public string GidFIO { get;}
public int Experion { get;}
public Dictionary<int, IExecurtionModel> GidExecurtions { get; }
}
}

View File

@ -17,6 +17,7 @@ namespace TourCompanyDataModels.Models
public int TourGroupId { get; }
public string TourGroupName { get; }
}
public string TourGroupName { get; }
public Dictionary<int, ITripModel> PlaceVisitTrips { get; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace TourCompanyDataModels.Models
{
public interface ITripModel : IId
{
public string TripName { get; }
public DateTime DateTrip { get; }
public int GidId { get; }
public string GidFIO { get; }
}
}

View File

@ -0,0 +1,110 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.StoragesContracts;
using TourCompanyContracts.ViewModels;
using TourCompanyDatabaseImplement.Models;
namespace TourCompanyDatabaseImplement.Implements
{
public class GidStorage : IGidStorage
{
public List<GidViewModel> GetFullList()
{
using var context = new TourCompanyDatabase();
return context.Gids
.Include(x => x.Execurtions)
.ThenInclude(x => x.Execurtion)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<GidViewModel> GetFilteredList(GidSearchModel model)
{
if (string.IsNullOrEmpty(model.GidFIO))
{
return new();
}
using var context = new TourCompanyDatabase();
return context.Gids
.Include(x => x.Execurtions)
.ThenInclude(x => x.Execurtion)
.Where(x => x.GidFIO.Contains(model.GidFIO))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public GidViewModel? GetElement(GidSearchModel model)
{
if (string.IsNullOrEmpty(model.GidFIO) && !model.Id.HasValue)
{
return null;
}
using var context = new TourCompanyDatabase();
return context.Gids
.Include(x => x.Execurtions)
.ThenInclude(x => x.Execurtion)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.GidFIO) && x.GidFIO == model.GidFIO) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public GidViewModel? Insert(GidBindingModel model)
{
using var context = new TourCompanyDatabase();
var newGid = Gid.Create(context, model);
if (newGid == null)
{
return null;
}
context.Gids.Add(newGid);
context.SaveChanges();
return newGid.GetViewModel;
}
public GidViewModel? Update(GidBindingModel model)
{
using var context = new TourCompanyDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var execurtion = context.Gids.FirstOrDefault(rec => rec.Id == model.Id);
if (execurtion == null)
{
return null;
}
execurtion.Update(model);
context.SaveChanges();
execurtion.UpdateExecurtions(context, model);
transaction.Commit();
return execurtion.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public GidViewModel? Delete(GidBindingModel model)
{
using var context = new TourCompanyDatabase();
var element = context.Gids
.Include(x => x.Execurtions)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Gids.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -70,8 +70,10 @@ namespace TourCompanyDatabaseImplement.Implements
}
return queryWhere
.Include(x => x.TourGroup)
.Select(x => x.GetViewModel)
.Include(x => x.Trips)
.ThenInclude(x => x.Trip)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
@ -80,21 +82,23 @@ namespace TourCompanyDatabaseImplement.Implements
using var context = new TourCompanyDatabase();
return context.PlaceVisits
.Include(x => x.TourGroup)
.Select(x => x.GetViewModel).ToList();
.Include(x => x.Trips)
.ThenInclude(x => x.Trip)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public PlaceVisitViewModel? Insert(PlaceVisitBindingModel model)
{
var newPlaceVisit = PlaceVisit.Create(model);
using var context = new TourCompanyDatabase();
var newPlaceVisit = PlaceVisit.Create(context, model);
if (newPlaceVisit == null)
{
return null;
}
using var context = new TourCompanyDatabase();
context.PlaceVisits.Add(newPlaceVisit);
context.SaveChanges();

View File

@ -0,0 +1,125 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.SearchModels;
using TourCompanyContracts.StoragesContracts;
using TourCompanyContracts.ViewModels;
using TourCompanyDatabaseImplement.Models;
namespace TourCompanyDatabaseImplement.Implements
{
public class TripStorage : ITripStorage
{
public TripViewModel? Delete(TripBindingModel model)
{
using var context = new TourCompanyDatabase();
var element = context.Trips
.Include(x => x.Gid)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Trips.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public TripViewModel? GetElement(TripSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new TourCompanyDatabase();
return context.Trips
.Include(x => x.Gid)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public List<TripViewModel> GetFilteredList(TripSearchModel model)
{
if (model.Id.HasValue)
{
var result = GetElement(model);
return result != null ? new() { result } : new();
}
using var context = new TourCompanyDatabase();
IQueryable<Trip>? queryWhere = null;
if (model.GidId.HasValue)
{
queryWhere = context.Trips.Where(x => x.GidId == model.GidId);
}
else
{
return new();
}
return queryWhere
.Include(x => x.Gid)
.Select(x => x.GetViewModel)
.ToList();
}
public List<TripViewModel> GetFullList()
{
using var context = new TourCompanyDatabase();
return context.Trips
.Include(x => x.Gid)
.Select(x => x.GetViewModel).ToList();
}
public TripViewModel? Insert(TripBindingModel model)
{
var newTrip = Trip.Create(model);
if (newTrip == null)
{
return null;
}
using var context = new TourCompanyDatabase();
context.Trips.Add(newTrip);
context.SaveChanges();
return context.Trips
.Include(x => x.Gid)
.FirstOrDefault(x => x.Id == newTrip.Id)
?.GetViewModel;
}
public TripViewModel? Update(TripBindingModel model)
{
using var context = new TourCompanyDatabase();
var trip = context.Trips
.Include(x => x.Gid)
.FirstOrDefault(x => x.Id == model.Id);
if (trip == null)
{
return null;
}
trip.Update(model);
context.SaveChanges();
return trip.GetViewModel;
}
}
}

View File

@ -12,7 +12,7 @@ using TourCompanyDatabaseImplement;
namespace TourCompanyDatabaseImplement.Migrations
{
[DbContext(typeof(TourCompanyDatabase))]
[Migration("20230519192042_InitialCreate")]
[Migration("20230519231349_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -71,6 +71,52 @@ namespace TourCompanyDatabaseImplement.Migrations
b.ToTable("ExecurtionTours");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Gid", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Experion")
.HasColumnType("int");
b.Property<string>("GidFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Gids");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.GidExecurtion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExecurtionId")
.HasColumnType("int");
b.Property<int>("GidId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecurtionId");
b.HasIndex("GidId");
b.ToTable("GidExecurtions");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisit", b =>
{
b.Property<int>("Id")
@ -100,6 +146,29 @@ namespace TourCompanyDatabaseImplement.Migrations
b.ToTable("PlaceVisits");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisitTrip", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PlaceVisitId")
.HasColumnType("int");
b.Property<int>("TripId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PlaceVisitId");
b.HasIndex("TripId");
b.ToTable("PlaceVisitTrips");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Tour", b =>
{
b.Property<int>("Id")
@ -168,6 +237,35 @@ namespace TourCompanyDatabaseImplement.Migrations
b.ToTable("TourGroupTours");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Trip", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateTrip")
.HasColumnType("datetime2");
b.Property<string>("GidFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("GidId")
.HasColumnType("int");
b.Property<string>("TripName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GidId");
b.ToTable("Trips");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
@ -212,6 +310,25 @@ namespace TourCompanyDatabaseImplement.Migrations
b.Navigation("Tour");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.GidExecurtion", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.Execurtion", "Execurtion")
.WithMany()
.HasForeignKey("ExecurtionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TourCompanyDatabaseImplement.Models.Gid", "Gid")
.WithMany("Execurtions")
.HasForeignKey("GidId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Execurtion");
b.Navigation("Gid");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisit", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.TourGroup", "TourGroup")
@ -223,6 +340,25 @@ namespace TourCompanyDatabaseImplement.Migrations
b.Navigation("TourGroup");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisitTrip", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.PlaceVisit", "PlaceVisit")
.WithMany("Trips")
.HasForeignKey("PlaceVisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TourCompanyDatabaseImplement.Models.Trip", "Trip")
.WithMany()
.HasForeignKey("TripId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlaceVisit");
b.Navigation("Trip");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Tour", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.User", "User")
@ -253,11 +389,32 @@ namespace TourCompanyDatabaseImplement.Migrations
b.Navigation("TourGroup");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Trip", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.Gid", "Gid")
.WithMany()
.HasForeignKey("GidId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Gid");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Execurtion", b =>
{
b.Navigation("Tours");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Gid", b =>
{
b.Navigation("Execurtions");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisit", b =>
{
b.Navigation("Trips");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.TourGroup", b =>
{
b.Navigation("Tours");

View File

@ -26,6 +26,21 @@ namespace TourCompanyDatabaseImplement.Migrations
table.PrimaryKey("PK_Execurtions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Gids",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
GidFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Experion = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Gids", x => x.Id);
});
migrationBuilder.CreateTable(
name: "TourGroups",
columns: table => new
@ -55,6 +70,54 @@ namespace TourCompanyDatabaseImplement.Migrations
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "GidExecurtions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ExecurtionId = table.Column<int>(type: "int", nullable: false),
GidId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GidExecurtions", x => x.Id);
table.ForeignKey(
name: "FK_GidExecurtions_Execurtions_ExecurtionId",
column: x => x.ExecurtionId,
principalTable: "Execurtions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GidExecurtions_Gids_GidId",
column: x => x.GidId,
principalTable: "Gids",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Trips",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TripName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateTrip = table.Column<DateTime>(type: "datetime2", nullable: false),
GidId = table.Column<int>(type: "int", nullable: false),
GidFIO = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Trips", x => x.Id);
table.ForeignKey(
name: "FK_Trips_Gids_GidId",
column: x => x.GidId,
principalTable: "Gids",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlaceVisits",
columns: table => new
@ -98,6 +161,32 @@ namespace TourCompanyDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PlaceVisitTrips",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlaceVisitId = table.Column<int>(type: "int", nullable: false),
TripId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PlaceVisitTrips", x => x.Id);
table.ForeignKey(
name: "FK_PlaceVisitTrips_PlaceVisits_PlaceVisitId",
column: x => x.PlaceVisitId,
principalTable: "PlaceVisits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PlaceVisitTrips_Trips_TripId",
column: x => x.TripId,
principalTable: "Trips",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ExecurtionTours",
columns: table => new
@ -160,11 +249,31 @@ namespace TourCompanyDatabaseImplement.Migrations
table: "ExecurtionTours",
column: "TourId");
migrationBuilder.CreateIndex(
name: "IX_GidExecurtions_ExecurtionId",
table: "GidExecurtions",
column: "ExecurtionId");
migrationBuilder.CreateIndex(
name: "IX_GidExecurtions_GidId",
table: "GidExecurtions",
column: "GidId");
migrationBuilder.CreateIndex(
name: "IX_PlaceVisits_TourGroupId",
table: "PlaceVisits",
column: "TourGroupId");
migrationBuilder.CreateIndex(
name: "IX_PlaceVisitTrips_PlaceVisitId",
table: "PlaceVisitTrips",
column: "PlaceVisitId");
migrationBuilder.CreateIndex(
name: "IX_PlaceVisitTrips_TripId",
table: "PlaceVisitTrips",
column: "TripId");
migrationBuilder.CreateIndex(
name: "IX_TourGroupTours_TourGroupId",
table: "TourGroupTours",
@ -179,6 +288,11 @@ namespace TourCompanyDatabaseImplement.Migrations
name: "IX_Tours_UserId",
table: "Tours",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Trips_GidId",
table: "Trips",
column: "GidId");
}
/// <inheritdoc />
@ -188,7 +302,10 @@ namespace TourCompanyDatabaseImplement.Migrations
name: "ExecurtionTours");
migrationBuilder.DropTable(
name: "PlaceVisits");
name: "GidExecurtions");
migrationBuilder.DropTable(
name: "PlaceVisitTrips");
migrationBuilder.DropTable(
name: "TourGroupTours");
@ -197,11 +314,20 @@ namespace TourCompanyDatabaseImplement.Migrations
name: "Execurtions");
migrationBuilder.DropTable(
name: "TourGroups");
name: "PlaceVisits");
migrationBuilder.DropTable(
name: "Trips");
migrationBuilder.DropTable(
name: "Tours");
migrationBuilder.DropTable(
name: "TourGroups");
migrationBuilder.DropTable(
name: "Gids");
migrationBuilder.DropTable(
name: "Users");
}

View File

@ -68,6 +68,52 @@ namespace TourCompanyDatabaseImplement.Migrations
b.ToTable("ExecurtionTours");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Gid", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Experion")
.HasColumnType("int");
b.Property<string>("GidFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Gids");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.GidExecurtion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExecurtionId")
.HasColumnType("int");
b.Property<int>("GidId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecurtionId");
b.HasIndex("GidId");
b.ToTable("GidExecurtions");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisit", b =>
{
b.Property<int>("Id")
@ -97,6 +143,29 @@ namespace TourCompanyDatabaseImplement.Migrations
b.ToTable("PlaceVisits");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisitTrip", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PlaceVisitId")
.HasColumnType("int");
b.Property<int>("TripId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PlaceVisitId");
b.HasIndex("TripId");
b.ToTable("PlaceVisitTrips");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Tour", b =>
{
b.Property<int>("Id")
@ -165,6 +234,35 @@ namespace TourCompanyDatabaseImplement.Migrations
b.ToTable("TourGroupTours");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Trip", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateTrip")
.HasColumnType("datetime2");
b.Property<string>("GidFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("GidId")
.HasColumnType("int");
b.Property<string>("TripName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("GidId");
b.ToTable("Trips");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.User", b =>
{
b.Property<int>("Id")
@ -209,6 +307,25 @@ namespace TourCompanyDatabaseImplement.Migrations
b.Navigation("Tour");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.GidExecurtion", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.Execurtion", "Execurtion")
.WithMany()
.HasForeignKey("ExecurtionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TourCompanyDatabaseImplement.Models.Gid", "Gid")
.WithMany("Execurtions")
.HasForeignKey("GidId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Execurtion");
b.Navigation("Gid");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisit", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.TourGroup", "TourGroup")
@ -220,6 +337,25 @@ namespace TourCompanyDatabaseImplement.Migrations
b.Navigation("TourGroup");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisitTrip", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.PlaceVisit", "PlaceVisit")
.WithMany("Trips")
.HasForeignKey("PlaceVisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TourCompanyDatabaseImplement.Models.Trip", "Trip")
.WithMany()
.HasForeignKey("TripId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PlaceVisit");
b.Navigation("Trip");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Tour", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.User", "User")
@ -250,11 +386,32 @@ namespace TourCompanyDatabaseImplement.Migrations
b.Navigation("TourGroup");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Trip", b =>
{
b.HasOne("TourCompanyDatabaseImplement.Models.Gid", "Gid")
.WithMany()
.HasForeignKey("GidId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Gid");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Execurtion", b =>
{
b.Navigation("Tours");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.Gid", b =>
{
b.Navigation("Execurtions");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.PlaceVisit", b =>
{
b.Navigation("Trips");
});
modelBuilder.Entity("TourCompanyDatabaseImplement.Models.TourGroup", b =>
{
b.Navigation("Tours");

View File

@ -0,0 +1,96 @@
using TourCompanyDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.ViewModels;
using TourCompanyDataModels.Models;
namespace TourCompanyDatabaseImplement.Models
{
public class Gid : IGidModel
{
public int Id { get; set; }
public string GidFIO { get; set; } = string.Empty;
public int Experion { get; set; }
public int UserId { get; set; }
public Dictionary<int, IExecurtionModel>? _gidExecurtions = null;
public virtual List<GidExecurtion> Execurtions { get; set; } = new();
public Dictionary<int, IExecurtionModel> GidExecurtions
{
get
{
if (_gidExecurtions == null)
{
_gidExecurtions = Execurtions
.ToDictionary(recPC => recPC.ExecurtionId, recPC => (recPC.Execurtion as IExecurtionModel));
}
return _gidExecurtions;
}
}
public static Gid Create(TourCompanyDatabase context, GidBindingModel model)
{
return new Gid()
{
Id = model.Id,
GidFIO = model.GidFIO,
Experion = model.Experion,
Execurtions = model.GidExecurtions.Select(x => new GidExecurtion
{
Execurtion = context.Execurtions.First(y => y.Id == x.Key),
}).ToList()
};
}
public void Update(GidBindingModel model)
{
GidFIO = model.GidFIO;
Experion = model.Experion;
}
public GidViewModel GetViewModel
{
get
{
using var context = new TourCompanyDatabase();
return new GidViewModel
{
Id = Id,
GidFIO = GidFIO,
Experion = Experion,
GidExecurtions = GidExecurtions
};
}
}
public void UpdateExecurtions(TourCompanyDatabase context, GidBindingModel model)
{
var gidExecurtions = context.GidExecurtions.Where(rec => rec.GidId == model.Id).ToList();
if (gidExecurtions != null)
{ // удалили те, которых нет в модели
context.GidExecurtions.RemoveRange(gidExecurtions.Where(rec => !model.GidExecurtions.ContainsKey(rec.ExecurtionId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var UpdateExecurtion in gidExecurtions)
{
model.GidExecurtions.Remove(UpdateExecurtion.Id);
}
context.SaveChanges();
}
var gid = context.Gids.First(x => x.Id == Id);
foreach (var pc in model.GidExecurtions)
{
context.GidExecurtions.Add(new GidExecurtion
{
Gid = gid,
Execurtion = context.Execurtions.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_gidExecurtions = null;
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TourCompanyDatabaseImplement.Models
{
public class GidExecurtion
{
public int Id { get; set; }
[Required]
public int ExecurtionId { get; set; }
[Required]
public int GidId { get; set; }
public virtual Execurtion Execurtion { get; set; } = new();
public virtual Gid Gid { get; set; } = new();
}
}

View File

@ -22,7 +22,22 @@ namespace TourCompanyDatabaseImplement.Models
public string TourGroupName { get; set; }
public TourGroup TourGroup { get; set; }
public static PlaceVisit? Create(PlaceVisitBindingModel? model)
public Dictionary<int, ITripModel>? _placeVisitTrips = null;
public virtual List<PlaceVisitTrip> Trips { get; set; } = new();
public Dictionary<int, ITripModel> PlaceVisitTrips
{
get
{
if (_placeVisitTrips == null)
{
_placeVisitTrips = Trips
.ToDictionary(recPC => recPC.TripId, recPC => recPC.Trip as ITripModel);
}
return _placeVisitTrips;
}
}
public static PlaceVisit? Create(TourCompanyDatabase context, PlaceVisitBindingModel? model)
{
return new PlaceVisit()
{
@ -30,8 +45,12 @@ namespace TourCompanyDatabaseImplement.Models
PlaceVisitName = model.PlaceVisitName,
DatePlaceVisit = model.DatePlaceVisit,
TourGroupId = model.TourGroupId,
TourGroupName = model.TourGroupName
};
TourGroupName = model.TourGroupName,
Trips = model.PlaceVisitTrips.Select(x => new PlaceVisitTrip
{
Trip = context.Trips.First(y => y.Id == x.Key)
}).ToList()
};
}
public void Update(PlaceVisitBindingModel model)
{
@ -49,9 +68,36 @@ namespace TourCompanyDatabaseImplement.Models
PlaceVisitName = PlaceVisitName,
DatePlaceVisit = DatePlaceVisit,
TourGroupId = TourGroupId,
TourGroupName = context.TourGroups.FirstOrDefault(x => x.Id == TourGroupId)?.TourGroupName ?? string.Empty
TourGroupName = context.TourGroups.FirstOrDefault(x => x.Id == TourGroupId)?.TourGroupName ?? string.Empty,
PlaceVisitTrips = PlaceVisitTrips
};
}
}
public void UpdateTrips(TourCompanyDatabase context, PlaceVisitBindingModel model)
{
var placeVisitTrips = context.PlaceVisitTrips.Where(rec => rec.PlaceVisitId == model.Id).ToList();
if (placeVisitTrips != null)
{ // удалили те, которых нет в модели
context.PlaceVisitTrips.RemoveRange(placeVisitTrips.Where(rec => !model.PlaceVisitTrips.ContainsKey(rec.TripId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateTour in placeVisitTrips)
{
model.PlaceVisitTrips.Remove(updateTour.TripId);
}
context.SaveChanges();
}
var placeVisit = context.PlaceVisits.First(x => x.Id == Id);
foreach (var pc in model.PlaceVisitTrips)
{
context.PlaceVisitTrips.Add(new PlaceVisitTrip
{
PlaceVisit = placeVisit,
Trip = context.Trips.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_placeVisitTrips = null;
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TourCompanyDatabaseImplement.Models
{
public class PlaceVisitTrip
{
public int Id { get; set; }
[Required]
public int PlaceVisitId { get; set; }
[Required]
public int TripId { get; set; }
public virtual PlaceVisit PlaceVisit { get; set; } = new();
public virtual Trip Trip { get; set; } = new();
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TourCompanyContracts.BindingModels;
using TourCompanyContracts.ViewModels;
using TourCompanyDataModels.Models;
namespace TourCompanyDatabaseImplement.Models
{
public class Trip : ITripModel
{
public int Id { get; set; }
public string TripName { get; set; }
public DateTime DateTrip { get; set; }
public int GidId { get; set; }
public string GidFIO { get; set; }
public virtual Gid Gid { get; set; }
public static Trip? Create(TripBindingModel? model)
{
return new Trip()
{
Id = model.Id,
TripName = model.TripName,
DateTrip = model.DateTrip,
GidId = model.GidId,
GidFIO = model.GidFIO
};
}
public void Update(TripBindingModel model)
{
TripName = model.TripName;
DateTrip = model.DateTrip;
}
public TripViewModel GetViewModel
{
get
{
using var context = new TourCompanyDatabase();
return new TripViewModel
{
Id = Id,
TripName = TripName,
DateTrip = DateTrip,
GidId = GidId,
GidFIO = context.Gids.FirstOrDefault(x => x.Id == GidId)?.GidFIO ?? string.Empty,
};
}
}
}
}

View File

@ -21,8 +21,12 @@ namespace TourCompanyDatabaseImplement
public virtual DbSet<Execurtion> Execurtions { set; get; }
public virtual DbSet<PlaceVisit> PlaceVisits { set; get; }
public virtual DbSet<TourGroup> TourGroups { set; get; }
public virtual DbSet<Trip> Trips { set; get; }
public virtual DbSet<Gid> Gids { set; get; }
public virtual DbSet<ExecurtionTour> ExecurtionTours { set; get; }
public virtual DbSet<TourGroupTour> TourGroupTours { set; get; }
public virtual DbSet<PlaceVisitTrip> PlaceVisitTrips { set; get; }
public virtual DbSet<GidExecurtion> GidExecurtions { set; get; }
}
}

View File

@ -6,10 +6,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />