полный круд)
This commit is contained in:
parent
456f0e83c4
commit
d840395ab6
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using TravelCompanyClientApp.Models;
|
||||
using TravelCompanyContracts.BindingModels.TouristBindingModels;
|
||||
using TravelCompanyContracts.BusinessLogicsContracts.OperatorBusinessLogicsContracts;
|
||||
using TravelCompanyContracts.BusinessLogicsContracts.TouristBusinessLogicsContracts;
|
||||
using TravelCompanyContracts.SearchModels.OperatorSearchModels;
|
||||
using TravelCompanyContracts.SearchModels.TouristSearchModels;
|
||||
@ -20,13 +21,14 @@ namespace TravelCompanyClientApp.Controllers
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IExcursionLogic _logic;
|
||||
private readonly ITravelLogic _travelLogic;
|
||||
private readonly IGuideLogic _guideLogic;
|
||||
|
||||
|
||||
public ExcursionController(ILogger<HomeController> logger, IExcursionLogic logic, ITravelLogic travelLogic)
|
||||
public ExcursionController(ILogger<HomeController> logger, IExcursionLogic logic, ITravelLogic travelLogic, IGuideLogic guideLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_travelLogic = travelLogic;
|
||||
_guideLogic = guideLogic;
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Excursion()
|
||||
@ -108,7 +110,7 @@ namespace TravelCompanyClientApp.Controllers
|
||||
Response.Redirect("/Excursion/Excursion");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateTravelExcursion(int id)
|
||||
public IActionResult CreateTravelExcursion()
|
||||
{
|
||||
if (APIClient.Tourist == null)
|
||||
{
|
||||
@ -118,7 +120,7 @@ namespace TravelCompanyClientApp.Controllers
|
||||
ViewBag.Excursions = _logic.ReadList(new ExcursionSearchModel { TouristId = APIClient.Tourist.Id });
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateTravelExcursion(int travelselect, List<int> excursionselect)
|
||||
{
|
||||
if (APIClient.Tourist == null)
|
||||
@ -144,7 +146,46 @@ namespace TravelCompanyClientApp.Controllers
|
||||
TourTravels=travel.TourTravels,
|
||||
ExcursionTravels = te
|
||||
});
|
||||
Response.Redirect("/Excursion/Excursion");
|
||||
Response.Redirect($"/Travel/UpdateTravel/{travel.Id}");
|
||||
return;
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateGuideExcursion()
|
||||
{
|
||||
if (APIClient.Tourist == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Guides = _guideLogic.ReadList(null);
|
||||
ViewBag.Excursions = _logic.ReadList(new ExcursionSearchModel { TouristId = APIClient.Tourist.Id });
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateGuideExcursion(int excursionselect, List<int> guideselect)
|
||||
{
|
||||
if (APIClient.Tourist == null)
|
||||
{
|
||||
throw new Exception("Доступно только авторизованным пользователям");
|
||||
}
|
||||
if (excursionselect <= 0 || guideselect == null)
|
||||
{
|
||||
throw new Exception("Неправильноо введенные данные");
|
||||
}
|
||||
Dictionary<int, IGuideModel> te = new Dictionary<int, IGuideModel>();
|
||||
foreach (int exc in guideselect)
|
||||
{
|
||||
te.Add(exc, _guideLogic.ReadElement(new GuideSearchModel { Id = exc }));
|
||||
}
|
||||
var excursion = _logic.ReadElement(new ExcursionSearchModel { Id = excursionselect });
|
||||
_logic.Update(new ExcursionBindingModel
|
||||
{
|
||||
Id = excursion.Id,
|
||||
ExcursionName= excursion.ExcursionName,
|
||||
Duration = excursion.Duration,
|
||||
ExcursionDescrition= excursion.ExcursionDescrition,
|
||||
GuideExcursions = te
|
||||
});
|
||||
Response.Redirect($"/Excursion/UpdateExcursion/{excursion.Id}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ builder.Services.AddTransient<ITravelStorage, TravelStorage>();
|
||||
builder.Services.AddTransient<IExcursionStorage, ExcursionStorage>();
|
||||
builder.Services.AddTransient<IPlaceStorage, PlaceStorage>();
|
||||
builder.Services.AddTransient<ITourStorage, TourStorage>();
|
||||
builder.Services.AddTransient<IOperatorStorage, OperatorStorage>();
|
||||
builder.Services.AddTransient<IGuideStorage, GuideStorage>();
|
||||
|
||||
builder.Services.AddTransient<ITouristLogic, TouristLogic>();
|
||||
builder.Services.AddTransient<ITravelLogic, TravelLogic>();
|
||||
builder.Services.AddTransient<IExcursionLogic, ExcursionLogic>();
|
||||
builder.Services.AddTransient<IPlaceLogic, PlaceLogic>();
|
||||
builder.Services.AddTransient<ITourLogic, TourLogic>();
|
||||
builder.Services.AddTransient<IOperatorLogic, OperatorLogic>();
|
||||
builder.Services.AddTransient<IGuideLogic, GuideLogic>();
|
||||
|
||||
var app = builder.Build();
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
@ -0,0 +1,41 @@
|
||||
@{
|
||||
ViewData["Title"] = "CreateGuideExcursion";
|
||||
}
|
||||
|
||||
<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="excursionselect" class="form-control" id="excursionselect">
|
||||
@foreach (var excursion in ViewBag.Excursions)
|
||||
{
|
||||
<option value="@excursion.Id">@excursion.ExcursionName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-2">Гиды:</div>
|
||||
<div class="col-4">
|
||||
<select name="guideselect" class="form-control" multiple size="4" id="guideselect">
|
||||
@foreach (var guide in ViewBag.Guides)
|
||||
{
|
||||
<option value="@guide.Id">@guide.Surname @guide.Name</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>
|
@ -27,8 +27,7 @@
|
||||
<select name="excursionselect" class="form-control" multiple size="4" id="excursionselect">
|
||||
@foreach (var excursion in ViewBag.Excursions)
|
||||
{
|
||||
var isSelected = ((List<int>)ViewBag.SelectedExcursions)?.Contains(excursion.Id) ?? false;
|
||||
<option value="@excursion.Id" selected="@isSelected">@excursion.ExcursionName</option>
|
||||
<option value="@excursion.Id" >@excursion.ExcursionName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -23,6 +23,18 @@
|
||||
<div class="col-2">Описание:</div>
|
||||
<div class="col-4"><input type="text" name="description" value="@Model.ExcursionDescrition" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-2">Гиды:</div>
|
||||
<div class="col-4">
|
||||
<ul>
|
||||
@foreach (var exc in Model.GuideExcursions)
|
||||
{
|
||||
<li> @exc.Value.Surname @exc.Value.Name @exc.Value.Patronymic</li>
|
||||
}
|
||||
</ul>
|
||||
</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>
|
||||
|
@ -5,13 +5,6 @@
|
||||
<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="excursion" class="form-control" asp-items="@(new SelectList(@ViewBag.Excursions,"Id", "ExcursionName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-2">Название:</div>
|
||||
@ -26,5 +19,12 @@
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4"></div>
|
||||
<div class="col-2">Экскурсия:</div>
|
||||
<div class="col-4">
|
||||
<select name="excursion" class="form-control" asp-items="@(new SelectList(@ViewBag.Excursions,"Id", "ExcursionName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Excursion" asp-action="CreateTravelExcursion">Привяка экскурсий к путешествиям</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Excursion" asp-action="CreateGuideExcursion">Привяка гидов к экскурсиям</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчеты</a>
|
||||
</li>
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyDataModels.Models.OperatorModels;
|
||||
using TravelCompanyDataModels.Models.TouristModels;
|
||||
|
||||
namespace TravelCompanyContracts.BindingModels.TouristBindingModels
|
||||
@ -14,5 +15,10 @@ namespace TravelCompanyContracts.BindingModels.TouristBindingModels
|
||||
public string ExcursionDescrition { get; set; } = string.Empty;
|
||||
public int Duration { get; set; }
|
||||
public int TouristId { get; set; }
|
||||
public Dictionary<int, IGuideModel> GuideExcursions
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyDataModels.Models.OperatorModels;
|
||||
using TravelCompanyDataModels.Models.TouristModels;
|
||||
|
||||
namespace TravelCompanyContracts.ViewModels.TouristViewModels
|
||||
@ -18,5 +19,10 @@ namespace TravelCompanyContracts.ViewModels.TouristViewModels
|
||||
[DisplayName("Длительность экскурсии")]
|
||||
public int Duration { get; set; }
|
||||
public int TouristId { get; set; }
|
||||
public Dictionary<int, IGuideModel> GuideExcursions
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyDataModels.Models.OperatorModels;
|
||||
|
||||
namespace TravelCompanyDataModels.Models.TouristModels
|
||||
{
|
||||
@ -11,5 +12,6 @@ namespace TravelCompanyDataModels.Models.TouristModels
|
||||
string ExcursionName { get; }
|
||||
string ExcursionDescrition { get; }
|
||||
int Duration { get; }
|
||||
Dictionary<int, IGuideModel> GuideExcursions { get; }
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,10 @@ namespace TravelCompanyDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new TravelCompanyDatabase();
|
||||
return context.Excursions
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Include(x => x.Guides)
|
||||
.ThenInclude(x => x.Guide)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ExcursionViewModel> GetFilteredList(ExcursionSearchModel
|
||||
model)
|
||||
@ -28,10 +30,12 @@ namespace TravelCompanyDatabaseImplement.Implements
|
||||
if (model.TouristId.HasValue)
|
||||
{
|
||||
return context.Excursions
|
||||
.Where(x => x.TouristId == model.TouristId)
|
||||
.Include(x => x.Tourist)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Where(x => x.TouristId == model.TouristId)
|
||||
.Include(x => x.Tourist)
|
||||
.Include(x => x.Guides)
|
||||
.ThenInclude(x => x.Guide)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else return new();
|
||||
}
|
||||
@ -43,11 +47,13 @@ namespace TravelCompanyDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new TravelCompanyDatabase();
|
||||
return context.Excursions
|
||||
.FirstOrDefault(x =>
|
||||
!string.IsNullOrEmpty(model.ExcursionName) && x.ExcursionName ==
|
||||
model.ExcursionName ||
|
||||
model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
.Include(x => x.Guides)
|
||||
.ThenInclude(x => x.Guide)
|
||||
.FirstOrDefault(x =>
|
||||
!string.IsNullOrEmpty(model.ExcursionName) && x.ExcursionName ==
|
||||
model.ExcursionName ||
|
||||
model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ExcursionViewModel? Insert(ExcursionBindingModel model)
|
||||
{
|
||||
@ -70,7 +76,7 @@ namespace TravelCompanyDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
component.Update(context, model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ namespace TravelCompanyDatabaseImplement.Models.OperatorModels
|
||||
Name = Name,
|
||||
Patronymic = Patronymic,
|
||||
OperatorId = OperatorId,
|
||||
OperatorLogin = Operator.Login
|
||||
};
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using TravelCompanyDataModels.Models.TouristModels;
|
||||
using TravelCompanyContracts.BindingModels.TouristBindingModels;
|
||||
using TravelCompanyContracts.ViewModels.TouristViewModels;
|
||||
using TravelCompanyDataModels.Models.OperatorModels;
|
||||
|
||||
namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
{
|
||||
@ -27,9 +28,21 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
public virtual List<Place> Places { get; set; } = new();
|
||||
[ForeignKey("ExcursionId")]
|
||||
public virtual List<ExcursionTravel> ExcursionTravels { get; set; } = new();
|
||||
public Dictionary<int, IGuideModel>? _guideExcursions = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IGuideModel> GuideExcursions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_guideExcursions == null)
|
||||
{
|
||||
_guideExcursions = Guides.ToDictionary(rec => rec.GuideId, rec => rec.Guide as IGuideModel);
|
||||
}
|
||||
return _guideExcursions;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ExcursionId")]
|
||||
public virtual List<GuideExcursion> GuideExcursions { get; set; } = new();
|
||||
|
||||
public virtual List<GuideExcursion> Guides { get; set; } = new();
|
||||
public static Excursion? Create(ExcursionBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -45,7 +58,7 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
TouristId = model.TouristId
|
||||
};
|
||||
}
|
||||
public void Update(ExcursionBindingModel model)
|
||||
public void Update(TravelCompanyDatabase context, ExcursionBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -54,6 +67,25 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
ExcursionName = model.ExcursionName;
|
||||
ExcursionDescrition = model.ExcursionDescrition;
|
||||
Duration = model.Duration;
|
||||
|
||||
var GuideExcursions = context.GuideExcursions.Where(rec => rec.ExcursionId == model.Id).ToList();
|
||||
if (GuideExcursions != null && GuideExcursions.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.GuideExcursions.RemoveRange(GuideExcursions.Where(rec => model.Id == rec.Excursion.Id));
|
||||
context.SaveChanges();
|
||||
}
|
||||
var Excursion = context.Excursions.First(x => x.Id == Id);
|
||||
foreach (var rc in model.GuideExcursions)
|
||||
{
|
||||
context.GuideExcursions.Add(new GuideExcursion
|
||||
{
|
||||
Excursion = Excursion,
|
||||
Guide = context.Guides.First(x => x.Id == rc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_guideExcursions = null;
|
||||
}
|
||||
public ExcursionViewModel GetViewModel => new()
|
||||
{
|
||||
@ -61,7 +93,8 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
ExcursionName = ExcursionName,
|
||||
ExcursionDescrition = ExcursionDescrition,
|
||||
Duration = Duration,
|
||||
TouristId = TouristId
|
||||
TouristId = TouristId,
|
||||
GuideExcursions=GuideExcursions
|
||||
};
|
||||
}
|
||||
}
|
@ -33,9 +33,6 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
{
|
||||
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;
|
||||
@ -49,7 +46,6 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
{
|
||||
if (_excursionTravels == null)
|
||||
{
|
||||
|
||||
_excursionTravels = Excursions.ToDictionary(rec => rec.ExcursionId,
|
||||
rec => rec.Excursion as IExcursionModel);
|
||||
}
|
||||
@ -82,17 +78,6 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public static Travel Create(TravelBindingModel model)
|
||||
{
|
||||
return new Travel
|
||||
{
|
||||
Id = model.Id,
|
||||
TravelName = model.TravelName,
|
||||
DateStart = model.DateStart,
|
||||
TouristId = model.TouristId,
|
||||
TravelDescription = model.TravelDescription
|
||||
};
|
||||
}
|
||||
public void Update(TravelCompanyDatabase context, TravelBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -131,7 +116,6 @@ namespace TravelCompanyDatabaseImplement.Models.TouristModel
|
||||
_tourTravels = null;
|
||||
try
|
||||
{
|
||||
var Excursion = context.Excursions.First(x => x.Id == Id);
|
||||
foreach (var rc in model.ExcursionTravels)
|
||||
{
|
||||
context.ExcursionTravels.Add(new ExcursionTravel
|
||||
|
Loading…
x
Reference in New Issue
Block a user