круд 1 сущности

This commit is contained in:
Kate 2023-06-21 15:02:10 +03:00
parent 6669e7ef01
commit 00e37e4ebc
19 changed files with 1287 additions and 167 deletions

View File

@ -99,9 +99,9 @@ namespace TravelCompanyBusinessLogic.BusinessLogic.TouristLogics
{
throw new ArgumentNullException("Нет пароля туриста", nameof(model.Password));
}
if (model.BirthDay == default)
if ((DateTime.Now - model.BirthDay).Days/365<18)
{
throw new ArgumentNullException("Нет даты рождения туриста", nameof(model.BirthDay));
throw new ArgumentNullException("Неверная дата рождения туриста", nameof(model.BirthDay));
}
_logger.LogInformation("Tourist. Id:{Id}.Surname:{Surname}.Name:{Name}.Patronomic:{Patronomic}.BirthDay:{BirthDay}.Email:{Email}.Login:{Login}.Password:{ Password}.",
model.Id, model.Surname, model.Name, model.Patronymic, model.BirthDay, model.Email, model.Login, new string('*', model.Password.Length));

View File

@ -5,11 +5,13 @@ using System.Diagnostics;
using TravelCompanyClientApp.Models;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.BusinessLogicsContracts.TouristBusinessLogicsContracts;
using TravelCompanyContracts.SearchModels.OperatorSearchModels;
using TravelCompanyContracts.SearchModels.TouristSearchModels;
using TravelCompanyContracts.ViewModels.OperatorViewModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;
using TravelCompanyDatabaseImplement.Models.TouristModel;
using TravelCompanyDataModels.Models.OperatorModels;
using TravelCompanyDataModels.Models.TouristModels;
namespace TravelCompanyClientApp.Controllers
{
@ -17,12 +19,14 @@ namespace TravelCompanyClientApp.Controllers
{
private readonly ILogger<HomeController> _logger;
private readonly IExcursionLogic _logic;
private readonly ITravelLogic _travelLogic;
public ExcursionController(ILogger<HomeController> logger, IExcursionLogic logic)
public ExcursionController(ILogger<HomeController> logger, IExcursionLogic logic, ITravelLogic travelLogic)
{
_logger = logger;
_logic = logic;
_travelLogic = travelLogic;
}
[HttpGet]
public IActionResult Excursion()
@ -44,11 +48,15 @@ namespace TravelCompanyClientApp.Controllers
[HttpPost]
public void CreateExcursion(string excursionname, string description, int duration)
{
if (string.IsNullOrEmpty(excursionname) || string.IsNullOrEmpty(description) || duration<=0)
if (APIClient.Tourist == null)
{
throw new Exception("Введите логин, пароль и ФИО");
throw new Exception("Доступно только авторизованным пользователям");
}
_logic.Create( new ExcursionBindingModel
if (string.IsNullOrEmpty(excursionname) || string.IsNullOrEmpty(description) || duration <= 0)
{
throw new Exception("Неправильноо введенные данные");
}
_logic.Create(new ExcursionBindingModel
{
ExcursionName = excursionname,
ExcursionDescrition = description,
@ -65,23 +73,23 @@ namespace TravelCompanyClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(_logic.ReadElement(new ExcursionSearchModel { TouristId = APIClient.Tourist.Id, Id=id})) ;
return View(_logic.ReadElement(new ExcursionSearchModel { TouristId = APIClient.Tourist.Id, Id = id }));
}
[HttpPost("/excursion/updateexcursion/{id?}")]
public void UpdateExcursion(int id, string name, string description, int duration)
public void UpdateExcursion(int id, string excursionname, string description, int duration)
{
if (APIClient.Tourist == null)
{
throw new Exception("Доступно только авторизованным пользователям");
}
//if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
//{
// throw new Exception("Введите логин, пароль и ФИО");
//}
_logic.Update( new ExcursionBindingModel
if (string.IsNullOrEmpty(excursionname) || string.IsNullOrEmpty(description) || duration <= 0)
{
throw new Exception("Неправильноо введенные данные");
}
_logic.Update(new ExcursionBindingModel
{
Id = id,
ExcursionName = name,
ExcursionName = excursionname,
ExcursionDescrition = description,
Duration = duration,
TouristId = APIClient.Tourist.Id
@ -89,19 +97,53 @@ namespace TravelCompanyClientApp.Controllers
Response.Redirect("/Excursion/Excursion");
return;
}
[HttpPost("/excursion/deleteexcursion/{id?}")]
public void DeleteExcursion(int id)
{
if (APIClient.Tourist == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
_logic.Delete( new ExcursionBindingModel { Id = id });
if (APIClient.Tourist == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
_logic.Delete(new ExcursionBindingModel { Id = id });
Response.Redirect("/Excursion/Excursion");
}
[HttpGet]
public IActionResult CreateTravelExcursion(int id)
{
if (APIClient.Tourist == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Travels = _travelLogic.ReadList(new TravelSearchModel { TouristId = APIClient.Tourist.Id});
ViewBag.Excursions = _logic.ReadList(new ExcursionSearchModel { TouristId = APIClient.Tourist.Id });
return View();
}
public void CreateTravelExcursion(int travelselect, List<int> excursionselect)
{
if (APIClient.Tourist == null)
{
throw new Exception("Доступно только авторизованным пользователям");
}
if (travelselect <= 0 || excursionselect==null)
{
throw new Exception("Неправильноо введенные данные");
}
Dictionary<int, IExcursionModel> te = new Dictionary<int, IExcursionModel>();
foreach (int exc in excursionselect)
{
te.Add(exc, _logic.ReadElement(new ExcursionSearchModel { Id = exc }));
}
var travel=_travelLogic.ReadElement(new TravelSearchModel { Id=travelselect });
_travelLogic.Update(new TravelBindingModel
{
TravelName = travel.TravelName,
DateStart = travel.DateStart,
TravelDescription = travel.TravelDescription,
ExcursionTravels = te
});
Response.Redirect("/Excursion/Excursion");
return;
}
}
}

View File

@ -10,6 +10,7 @@ using TravelCompanyContracts.ViewModels.OperatorViewModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;
using TravelCompanyDatabaseImplement.Models.TouristModel;
using TravelCompanyDataModels.Models.OperatorModels;
using VisioForge.MediaFramework.Helpers;
namespace TravelCompanyClientApp.Controllers
{
@ -25,50 +26,8 @@ namespace TravelCompanyClientApp.Controllers
_logic = logic;
}
[HttpGet]
public IActionResult Index()
{
if (APIClient.Tourist == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<TravelViewModel>>($"api/travel/gettravels?touristId={APIClient.Tourist.Id}"));
}
[HttpGet]
public IActionResult CreateTravel()
{
if (APIClient.Tourist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
return View(APIClient.GetRequest<List<TourViewModel>>($"api/tour/gettours"));
}
[HttpPost]
public void CreateTravel(List<int> selectedTours, string travelname, string datestart, string description)
{
//if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
//{
// throw new Exception("Введите логин, пароль и ФИО");
//}
var model = new TravelBindingModel
{
TravelName = travelname,
TravelDescription = description,
DateStart = DateTime.Parse(datestart),
TourTravels = new Dictionary<int, ITourModel>(),
TouristId = APIClient.Tourist.Id
};
foreach(var tourId in selectedTours)
{
var modelTour = APIClient.GetRequest<TourViewModel>($"api/tour/gettour?id={tourId}");
model.TourTravels.Add(tourId, modelTour);
};
APIClient.PostRequest("api/travel/createtravel", model);
Response.Redirect("Excursion");
return;
}
[HttpGet]
public IActionResult Privacy()
{
@ -85,12 +44,12 @@ namespace TravelCompanyClientApp.Controllers
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
//доделать проверку
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)
|| string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(birthday))
{
throw new Exception("Введите логин, пароль и ФИО");
throw new Exception("Неверно введены личные данные");
}
APIClient.PostRequest("api/tourist/updatedata", new TouristBindingModel
_logic.Update( new TouristBindingModel
{
Id = APIClient.Tourist.Id,
Surname=surname,
@ -101,7 +60,6 @@ namespace TravelCompanyClientApp.Controllers
Email = login,
Password = password
});
APIClient.Tourist.Surname = surname;
APIClient.Tourist.Name = name;
APIClient.Tourist.Patronymic = patronymic;
@ -112,9 +70,6 @@ namespace TravelCompanyClientApp.Controllers
Response.Redirect("Privacy");
}
//crud place
[HttpGet]
public IActionResult Enter()
{
@ -142,6 +97,10 @@ namespace TravelCompanyClientApp.Controllers
public IActionResult Report()
{
if (APIClient.Tourist == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpGet]
@ -153,11 +112,12 @@ namespace TravelCompanyClientApp.Controllers
[HttpPost]
public void Register(string login, string email, string password, string surname, string name, string patronymic, string birthday)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) )
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)
|| string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(birthday))
{
throw new Exception("Введите логин, пароль и ФИО");
throw new Exception("Неверно введены личные данные");
}
_logic.Create( new TouristBindingModel
_logic.Create( new TouristBindingModel
{
Login = login,
Email = email,
@ -171,35 +131,6 @@ namespace TravelCompanyClientApp.Controllers
return;
}
/*[HttpPost]
public void CreateTravel(string travelname, string datestart, string traveldesc, List<int> tours)
{
if (APIClient.Client == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (count <= 0)
{
throw new Exception("Количество и сумма должны быть больше 0");
}
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
{
ClientId = APIClient.Client.Id,
ReinforcedId = Reinforced,
Count = count,
Sum = Calc(count, Reinforced)
});
Response.Redirect("Index");
}
*/
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@ -2,6 +2,7 @@
using FluentNHibernate;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using TravelCompanyBusinessLogic.BusinessLogic.TouristLogics;
using TravelCompanyClientApp.Models;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.BusinessLogicsContracts.OperatorBusinessLogicsContracts;
@ -35,7 +36,6 @@ namespace TravelCompanyClientApp.Controllers
return Redirect("~/Home/Enter");
}
return View(_logic.ReadList(new TravelSearchModel { TouristId = APIClient.Tourist.Id }));
}
[HttpGet]
@ -63,7 +63,7 @@ namespace TravelCompanyClientApp.Controllers
TravelDescription = description,
DateStart = datestart,
TouristId = APIClient.Tourist.Id,
TourTravels=ts
TourTravels= ts
});
Response.Redirect("Travel");
return;
@ -75,23 +75,29 @@ namespace TravelCompanyClientApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Tours = _tourLogic.ReadList(null);
return View(_logic.ReadElement(new TravelSearchModel { TouristId = APIClient.Tourist.Id, Id=id})) ;
}
[HttpPost("/travel/updatetravel/{id?}")]
public void UpdateTravel(int id, string placename, string address, int excursion)
public void UpdateTravel(int id, string travelname, DateTime datestart, string description, List<int> tourselect)
{
if (string.IsNullOrEmpty(placename) || string.IsNullOrEmpty(address) || excursion == null)
if (string.IsNullOrEmpty(travelname) || string.IsNullOrEmpty(description) || datestart == null || tourselect == null || tourselect.Count <= 0)
{
throw new Exception("Введите логин, пароль и ФИО");
throw new Exception("Неверный ввод");
}
_logic.Update( new TravelBindingModel
Dictionary<int, ITourModel> ts = new Dictionary<int, ITourModel>();
foreach (int tour in tourselect)
{
ts.Add(tour, _tourLogic.ReadElement(new TourSearchModel { Id = tour }));
}
_logic.Update(new TravelBindingModel
{
Id = id,
TravelName = placename,
// TravelAddress = address,
//ExcursionId = excursion,
TouristId=APIClient.Tourist.Id
});
TravelName = travelname,
TravelDescription = description,
DateStart = datestart,
TourTravels = ts
}); ;
Response.Redirect("/Travel/Travel");
return;
}

View File

@ -0,0 +1,38 @@
@{
ViewData["Title"] = "CreateTravelExcursion";
}
<div class="text-center">
<h2 class="display-4">Привяка экскурсий к путешествиям</h2>
</div>
<form method="post" style="margin-top:50px">
<div class="row">
<div class="col-4"></div>
<div class="col-2">Путешествие:</div>
<div class="col-4">
<select name="travelselect" class="form-control" id="travelselect">
@foreach (var travel in ViewBag.Travels)
{
<option value="@travel.Id">@travel.TravelName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-2">Экскурсии:</div>
<div class="col-4">
<select name="excursionselect" class="form-control" multiple size="4" id="excursionselect">
@foreach (var excursion in ViewBag.Excursions)
{
<option value="@excursion.Id">@excursion.ExcursionName</option>
}
</select>
</div>
</div>
<div class="row" style="margin-top:20px">
<div class="col-4"></div>
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -11,7 +11,7 @@
<div class="row">
<div class="col-4"></div>
<div class="col-2">Название:</div>
<div class="col-4"><input type="text" name="name" value="@Model.ExcursionName" /></div>
<div class="col-4"><input type="text" name="excursionname" value="@Model.ExcursionName" /></div>
</div>
<div class="row">
<div class="col-4"></div>

View File

@ -29,7 +29,7 @@
<a class="nav-link text-dark" asp-area="" asp-controller="Place" asp-action="Place">Места</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Place" asp-action="Place">Привяка экскурсий к путешествиям</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Excursion" asp-action="ExcursionTravels">Привяка экскурсий к путешествиям</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчеты</a>

View File

@ -12,12 +12,14 @@
<div class="row">
<div class="col-4"></div>
<div class="col-2">Название:</div>
<div class="col-4"><input type="text" name="name" value="@Model.TravelName" /></div>
<div class="col-4"><input type="text" name="travelname" value="@Model.TravelName" /></div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-2">Начало путешествия:</div>
<div class="col-4"><input type="date" class="form-control" name="datestart" value="@Model.DateStart" /></div>
<div class="col-4">
<input type="date" class="form-control" name="datestart" value="@Model.DateStart.ToString("yyyy-MM-dd")" />
</div>
</div>
<div class="row">
<div class="col-4"></div>
@ -27,17 +29,16 @@
<div class="row">
<div class="col-4"></div>
<div class="col-2">Туры:</div>
<div class="col-4">
<select name="tourselect" class="form-control" multiple size="4" id="tourselect">
@foreach (var tour in ViewBag.Tours)
{
var isSelected = Model.TourTravels.Any(x => x.Key == tour.Id);
<option value="@tour.Id" selected="@isSelected">@tour.TourName</option>
}
</select>
</div>
</div>
@foreach (var item in Model.TourTravels.Values)
{
<div class="row">
<div class="col-4"></div>
<div class="col-4">
<select name="tour" class="form-control" value="@item.TourName" asp-items="@(new SelectList(@ViewBag.Tours,"Id", "TourName"))"></select>
</div>
</div>
}
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" style="margin-top:20px"/></div>

View File

@ -18,12 +18,15 @@ namespace TravelCompanyContracts.BindingModels.TouristBindingModels
public DateTime DateStart { get; set; } = DateTime.Now;
public string TravelDescription { get; set; } = string.Empty;
public int TouristId { get; set; }
public Dictionary<int, ITourModel> TourTravels { get; set; }
public TravelBindingModel() { }
[JsonConstructor]
public TravelBindingModel(Dictionary<int, TourViewModel> TourTravels)
public Dictionary<int, ITourModel> TourTravels
{
this.TourTravels = TourTravels.ToDictionary(x => x.Key, x => x.Value as ITourModel);
}
get;
set;
} = new();
public Dictionary<int, IExcursionModel> ExcursionTravels
{
get;
set;
} = new();
}
}

View File

@ -8,6 +8,7 @@ using TravelCompanyDataModels.Models.TouristModels;
using TravelCompanyDataModels.Models.OperatorModels;
using TravelCompanyContracts.ViewModels.OperatorViewModels;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations.Schema;
namespace TravelCompanyContracts.ViewModels.TouristViewModels
{
@ -21,12 +22,15 @@ namespace TravelCompanyContracts.ViewModels.TouristViewModels
[DisplayName("Описание путешествия")]
public string TravelDescription { get; set; } = string.Empty;
public int TouristId { get; set; }
public Dictionary<int, ITourModel> TourTravels { get; set; }
public TravelViewModel() { }
[JsonConstructor]
public TravelViewModel(Dictionary<int, TourViewModel> TourTravels)
public Dictionary<int, ITourModel> TourTravels
{
this.TourTravels = TourTravels.ToDictionary(x => x.Key, x => x.Value as ITourModel);
}
get;
set;
} = new();
public Dictionary<int, IExcursionModel> ExcursionTravels
{
get;
set;
} = new();
}
}

View File

@ -13,5 +13,6 @@ namespace TravelCompanyDataModels.Models.TouristModels
DateTime DateStart { get; }
string TravelDescription { get; }
Dictionary<int, ITourModel> TourTravels { get; }
Dictionary<int, IExcursionModel> ExcursionTravels { get; }
}
}

View File

@ -40,9 +40,10 @@ namespace TravelCompanyDatabaseImplement.Implements
}
using var context = new TravelCompanyDatabase();
return context.Travels
.Include(x => x.Tours)
.ThenInclude(x => x.Tour)
.FirstOrDefault(x =>
!string.IsNullOrEmpty(model.TravelName) && x.TravelName ==
model.TravelName ||
!string.IsNullOrEmpty(model.TravelName) && x.TravelName == model.TravelName ||
model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
@ -67,7 +68,7 @@ namespace TravelCompanyDatabaseImplement.Implements
{
return null;
}
component.Update(model);
component.Update(context,model);
context.SaveChanges();
return component.GetViewModel;
}

View File

@ -0,0 +1,478 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using TravelCompanyDatabaseImplement;
#nullable disable
namespace TravelCompanyDatabaseImplement.Migrations
{
[DbContext(typeof(TravelCompanyDatabase))]
[Migration("20230621083414_addPrivazka")]
partial class addPrivazka
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.GuideExcursion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<int>("GuideId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.HasIndex("GuideId");
b.ToTable("GuideExcursions");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("OperatorId")
.HasColumnType("int");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OperatorId");
b.ToTable("Guides");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDay")
.HasColumnType("datetime2");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Operators");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("OperatorId")
.HasColumnType("int");
b.Property<string>("TourName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OperatorId");
b.ToTable("Tours");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TourTravel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("TourId")
.HasColumnType("int");
b.Property<int>("TravelId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TravelId");
b.ToTable("TourTravels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Duration")
.HasColumnType("int");
b.Property<string>("ExcursionDescrition")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ExcursionName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TouristId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TouristId");
b.ToTable("Excursions");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.ExcursionTravel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<int>("TravelId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.HasIndex("TravelId");
b.ToTable("ExcursionTravels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Place", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<string>("PlaceAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PlaceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TouristId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.HasIndex("TouristId");
b.ToTable("Places");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDay")
.HasColumnType("datetime2");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Tourists");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateStart")
.HasColumnType("datetime2");
b.Property<int>("TouristId")
.HasColumnType("int");
b.Property<string>("TravelDescription")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("TravelName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("TouristId");
b.ToTable("Travels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.GuideExcursion", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", "Excursion")
.WithMany("GuideExcursions")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", "Guide")
.WithMany("GuideExcursions")
.HasForeignKey("GuideId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Excursion");
b.Navigation("Guide");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", "Operator")
.WithMany("Guides")
.HasForeignKey("OperatorId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Operator");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", "Operator")
.WithMany("Tours")
.HasForeignKey("OperatorId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Operator");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TourTravel", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", "Tour")
.WithMany("TourTravels")
.HasForeignKey("TravelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", "Travel")
.WithMany("Tours")
.HasForeignKey("TravelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Tour");
b.Navigation("Travel");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", "Tourist")
.WithMany("Excursions")
.HasForeignKey("TouristId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Tourist");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.ExcursionTravel", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", "Excursion")
.WithMany("ExcursionTravels")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", "Travel")
.WithMany("Excursions")
.HasForeignKey("TravelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Excursion");
b.Navigation("Travel");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Place", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", "Excursion")
.WithMany("Places")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", "Tourist")
.WithMany("Places")
.HasForeignKey("TouristId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Excursion");
b.Navigation("Tourist");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", "Tourist")
.WithMany("Travels")
.HasForeignKey("TouristId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Tourist");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
{
b.Navigation("GuideExcursions");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", b =>
{
b.Navigation("Guides");
b.Navigation("Tours");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
{
b.Navigation("TourTravels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
{
b.Navigation("ExcursionTravels");
b.Navigation("GuideExcursions");
b.Navigation("Places");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", b =>
{
b.Navigation("Excursions");
b.Navigation("Places");
b.Navigation("Travels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.Navigation("Excursions");
b.Navigation("Tours");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace TravelCompanyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class addPrivazka : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -0,0 +1,480 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using TravelCompanyDatabaseImplement;
#nullable disable
namespace TravelCompanyDatabaseImplement.Migrations
{
[DbContext(typeof(TravelCompanyDatabase))]
[Migration("20230621100736_test")]
partial class test
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.GuideExcursion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<int>("GuideId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.HasIndex("GuideId");
b.ToTable("GuideExcursions");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("OperatorId")
.HasColumnType("int");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OperatorId");
b.ToTable("Guides");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDay")
.HasColumnType("datetime2");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Operators");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("OperatorId")
.HasColumnType("int");
b.Property<string>("TourName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OperatorId");
b.ToTable("Tours");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TourTravel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("TourId")
.HasColumnType("int");
b.Property<int>("TravelId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TourId");
b.HasIndex("TravelId");
b.ToTable("TourTravels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Duration")
.HasColumnType("int");
b.Property<string>("ExcursionDescrition")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ExcursionName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TouristId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TouristId");
b.ToTable("Excursions");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.ExcursionTravel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<int>("TravelId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.HasIndex("TravelId");
b.ToTable("ExcursionTravels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Place", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<string>("PlaceAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PlaceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TouristId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.HasIndex("TouristId");
b.ToTable("Places");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDay")
.HasColumnType("datetime2");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Tourists");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("DateStart")
.HasColumnType("datetime2");
b.Property<int>("TouristId")
.HasColumnType("int");
b.Property<string>("TravelDescription")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("TravelName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("TouristId");
b.ToTable("Travels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.GuideExcursion", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", "Excursion")
.WithMany("GuideExcursions")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", "Guide")
.WithMany("GuideExcursions")
.HasForeignKey("GuideId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Excursion");
b.Navigation("Guide");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", "Operator")
.WithMany("Guides")
.HasForeignKey("OperatorId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Operator");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", "Operator")
.WithMany("Tours")
.HasForeignKey("OperatorId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Operator");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TourTravel", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", "Tour")
.WithMany("TourTravels")
.HasForeignKey("TourId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", "Travel")
.WithMany("Tours")
.HasForeignKey("TravelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Tour");
b.Navigation("Travel");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", "Tourist")
.WithMany("Excursions")
.HasForeignKey("TouristId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Tourist");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.ExcursionTravel", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", "Excursion")
.WithMany("ExcursionTravels")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", "Travel")
.WithMany("Excursions")
.HasForeignKey("TravelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Excursion");
b.Navigation("Travel");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Place", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", "Excursion")
.WithMany("Places")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", "Tourist")
.WithMany("Places")
.HasForeignKey("TouristId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Excursion");
b.Navigation("Tourist");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", "Tourist")
.WithMany("Travels")
.HasForeignKey("TouristId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Tourist");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
{
b.Navigation("GuideExcursions");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", b =>
{
b.Navigation("Guides");
b.Navigation("Tours");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
{
b.Navigation("TourTravels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
{
b.Navigation("ExcursionTravels");
b.Navigation("GuideExcursions");
b.Navigation("Places");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", b =>
{
b.Navigation("Excursions");
b.Navigation("Places");
b.Navigation("Travels");
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.Navigation("Excursions");
b.Navigation("Tours");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace TravelCompanyDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class test : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_TourTravels_Tours_TravelId",
table: "TourTravels");
migrationBuilder.CreateIndex(
name: "IX_TourTravels_TourId",
table: "TourTravels",
column: "TourId");
migrationBuilder.AddForeignKey(
name: "FK_TourTravels_Tours_TourId",
table: "TourTravels",
column: "TourId",
principalTable: "Tours",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_TourTravels_Tours_TourId",
table: "TourTravels");
migrationBuilder.DropIndex(
name: "IX_TourTravels_TourId",
table: "TourTravels");
migrationBuilder.AddForeignKey(
name: "FK_TourTravels_Tours_TravelId",
table: "TourTravels",
column: "TravelId",
principalTable: "Tours",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -42,7 +42,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("GuideId");
b.ToTable("GuideExcursions");
b.ToTable("GuideExcursions", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Guide", b =>
@ -71,7 +71,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("OperatorId");
b.ToTable("Guides");
b.ToTable("Guides", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Operator", b =>
@ -110,7 +110,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Operators");
b.ToTable("Operators", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", b =>
@ -132,7 +132,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("OperatorId");
b.ToTable("Tours");
b.ToTable("Tours", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TourTravel", b =>
@ -151,9 +151,11 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("TourId");
b.HasIndex("TravelId");
b.ToTable("TourTravels");
b.ToTable("TourTravels", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Excursion", b =>
@ -182,7 +184,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("TouristId");
b.ToTable("Excursions");
b.ToTable("Excursions", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.ExcursionTravel", b =>
@ -205,7 +207,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("TravelId");
b.ToTable("ExcursionTravels");
b.ToTable("ExcursionTravels", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Place", b =>
@ -236,7 +238,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("TouristId");
b.ToTable("Places");
b.ToTable("Places", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Tourist", b =>
@ -276,7 +278,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Tourists");
b.ToTable("Tourists", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
@ -305,7 +307,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
b.HasIndex("TouristId");
b.ToTable("Travels");
b.ToTable("Travels", (string)null);
});
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.GuideExcursion", b =>
@ -353,7 +355,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
{
b.HasOne("TravelCompanyDatabaseImplement.Models.OperatorModels.Tour", "Tour")
.WithMany("TourTravels")
.HasForeignKey("TravelId")
.HasForeignKey("TourId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -388,7 +390,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
.IsRequired();
b.HasOne("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", "Travel")
.WithMany("ExcursionTravels")
.WithMany("Excursions")
.HasForeignKey("TravelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -465,7 +467,7 @@ namespace TravelCompanyDatabaseImplement.Migrations
modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TouristModel.Travel", b =>
{
b.Navigation("ExcursionTravels");
b.Navigation("Excursions");
b.Navigation("Tours");
});

View File

@ -19,7 +19,7 @@ namespace TravelCompanyDatabaseImplement.Models.OperatorModels
[Required]
public int OperatorId { get; private set; }
public virtual Operator Operator { get; set; }
[ForeignKey("TravelId")]
[ForeignKey("TourId")]
public virtual List<TourTravel> TourTravels { get; set; } = new();
public static Tour? Create(TourBindingModel model)

View File

@ -9,6 +9,7 @@ using TravelCompanyDataModels.Models.TouristModels;
using TravelCompanyDataModels.Models.OperatorModels;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;
using TravelCompanyDatabaseImplement.Models.OperatorModels;
namespace TravelCompanyDatabaseImplement.Models.TouristModel
{
@ -24,23 +25,40 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
[Required]
public int TouristId { get; private set; }
public virtual Tourist Tourist { get; set; }
[NotMapped]
public Dictionary<int, ITourModel>? _tourTravels = null;
[NotMapped]
public Dictionary<int, ITourModel> TourTravels
{
get
{
if (_tourTravels == null)
{
using var context = new TravelCompanyDatabase();
//_tourTravels = Tours.ToDictionary(x => x.TourId, x => (context.Tours.FirstOrDefault(y => y.Id == x.TourId)! as ITourModel));
_tourTravels = Tours.ToDictionary(rec => rec.TourId, rec => rec.Tour as ITourModel);
}
return _tourTravels;
}
}
public Dictionary<int, IExcursionModel>? _excursionTravels = null;
[NotMapped]
public Dictionary<int, IExcursionModel> ExcursionTravels
{
get
{
if (_excursionTravels == null)
{
_excursionTravels = Excursions.ToDictionary(rec => rec.ExcursionId,
rec => rec.Excursion as IExcursionModel);
}
return _excursionTravels;
}
}
[ForeignKey("TravelId")]
public virtual List<ExcursionTravel> ExcursionTravels { get; set; } = new();
public virtual List<ExcursionTravel> Excursions { get; set; } = new();
[ForeignKey("TravelId")]
public virtual List<TourTravel> Tours { get; set; } = new();
@ -50,6 +68,7 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
{
return null;
}
return new Travel()
{
Id = model.Id,
@ -60,7 +79,6 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
Tours = model.TourTravels.Select(x => new TourTravel
{
Tour = context.Tours.First(y => y.Id == x.Key)
}).ToList()
};
}
@ -75,7 +93,7 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
TravelDescription = model.TravelDescription
};
}
public void Update(TravelBindingModel model)
public void Update(TravelCompanyDatabase context, TravelBindingModel model)
{
if (model == null)
{
@ -84,6 +102,47 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
TravelName = model.TravelName;
DateStart = model.DateStart;
TravelDescription = model.TravelDescription;
var TourTravels = context.TourTravels.Where(rec => rec.TravelId == model.Id).ToList();
if (TourTravels!= null && TourTravels.Count > 0)
{
// удалили те, которых нет в модели
context.TourTravels.RemoveRange(TourTravels.Where(rec => model.Id == rec.Travel.Id));
context.SaveChanges();
}
var ExcursionTravels = context.ExcursionTravels.Where(rec =>
rec.TravelId == model.Id).ToList();
if (ExcursionTravels != null && ExcursionTravels.Count > 0)
{
// удалили те, которых нет в модели
context.ExcursionTravels.RemoveRange(ExcursionTravels.Where(rec => model.Id == rec.Travel.Id));
context.SaveChanges();
}
var Travel = context.Travels.First(x => x.Id == Id);
foreach (var rc in model.TourTravels)
{
context.TourTravels.Add(new TourTravel
{
Travel = Travel,
Tour = context.Tours.First(x => x.Id == rc.Key),
});
context.SaveChanges();
}
_tourTravels = null;
try
{
var Excursion = context.Excursions.First(x => x.Id == Id);
foreach (var rc in model.ExcursionTravels)
{
context.ExcursionTravels.Add(new ExcursionTravel
{
Travel = Travel,
Excursion = context.Excursions.First(x => x.Id == rc.Key),
});
context.SaveChanges();
}
_tourTravels = null;
}catch (Exception ex) { }
}
public TravelViewModel GetViewModel => new()
{
@ -92,7 +151,8 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
DateStart = DateStart,
TouristId = TouristId,
TravelDescription = TravelDescription,
TourTravels = TourTravels
TourTravels = TourTravels,
ExcursionTravels = ExcursionTravels
};
}
}