main
This commit is contained in:
parent
48fefe4fb7
commit
8d59a6a221
@ -23,7 +23,7 @@ namespace TourCompanyBusinessLogic.BusinessLogics
|
||||
}
|
||||
public List<GidViewModel>? ReadList(GidSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. UserId:{UserId}. ExecurtionId:{ExecurtionId}. TripId:{TripId}. Id: { Id}", model?.UserId, model?.ExecurtionId, model?.TripId, model?.Id);
|
||||
_logger.LogInformation("ReadList. UserId:{UserId}. ExecurtionId:{ExecurtionId}. Id: { Id}", model?.UserId, model?.ExecurtionId, model?.Id);
|
||||
var list = model == null ? _gidStorage.GetFullList() : _gidStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace TourCompanyBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement.UserId:{UserId}. ExecurtionId:{ExecurtionId}. TripId:{TripId}. Id: { Id}", model.UserId, model.ExecurtionId, model.TripId, model.Id);
|
||||
_logger.LogInformation("ReadElement.UserId:{UserId}. ExecurtionId:{ExecurtionId}. Id: { Id}", model.UserId, model.ExecurtionId, model.Id);
|
||||
var element = _gidStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
@ -90,10 +90,6 @@ namespace TourCompanyBusinessLogic.BusinessLogics
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.TripId == null)
|
||||
{
|
||||
throw new ArgumentNullException("нет внешнего ключа поездки", nameof(model.TripId));
|
||||
}
|
||||
if (model.UserId == null)
|
||||
{
|
||||
throw new ArgumentNullException("нет внешнего ключа пользователя", nameof(model.UserId));
|
||||
@ -102,10 +98,9 @@ namespace TourCompanyBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("нет внешнего ключа экскурсии", nameof(model.ExecurtionId));
|
||||
}
|
||||
_logger.LogInformation("Gid. UserId:{UserId}. ExecurtionId:{ExecurtionId}. TripId:{TripId}. Id: { Id}", model.UserId, model.ExecurtionId, model.TripId, model.Id);
|
||||
_logger.LogInformation("Gid. UserId:{UserId}. ExecurtionId:{ExecurtionId}. Id: { Id}", model.UserId, model.ExecurtionId, model.Id);
|
||||
var element = _gidStorage.GetElement(new GidSearchModel
|
||||
{
|
||||
TripId = model.TripId,
|
||||
UserId = model.UserId,
|
||||
ExecurtionId = model.ExecurtionId
|
||||
|
||||
|
@ -14,8 +14,9 @@ namespace TourCompanyContracts.BindingModels
|
||||
public string Purpose { get; set; } = string.Empty;
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
public int ExecurtionDuratation { get; set; }
|
||||
|
||||
public int GidId { get; set; }
|
||||
public int GidId { get; set; }
|
||||
public string GidFIO { get; set; } = string.Empty;
|
||||
|
||||
|
||||
@ -24,7 +25,7 @@ namespace TourCompanyContracts.BindingModels
|
||||
|
||||
public int TuorId { get; set; }
|
||||
|
||||
public Dictionary<int, (ITourModel, decimal)> ExecurtionTours { get; set; } = new();
|
||||
public Dictionary<int, (IGidModel, string)> ExecurtionGids { get; set; } = new();
|
||||
public Dictionary<int, ITourModel> ExecurtionTours { get; set; } = new();
|
||||
//public Dictionary<int, (IGidModel, string)> ExecurtionGids { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ namespace TourCompanyContracts.BindingModels
|
||||
|
||||
public int Experion { get; set; }
|
||||
|
||||
public int TripId { get; set; }
|
||||
public Dictionary<int, (ITripModel, string)> GidTrips { get; set; } = new();
|
||||
//public int TripId { get; set; }
|
||||
//public Dictionary<int, (ITripModel, string)> GidTrips { get; set; } = new();
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public int ExecurtionId { get; set; }
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)> GidExecurtions { get; set; } = new();
|
||||
public Dictionary<int, (IExecurtionModel, int)> GidExecurtions { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,15 @@ namespace TourCompanyContracts.BindingModels
|
||||
|
||||
public string PlaceVisitName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TourGroupId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public string TourGroupName { get; set; } = string.Empty;
|
||||
|
||||
// Dictionary<ID, (Название, Цена)>
|
||||
public Dictionary<int, (ITripModel, decimal)> PlaceVisitTrips { get; set; } = new();
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, ITripModel> PlaceVisitTrips { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ namespace TourCompanyContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Number { get; set; } = string.Empty;
|
||||
public string TourGroupName { get; set; } = string.Empty;
|
||||
|
||||
public TourType Type { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (ITourModel, decimal)> TourGroupTours { get; set; } = new();
|
||||
public Dictionary<int, ITourModel> TourGroupTours { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@ namespace TourCompanyContracts.BindingModels
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
public int GidId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IPlaceVisitModel, string)> TripPlaceVisits
|
||||
{
|
||||
get;
|
||||
|
@ -11,9 +11,11 @@ namespace TourCompanyContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? TripId { get; set; }
|
||||
public string? FIO { get; set; } = string.Empty;
|
||||
|
||||
public int? UserId { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public int? Duratation { get; set; }
|
||||
|
||||
public int? ExecurtionId { get; set; }
|
||||
public int? ExecurtionId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,9 @@ namespace TourCompanyContracts.SearchModels
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? TourGroupId { get; set; }
|
||||
public string? PlaceVisitName { get; set; }
|
||||
|
||||
public int? UserId { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
@ -9,6 +9,7 @@ namespace TourCompanyContracts.SearchModels
|
||||
public class TourGroupSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public string? TourGroupName { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ namespace TourCompanyContracts.SearchModels
|
||||
public class TourSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace TourCompanyContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
public int? GidId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace TourCompanyContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? FIO { get; set; } = string.Empty;
|
||||
public string? Password { get; set; } = string.Empty;
|
||||
public string? Email { get; set; }
|
||||
public string? Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,14 @@ namespace TourCompanyContracts.ViewModels
|
||||
public string Purpose { get; set; } = string.Empty;
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
public int ExecurtionDuratation { get; set; }
|
||||
|
||||
public int GidId { get; set; }
|
||||
public int GidId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int TourId { get; set; }
|
||||
|
||||
public Dictionary<int, (ITourModel, decimal)> ExecurtionTours { get; set; } = new();
|
||||
public Dictionary<int, (IGidModel, string)> ExecurtionGids { get; set; } = new();
|
||||
public Dictionary<int, ITourModel> ExecurtionTours { get; set; } = new();
|
||||
//public Dictionary<int, (IGidModel, string)> ExecurtionGids { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,13 @@ namespace TourCompanyContracts.ViewModels
|
||||
|
||||
public int Experion { get; set; }
|
||||
|
||||
public int TripId { get; set; }
|
||||
public Dictionary<int, (ITripModel, string)> GidTrips { get; set; } = new();
|
||||
//public int TripId { get; set; }
|
||||
//public Dictionary<int, (ITripModel, string)> GidTrips { get; set; } = new();
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public int ExecurtionId { get; set; }
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)> GidExecurtions { get; set; } = new();
|
||||
public int Duratation { get; set; }
|
||||
public Dictionary<int, (IExecurtionModel, int)> GidExecurtions { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,11 @@ namespace TourCompanyContracts.ViewModels
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TourGroupId { get; set; }
|
||||
public string TourGroupName { get; set; } = string.Empty;
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
// Dictionary<ID, (Название, Цена)>
|
||||
public Dictionary<int, (ITripModel, decimal)> PlaceVisitTrips { get; set; } = new();
|
||||
public Dictionary<int, ITripModel> PlaceVisitTrips { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ namespace TourCompanyContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Number { get; set; } = string.Empty;
|
||||
public string TourGroupName { get; set; } = string.Empty;
|
||||
|
||||
public TourType Type { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (ITourModel, decimal)> TourGroupTours { get; set; } = new();
|
||||
public Dictionary<int, ITourModel> TourGroupTours { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,9 @@ namespace TourCompanyContracts.ViewModels
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
public int GidId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IPlaceVisitModel, string)> TripPlaceVisits
|
||||
{
|
||||
get;
|
||||
|
@ -17,8 +17,9 @@ namespace TourCompanyDataModels.Models
|
||||
|
||||
public int UserId { get; }
|
||||
|
||||
public string TourName { get; }
|
||||
// public string TourName { get; }
|
||||
|
||||
public Dictionary<int, (ITourModel, decimal)> Tours { get; }
|
||||
}
|
||||
public Dictionary<int, ITourModel> ExecurtionTours { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ namespace TourCompanyDataModels.Models
|
||||
|
||||
public int Experion { get;}
|
||||
|
||||
public Dictionary<int, (ITripModel, string)> GidTrips { get;}
|
||||
//public Dictionary<int, (ITripModel, string)> GidTrips { get;}
|
||||
|
||||
public int UserId { get;}
|
||||
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)> GidExecurtions { get; }
|
||||
public Dictionary<int, (IExecurtionModel, int)> GidExecurtions { get; }
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,6 @@ namespace TourCompanyDataModels.Models
|
||||
|
||||
public int UserId { get; }
|
||||
|
||||
public Dictionary<int, (ITripModel, decimal)> Trips { get; }
|
||||
public Dictionary<int, ITripModel> PlaceVisitTrips { get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ namespace TourCompanyDataModels.Models
|
||||
public interface ITourGroupModel : IId
|
||||
{
|
||||
|
||||
public string Number { get; }
|
||||
public string TourGroupName { get; }
|
||||
|
||||
public TourType Type { get; }
|
||||
|
||||
public int UserId { get; }
|
||||
public Dictionary<int, (ITourModel, decimal)> Tours { get; }
|
||||
public Dictionary<int, ITourModel> TourGroupTours { get; }
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ namespace TourCompanyDataModels.Models
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)> Execurtions { get; }
|
||||
// public Dictionary<int, (IExecurtionModel, DateTime)> Execurtions { get; }
|
||||
|
||||
public Dictionary<ITourGroupModel, decimal> TourGroups { get; }
|
||||
// public Dictionary<ITourGroupModel, decimal> TourGroups { get; }
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace TourCompanyDataModels.Models
|
||||
public DateTime Date { get; }
|
||||
|
||||
public int UserId { get; }
|
||||
public Dictionary<int, (IPlaceVisitModel, int)> TripPlaceVisits{ get; }
|
||||
//public Dictionary<int, IPlaceVisitModel> TripPlaceVisits{ get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace TourCompanyDatabaseImplement
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
110
TourCompanyDatabaseImplement/Implements/ExecurtionStorage.cs
Normal file
110
TourCompanyDatabaseImplement/Implements/ExecurtionStorage.cs
Normal 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.ViewModels;
|
||||
using TourCompanyDatabaseImplement;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
public class ExecurtionStorage : IExecurtionStorage
|
||||
{
|
||||
public List<ExecurtionViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Execurtions
|
||||
.Include(x => x.Tours)
|
||||
.ThenInclude(x => x.Tour)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ExecurtionViewModel> GetFilteredList(ExecurtionSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Purpose))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Execurtions
|
||||
.Include(x => x.Tours)
|
||||
.ThenInclude(x => x.Tour)
|
||||
.Where(x => x.Purpose.Contains(model.Purpose))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ExecurtionViewModel? GetElement(ExecurtionSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Purpose) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Execurtions
|
||||
.Include(x => x.Tours)
|
||||
.ThenInclude(x => x.Tour)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Purpose) && x.Purpose == model.Purpose) || (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ExecurtionViewModel? Insert(ExecurtionBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var newExecurtion = Execurtion.Create(context, model);
|
||||
if (newExecurtion == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Execurtions.Add(newExecurtion);
|
||||
context.SaveChanges();
|
||||
return newExecurtion.GetViewModel;
|
||||
}
|
||||
|
||||
public ExecurtionViewModel? Update(ExecurtionBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var execurtion = context.Execurtions.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (execurtion == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
execurtion.Update(model);
|
||||
context.SaveChanges();
|
||||
execurtion.UpdateTours(context, model);
|
||||
transaction.Commit();
|
||||
return execurtion.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ExecurtionViewModel? Delete(ExecurtionBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var element = context.Execurtions
|
||||
.Include(x => x.Tours)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Execurtions.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
111
TourCompanyDatabaseImplement/Implements/GidStorage.cs
Normal file
111
TourCompanyDatabaseImplement/Implements/GidStorage.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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.ViewModels;
|
||||
using TourCompanyDatabaseImplement;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
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.FIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Gids
|
||||
.Include(x => x.Execurtions)
|
||||
.ThenInclude(x => x.Execurtion)
|
||||
.Where(x => x.FIO.Contains(model.FIO))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public GidViewModel? GetElement(GidSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.FIO) && !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.FIO) && x.FIO == model.FIO) ||
|
||||
(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 gid = context.Gids.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (gid == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
gid.Update(model);
|
||||
context.SaveChanges();
|
||||
gid.UpdateExecurtions(context, model);
|
||||
transaction.Commit();
|
||||
return gid.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;
|
||||
}
|
||||
}
|
||||
}
|
111
TourCompanyDatabaseImplement/Implements/PlaceVisitStorage.cs
Normal file
111
TourCompanyDatabaseImplement/Implements/PlaceVisitStorage.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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.ViewModels;
|
||||
using TourCompanyDatabaseImplement;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
public class PlaceVisitStorage : IPlaceVisitStorage
|
||||
{
|
||||
public List<PlaceVisitViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.PlaceVisits
|
||||
.Include(x => x.Trips)
|
||||
.ThenInclude(x => x.Trip)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PlaceVisitViewModel> GetFilteredList(PlaceVisitSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PlaceVisitName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.PlaceVisits
|
||||
.Include(x => x.Trips)
|
||||
.ThenInclude(x => x.Trip)
|
||||
.Where(x => x.PlaceVisitName.Contains(model.PlaceVisitName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PlaceVisitViewModel? GetElement(PlaceVisitSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PlaceVisitName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.PlaceVisits
|
||||
.Include(x => x.Trips)
|
||||
.ThenInclude(x => x.Trip)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PlaceVisitName) && x.PlaceVisitName == model.PlaceVisitName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PlaceVisitViewModel? Insert(PlaceVisitBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var newPlaceVisit = PlaceVisit.Create(context, model);
|
||||
if (newPlaceVisit == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.PlaceVisits.Add(newPlaceVisit);
|
||||
context.SaveChanges();
|
||||
return newPlaceVisit.GetViewModel;
|
||||
}
|
||||
|
||||
public PlaceVisitViewModel? Update(PlaceVisitBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var placeVisit = context.PlaceVisits.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (placeVisit == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
placeVisit.Update(model);
|
||||
context.SaveChanges();
|
||||
placeVisit.UpdateTrips(context, model);
|
||||
transaction.Commit();
|
||||
return placeVisit.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public PlaceVisitViewModel? Delete(PlaceVisitBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var element = context.PlaceVisits
|
||||
.Include(x => x.Trips)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.PlaceVisits.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
111
TourCompanyDatabaseImplement/Implements/TourGroupStorage.cs
Normal file
111
TourCompanyDatabaseImplement/Implements/TourGroupStorage.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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.ViewModels;
|
||||
using TourCompanyDatabaseImplement;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
public class TourGroupStorage : ITourGroupStorage
|
||||
{
|
||||
public List<TourGroupViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.TourGroups
|
||||
.Include(x => x.Tours)
|
||||
.ThenInclude(x => x.Tour)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<TourGroupViewModel> GetFilteredList(TourGroupSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.TourGroupName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.TourGroups
|
||||
.Include(x => x.Tours)
|
||||
.ThenInclude(x => x.Tour)
|
||||
.Where(x => x.TourGroupName.Contains(model.TourGroupName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public TourGroupViewModel? GetElement(TourGroupSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.TourGroupName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.TourGroups
|
||||
.Include(x => x.Tours)
|
||||
.ThenInclude(x => x.Tour)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.TourGroupName) && x.TourGroupName == model.TourGroupName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public TourGroupViewModel? Insert(TourGroupBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var newTourGroup = TourGroup.Create(context, model);
|
||||
if (newTourGroup == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.TourGroups.Add(newTourGroup);
|
||||
context.SaveChanges();
|
||||
return newTourGroup.GetViewModel;
|
||||
}
|
||||
|
||||
public TourGroupViewModel? Update(TourGroupBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var tourGroup = context.TourGroups.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (tourGroup == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
tourGroup.Update(model);
|
||||
context.SaveChanges();
|
||||
tourGroup.UpdateTours(context, model);
|
||||
transaction.Commit();
|
||||
return tourGroup.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public TourGroupViewModel? Delete(TourGroupBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var element = context.TourGroups
|
||||
.Include(x => x.Tours)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.TourGroups.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
131
TourCompanyDatabaseImplement/Implements/TourStorage.cs
Normal file
131
TourCompanyDatabaseImplement/Implements/TourStorage.cs
Normal file
@ -0,0 +1,131 @@
|
||||
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.ViewModels;
|
||||
using TourCompanyDatabaseImplement;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
public class TourStorage : ITourStorage
|
||||
{
|
||||
public TourViewModel? Delete(TourBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
var element = context.Tours
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Tours.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public TourViewModel? GetElement(TourSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
return context.Tours
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<TourViewModel> GetFilteredList(TourSearchModel model)
|
||||
{
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
var result = GetElement(model);
|
||||
return result != null ? new() { result } : new();
|
||||
}
|
||||
|
||||
using var context = new TourCompanyDatabase();
|
||||
IQueryable<Tour>? queryWhere = null;
|
||||
/*
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
queryWhere = context.Tours
|
||||
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate.Date <= model.DateTo);
|
||||
}
|
||||
else */
|
||||
if (model.UserId.HasValue)
|
||||
{
|
||||
queryWhere = context.Tours.Where(x => x.UserId == model.UserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return queryWhere
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<TourViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
return context.Tours
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public TourViewModel? Insert(TourBindingModel model)
|
||||
{
|
||||
var newTour = Tour.Create(model);
|
||||
|
||||
if (newTour == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
context.Tours.Add(newTour);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Tours
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newTour.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public TourViewModel? Update(TourBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
var tour = context.Tours
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (tour == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
tour.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return tour.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
136
TourCompanyDatabaseImplement/Implements/TripStorage.cs
Normal file
136
TourCompanyDatabaseImplement/Implements/TripStorage.cs
Normal file
@ -0,0 +1,136 @@
|
||||
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.ViewModels;
|
||||
using TourCompanyDatabaseImplement;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
public class TripStorage : ITripStorage
|
||||
{
|
||||
public TripViewModel? Delete(TripBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
var element = context.Trips
|
||||
.Include(x => x.Gid)
|
||||
.Include(x => x.User)
|
||||
.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)
|
||||
.Include(x => x.User)
|
||||
.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 if (model.UserId.HasValue)
|
||||
{
|
||||
queryWhere = context.Trips.Where(x => x.UserId == model.UserId);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return queryWhere
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Gid)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<TripViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
return context.Trips
|
||||
.Include(x => x.User)
|
||||
.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.User)
|
||||
.FirstOrDefault(x => x.Id == newTrip.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public TripViewModel? Update(TripBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
|
||||
var order = context.Trips
|
||||
.Include(x => x.User)
|
||||
.Include(x => x.Gid)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
90
TourCompanyDatabaseImplement/Implements/UserStorage.cs
Normal file
90
TourCompanyDatabaseImplement/Implements/UserStorage.cs
Normal file
@ -0,0 +1,90 @@
|
||||
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;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TourCompanyContracts.StoragesContracts
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Users
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
//
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.FIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Users
|
||||
.Where(x => x.FIO.Contains(model.FIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
//
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
return context.Users
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
//
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
var newUser = User.Create(model);
|
||||
if (newUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TourCompanyDatabase();
|
||||
context.Users.Add(newUser);
|
||||
context.SaveChanges();
|
||||
return newUser.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var component = context.Users.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Users.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,13 +22,14 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public int GidId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public int TourId { get; set; }
|
||||
|
||||
public Dictionary<int, (ITourModel, decimal)>? _execurtionTours = null;
|
||||
public Dictionary<int, (IGidModel, string)>? _execurtionGids = null;
|
||||
public virtual List<GidExecurtion> Gids { get; set; } = new();
|
||||
public Dictionary<int, ITourModel>? _execurtionTours = null;
|
||||
//public Dictionary<int, (IGidModel, string)>? _execurtionGids = null;
|
||||
//public virtual List<GidExecurtion> Gids { get; set; } = new();
|
||||
public virtual List<ExecurtionTour> Tours { get; set; } = new();
|
||||
|
||||
/*
|
||||
public Dictionary<int, (IGidModel, string)> ExecurtionGids
|
||||
{
|
||||
get
|
||||
@ -41,14 +42,15 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
return _execurtionGids;
|
||||
}
|
||||
}
|
||||
public Dictionary<int, (ITourModel, decimal)> ExecurtionTours
|
||||
*/
|
||||
public Dictionary<int, ITourModel> ExecurtionTours
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_execurtionTours == null)
|
||||
{
|
||||
_execurtionTours = Tours
|
||||
.ToDictionary(recPC => recPC.TourId, recPC => (recPC.Tour as ITourModel, recPC.Tour.Price));
|
||||
.ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel);
|
||||
}
|
||||
return _execurtionTours;
|
||||
}
|
||||
@ -61,10 +63,9 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
Purpose = model.Purpose,
|
||||
Date = model.Date,
|
||||
UserId = model.UserId,
|
||||
Gids = model.ExecurtionGids.Select(x => new GidExecurtion
|
||||
Tours = model.ExecurtionTours.Select(x => new ExecurtionTour
|
||||
{
|
||||
Gid = context.Gids.First(y => y.Id == x.Key),
|
||||
GidFIO = x.Value.Item2
|
||||
Tour = context.Tours.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@ -84,10 +85,37 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
Purpose = Purpose,
|
||||
Date = Date,
|
||||
UserId = UserId,
|
||||
ExecurtionGids = ExecurtionGids
|
||||
ExecurtionTours = ExecurtionTours
|
||||
};
|
||||
}
|
||||
}
|
||||
public void UpdateTours(TourCompanyDatabase context, ExecurtionBindingModel model)
|
||||
{
|
||||
var execurtionTours = context.ExecurtionTours.Where(rec => rec.TourId == model.Id).ToList();
|
||||
if (execurtionTours != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ExecurtionTours.RemoveRange(execurtionTours.Where(rec => !model.ExecurtionTours.ContainsKey(rec.TourId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateTour in execurtionTours)
|
||||
{
|
||||
model.ExecurtionTours.Remove(updateTour.TourId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var execurtion = context.Execurtions.First(x => x.Id == Id);
|
||||
foreach (var pc in model.ExecurtionTours)
|
||||
{
|
||||
context.ExecurtionTours.Add(new ExecurtionTour
|
||||
{
|
||||
Execurtion = execurtion,
|
||||
Tour = context.Tours.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_execurtionTours = null;
|
||||
}
|
||||
/*
|
||||
public void UpdateGids(TourCompanyDatabase context, ExecurtionBindingModel model)
|
||||
{
|
||||
var execurtionGids = context.ExecurtionGids.Where(rec => rec.ExecurtionId == model.Id).ToList();
|
||||
@ -116,5 +144,6 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
}
|
||||
_execurtionGids = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public int ExecurtionId { get; set; }
|
||||
public DateTime dateExecurtion { get; set; }
|
||||
public virtual Tour Tour { get; set; } = new();
|
||||
|
||||
public virtual Execurtion Execurtion { get; set; } = new();
|
||||
|
@ -19,16 +19,17 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public int Experion { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)>? _gidExecurtions = null;
|
||||
public User User { get; set; }
|
||||
public Dictionary<int, (IExecurtionModel, int)>? _gidExecurtions = null;
|
||||
public virtual List<GidExecurtion> Execurtions { get; set; } = new();
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)> GidExecurtions
|
||||
public Dictionary<int, (IExecurtionModel, int)> GidExecurtions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_gidExecurtions == null)
|
||||
{
|
||||
_gidExecurtions = Execurtions
|
||||
.ToDictionary(recPC => recPC.ExecurtionId, recPC => (recPC.Execurtion as IExecurtionModel, recPC.dateExecurtion));
|
||||
.ToDictionary(recPC => recPC.ExecurtionId, recPC => (recPC.Execurtion as IExecurtionModel, recPC.Duratation));
|
||||
}
|
||||
return _gidExecurtions;
|
||||
}
|
||||
@ -44,7 +45,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
Execurtions = model.GidExecurtions.Select(x => new GidExecurtion
|
||||
{
|
||||
Execurtion = context.Execurtions.First(y => y.Id == x.Key),
|
||||
dateExecurtion = x.Value.Item2
|
||||
Duratation = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@ -71,14 +72,13 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public void UpdateExecurtions(TourCompanyDatabase context, GidBindingModel model)
|
||||
{
|
||||
var gidExecurtions = context.GidExecurtions.Where(rec => rec.GidId == model.Id).ToList();
|
||||
if (gidExecurtions != null && gidExecurtions.dateExecurtion != null)
|
||||
if (gidExecurtions != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.GidExecurtions.RemoveRange(gidExecurtions.Where(rec => !model.GidExecurtions.ContainsKey(rec.ExecurtionId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var UpdateExecurtion in gidExecurtions)
|
||||
{
|
||||
UpdateExecurtion.dateExecurtion = model.GidExecurtions[UpdateExecurtion.ExecurtionId].Item2;
|
||||
model.GidExecurtions.Remove(UpdateExecurtion.Id);
|
||||
}
|
||||
context.SaveChanges();
|
||||
@ -90,7 +90,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
Gid = gid,
|
||||
Execurtion = context.Execurtions.First(x => x.Id == pc.Key),
|
||||
dateExecurtion = pc.Value.Item2
|
||||
Duratation = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public int ExecurtionId { get; set; }
|
||||
public DateTime dateExecurtion { get; set; }
|
||||
//public DateTime DateExecurtion { get; set; }
|
||||
public int Duratation { get; set; }
|
||||
public virtual Gid Gid { get; set; } = new();
|
||||
|
||||
public virtual Execurtion Execurtion { get; set; } = new();
|
||||
|
@ -9,29 +9,30 @@ using TourCompanyDataModels.Models;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class PlaceVisit
|
||||
{
|
||||
public class PlaceVisit : IPlaceVisitModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string PlaceVisitName { get; set; } = string.Empty;
|
||||
public string TourGroupName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TourGroupId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
// Dictionary<ID, (Название, Цена)>
|
||||
public Dictionary<int, (ITripModel, decimal)>? _placeVisitTrips = null;
|
||||
public Dictionary<int, ITripModel>? _placeVisitTrips = null;
|
||||
public virtual List<PlaceVisitTrip> Trips { get; set; } = new();
|
||||
public Dictionary<int, (ITripModel, decimal)> PlaceVisitTrips
|
||||
public Dictionary<int, ITripModel> PlaceVisitTrips
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_placeVisitTrips == null)
|
||||
{
|
||||
_placeVisitTrips = Trips
|
||||
.ToDictionary(recPC => recPC.TripId, recPC => (recPC.Trip as ITripModel, recPC.Trip.Price));
|
||||
.ToDictionary(recPC => recPC.TripId, recPC => recPC.Trip as ITripModel);
|
||||
}
|
||||
return _placeVisitTrips;
|
||||
}
|
||||
@ -44,16 +45,16 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
PlaceVisitName = model.PlaceVisitName,
|
||||
Date = model.Date,
|
||||
UserId = model.UserId,
|
||||
TourGroupId = model.TourGroupId,
|
||||
Trips = model.PlaceVisitTrips.Select(x => new PlaceVisitTrip
|
||||
{
|
||||
Trip = context.Trips.First(y => y.Id == x.Key),
|
||||
Price = x.Value.Item2
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
public void Update(PlaceVisitBindingModel model)
|
||||
{
|
||||
PlaceVisitName = model.PlaceVisitName,;
|
||||
PlaceVisitName = model.PlaceVisitName;
|
||||
Date = model.Date;
|
||||
}
|
||||
public PlaceVisitViewModel GetViewModel
|
||||
@ -67,6 +68,8 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
PlaceVisitName = PlaceVisitName,
|
||||
Date = Date,
|
||||
UserId = UserId,
|
||||
TourGroupId = TourGroupId,
|
||||
TourGroupName = context.TourGroups.FirstOrDefault(x => x.Id == TourGroupId)?.TourGroupName ?? string.Empty,
|
||||
PlaceVisitTrips = PlaceVisitTrips
|
||||
};
|
||||
}
|
||||
@ -74,14 +77,13 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public void UpdateTrips(TourCompanyDatabase context, PlaceVisitBindingModel model)
|
||||
{
|
||||
var placeVisitTrips = context.PlaceVisitTrips.Where(rec => rec.PlaceVisitId == model.Id).ToList();
|
||||
if (placeVisitTrips != null && placeVisitTrips.Price != null)
|
||||
if (placeVisitTrips != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.PlaceVisitTrips.RemoveRange(placeVisitTrips.Where(rec => !model.PlaceVisitTrips.ContainsKey(rec.TripId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var UpdateTrip in placeVisitTrips)
|
||||
{
|
||||
UpdateTrip.Price = model.PlaceVisitTrips[UpdateTrip.TripId].Item2;
|
||||
model.PlaceVisitTrips.Remove(UpdateTrip.TripId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
@ -92,8 +94,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
context.PlaceVisitTrips.Add(new PlaceVisitTrip
|
||||
{
|
||||
PlaceVisit = placeVisit,
|
||||
Trip = context.Trips.First(x => x.Id == pc.Key),
|
||||
Price = pc.Value.Item2
|
||||
Trip = context.Trips.First(x => x.Id == pc.Key)
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
@ -1,12 +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
|
||||
{
|
||||
internal class PlaceVisitTrip
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ using TourCompanyDataModels.Models;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class Tour
|
||||
public class Tour : ITourModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -20,14 +20,17 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
/*
|
||||
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)>? _tourExecurtions = null;
|
||||
|
||||
public Dictionary<int, (ITourGroupModel, string)>? _tourTourGroups = null;
|
||||
public virtual List<TourGroupTour> TourGroups { get; set; } = new();
|
||||
public virtual List<ExecurtionTour> Execurtions { get; set; } = new();
|
||||
*/
|
||||
|
||||
public Dictionary<int, (IExecurtionModel, DateTime)> TourExecurtions
|
||||
/* public Dictionary<int, (IExecurtionModel, DateTime)> TourExecurtions
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -50,8 +53,8 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
}
|
||||
return _tourTourGroups;
|
||||
}
|
||||
}
|
||||
public static Tour Create(TourCompanyDatabase context, TourBindingModel model)
|
||||
} */
|
||||
public static Tour? Create(TourBindingModel? model)
|
||||
{
|
||||
return new Tour()
|
||||
{
|
||||
@ -59,20 +62,9 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
TourName = model.TourName,
|
||||
Price = model.Price,
|
||||
UserId = model.UserId,
|
||||
Execurtions = model.TourExecurtions.Select(x => new GidExecurtion
|
||||
{
|
||||
Execurtion = context.Execurtions.First(y => y.Id == x.Key),
|
||||
dateExecurtion = x.Value.Item2
|
||||
}).ToList(),
|
||||
TourGroups = model.TourTourGroups.Select(x => new TourGroupTour
|
||||
{
|
||||
TourGroup = context.TourGroups.First(y => y.Id == x.Key),
|
||||
TourGroupName = x.Value.Item2
|
||||
}).ToList()
|
||||
|
||||
};
|
||||
}
|
||||
public void Update(TourBindingModel model)
|
||||
public void Update(TourBindingModel? model)
|
||||
{
|
||||
TourName = model.TourName;
|
||||
Price = model.Price;
|
||||
@ -88,11 +80,13 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
TourName = TourName,
|
||||
Price = Price,
|
||||
UserId = UserId,
|
||||
TourExecurtions = TourExecurtions,
|
||||
TourTourGroups = TourTourGroups
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public void UpdateExecurtions(TourCompanyDatabase context, TourBindingModel model)
|
||||
{
|
||||
var tourExecurtions = context.TourExecurtions.Where(rec => rec.TourId == model.Id).ToList();
|
||||
@ -148,7 +142,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
context.SaveChanges();
|
||||
}
|
||||
_tourTourGroups = null;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,32 +7,31 @@ using TourCompanyDataModels.Enums;
|
||||
using TourCompanyDataModels.Models;
|
||||
using TourCompanyContracts.BindingModels;
|
||||
using TourCompanyContracts.ViewModels;
|
||||
using TourCompanyDataModels.Models;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class TourGroup : ITourGroupModel
|
||||
public class TourGroup : ITourGroupModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Number { get; set; } = string.Empty;
|
||||
public string TourGroupName { get; set; } = string.Empty;
|
||||
|
||||
public TourType Type { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (ITourModel, decimal)>? _tourGroupTours = null;
|
||||
public User User { get; set; }
|
||||
public Dictionary<int, ITourModel>? _tourGroupTours = null;
|
||||
public virtual List<TourGroupTour> Tours { get; set; } = new();
|
||||
public virtual List<User> Users { get; set; } = new();
|
||||
public Dictionary<int, (ITourModel, decimal)> TourGroupTours
|
||||
public Dictionary<int, ITourModel> TourGroupTours
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_tourGroupTours == null)
|
||||
{
|
||||
_tourGroupTours = Tours
|
||||
.ToDictionary(recPC => recPC.TourId, recPC => (recPC.Tour as ITourModel, recPC.Price));
|
||||
.ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel);
|
||||
}
|
||||
return _tourGroupTours;
|
||||
}
|
||||
@ -42,40 +41,39 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
return new TourGroup()
|
||||
{
|
||||
Id = model.Id,
|
||||
Number = model.Number,
|
||||
TourGroupName = model.TourGroupName,
|
||||
Type = model.Type,
|
||||
UserId = model.UserId,
|
||||
Tours = model.TourGroupTours.Select(x => new TourGroupTour{
|
||||
Tour = context.Tours.First(y => y.Id == x.Key),
|
||||
Price = x.Value.Item2
|
||||
Tour = context.Tours.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(TourGroupBindingModel model)
|
||||
{
|
||||
Number = model.Number;
|
||||
TourGroupName = model.TourGroupName;
|
||||
Type = model.Type;
|
||||
}
|
||||
public TourGroupViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Number = Number,
|
||||
TourGroupName = TourGroupName,
|
||||
Type = Type,
|
||||
UserId = UserId,
|
||||
TourGroupTours = TourGroupTours
|
||||
//UserFIO = context.Users.FirstOrDefault(x => x.Id == UserId)?.UserFIO ?? string.Empty,
|
||||
TourGroupTours = TourGroupTours
|
||||
};
|
||||
|
||||
public void UpdateTours(TourCompanyDatabase context, TourGroupBindingModel model)
|
||||
{
|
||||
var tourGroupTours = context.TourGroupTours.Where(rec => rec.TourId == model.Id).ToList();
|
||||
if (tourGroupTours != null && tourGroupTours.Price > 0)
|
||||
if (tourGroupTours != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.TourGroupTours.RemoveRange(tourGroupTours.Where(rec => !model.TourGroupTours.ContainsKey(rec.TourId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateTour in tourGroupTours)
|
||||
{
|
||||
updateTour.Price = model.TourGroupTours[updateTour.TourId].Item2;
|
||||
model.TourGroupTours.Remove(updateTour.TourId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
@ -87,8 +85,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
TourGroup = tourGroup,
|
||||
Tour = context.Tours.First(x => x.Id == pc.Key),
|
||||
Price = pc.Value.Item2
|
||||
});
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_tourGroupTours = null;
|
||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class TourGroupTour
|
||||
public class TourGroupTour
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -17,10 +17,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public int TourId { get; set; }
|
||||
public string TourGroupName { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public virtual TourGroup TourGroup { get; set; } = new();
|
||||
|
||||
public virtual Tour Tour { get; set; } = new();
|
||||
|
@ -1,12 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TourCompanyContracts.BindingModels;
|
||||
using TourCompanyContracts.ViewModels;
|
||||
using TourCompanyDataModels.Models;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class Trip
|
||||
public class Trip : ITripModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string TripName { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
public int GidId { get; set; }
|
||||
public Gid Gid { get; set; }
|
||||
/*
|
||||
public Dictionary<int, IPlaceVisitModel>? _tripPlaceVisits = null;
|
||||
public virtual List<PlaceVisitTrip> PlaceVisits { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IPlaceVisitModel> TripPlaceVisits
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_tripPlaceVisits == null)
|
||||
{
|
||||
_tripPlaceVisits = PlaceVisits
|
||||
.ToDictionary(recPC => recPC.PlaceVisitId, recPC => recPC.PlaceVisit as IPlaceVisitModel);
|
||||
}
|
||||
return _tripPlaceVisits;
|
||||
}
|
||||
}
|
||||
*/
|
||||
public static Trip? Create(TripBindingModel? model)
|
||||
{
|
||||
return new Trip()
|
||||
{
|
||||
Id = model.Id,
|
||||
TripName = model.TripName,
|
||||
Price = model.Price,
|
||||
Date = model.Date,
|
||||
GidId = model.GidId,
|
||||
UserId = model.UserId,
|
||||
/*
|
||||
PlaceVisits = model.TripPlaceVisits.Select(x => new PlaceVisitTrip
|
||||
{
|
||||
PlaceVisit = context.PlaceVisits.First(y => y.Id == x.Key),
|
||||
}).ToList(),
|
||||
*/
|
||||
};
|
||||
}
|
||||
public void Update(TripBindingModel? model)
|
||||
{
|
||||
TripName = model.TripName;
|
||||
Price = model.Price;
|
||||
Date = model.Date;
|
||||
}
|
||||
public TripViewModel GetViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
return new TripViewModel
|
||||
{
|
||||
Id = Id,
|
||||
TripName = TripName,
|
||||
Price = Price,
|
||||
Date = Date,
|
||||
GidId = GidId,
|
||||
UserId = UserId,
|
||||
//TripPlaceVisits = TripPlaceVisits
|
||||
};
|
||||
}
|
||||
}
|
||||
/*
|
||||
public void UpdatePlaceVisits(TourCompanyDatabase context, TripBindingModel model)
|
||||
{
|
||||
var tripPlaceVisits = context.TripPlaceVisits.Where(rec => rec.TripId == model.Id).ToList();
|
||||
if (tripPlaceVisits != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.TripPlaceVisits.RemoveRange(tripPlaceVisits.Where(rec => !model.TripPlaceVisits.ContainsKey(rec.PlaceVisitId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var UpdatePlaceVisit in tripPlaceVisits)
|
||||
{
|
||||
model.TripPlaceVisits.Remove(UpdatePlaceVisit.PlaceVisitId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var tour = context.Trips.First(x => x.Id == Id);
|
||||
foreach (var pc in model.TripPlaceVisits)
|
||||
{
|
||||
context.TripPlaceVisits.Add(new PlaceVisitTrip
|
||||
{
|
||||
Trip = tour,
|
||||
PlaceVisit = context.PlaceVisits.First(x => x.Id == pc.Key)
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_tripPlaceVisits = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,13 @@ 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
|
||||
{
|
||||
internal class User
|
||||
public class User : IUserModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -15,5 +18,46 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
public static User? Create(UserBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new User()
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public static User Create(UserViewModel model)
|
||||
{
|
||||
return new User
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public void Update(UserBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FIO = model.FIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
public UserViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FIO = FIO,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
||||
|
32
TourCompanyDatabaseImplement/TourCompanyDatabase.cs
Normal file
32
TourCompanyDatabaseImplement/TourCompanyDatabase.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using TourCompanyDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace TourCompanyDatabaseImplement
|
||||
{
|
||||
public class TourCompanyDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VTSC074\SQLEXPRESS;Initial Catalog=TourCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Tour> Tours { set; get; }
|
||||
public virtual DbSet<User> Users { set; get; }
|
||||
public virtual DbSet<Execurtion> Execurtions { set; get; }
|
||||
public virtual DbSet<Gid> Gids { set; get; }
|
||||
public virtual DbSet<PlaceVisit> PlaceVisits { set; get; }
|
||||
public virtual DbSet<Trip> Trips { set; get; }
|
||||
public virtual DbSet<TourGroup> TourGroups { set; get; }
|
||||
public virtual DbSet<ExecurtionTour> ExecurtionTours { set; get; }
|
||||
public virtual DbSet<GidExecurtion> GidExecurtions { set; get; }
|
||||
public virtual DbSet<PlaceVisitTrip> PlaceVisitTrips { set; get; }
|
||||
public virtual DbSet<TourGroupTour> TourGroupTours { set; get; }
|
||||
|
||||
}
|
||||
}
|
@ -10,6 +10,15 @@
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TourCompanyContracts\TourCompanyContracts.csproj" />
|
||||
<ProjectReference Include="..\TourCompanyDataModels\TourCompanyDataModels.csproj" />
|
||||
|
Loading…
Reference in New Issue
Block a user