молодой белый

This commit is contained in:
platoff aeeee 2024-04-30 21:58:21 +04:00
parent 32c00a42a6
commit 454dd5c594
17 changed files with 129 additions and 125 deletions

View File

@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDatabaseImplement.Models.ContractorModels;
using TravelCompanyDatabaseImplement.Models;
namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements
{

View File

@ -8,7 +8,7 @@ using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDatabaseImplement.Models.ContractorModels;
using TravelCompanyDatabaseImplement.Models;
namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements
{

View File

@ -8,7 +8,7 @@ using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDatabaseImplement.Models.ContractorModels;
using TravelCompanyDatabaseImplement.Models;
namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements
{

View File

@ -8,7 +8,7 @@ using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.SearchModels.Contractor;
using TravelCompanyContracts.StoragesModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDatabaseImplement.Models.ContractorModels;
using TravelCompanyDatabaseImplement.Models;
namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements
{

View File

@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDataModels.Models.Contractor;
namespace TravelCompanyDatabaseImplement.Models.ContractorModels
namespace TravelCompanyDatabaseImplement.Models
{
public class Contractor : IContractorModel
{

View File

@ -1,109 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDataModels.Models.Contractor;
using Microsoft.EntityFrameworkCore;
using TravelCompanyDatabaseImplement.Models.GuarantorModels;
namespace TravelCompanyDatabaseImplement.Models.ContractorModels
{
public class ExcursionGroup : IExcursionGroupModel
{
public int Id { get; set; }
[Required]
public string ExcursionGroupName { get; set; } = string.Empty;
[Required]
public int PeopleAmount { get; set; }
[Required]
public int ContractorID { get; set; }
[DeleteBehavior(DeleteBehavior.Restrict)]
public virtual Contractor Contractor { get; set; }}
private Dictionary<int, ITourModel>? _excursionGroupTours = null;
[NotMapped]
public Dictionary<int, ITourModel> ExcursionGroupTours
{
get
{
if (_excursionGroupTours == null)
{
_excursionGroupTours = Tours
.ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel);
}
return _excursionGroupTours;
}
}
[ForeignKey("ExcursionGroupId")]
public virtual List<ExcursionGroupTour> Tours { get; set; } = new();
public static ExcursionGroup? Create(TravelCompanyDatabase context, ExcursionGroupBindingModel? model)
{
if (model == null)
{
return null;
}
return new ExcursionGroup()
{
Id = model.Id,
ExcursionGroupName = model.ExcursionGroupName,
PeopleAmount = model.PeopleAmount,
ContractorID = model.ContractorID,
Tours = model.ExcursionGroupTours.Select(x => new ExcursionGroupTour
{
Tour = context.Tours.First(y => y.Id == x.Key)
}).ToList()
};
}
public void Update(ExcursionGroupBindingModel? model)
{
if (model == null)
{
return;
}
ExcursionGroupName = model.ExcursionGroupName;
PeopleAmount = model.PeopleAmount;
}
public ExcursionGroupViewModel GetViewModel => new()
{
Id = Id,
ExcursionGroupName = ExcursionGroupName,
PeopleAmount = PeopleAmount,
ContractorID = ContractorID,
ExcursionGroupTours = ExcursionGroupTours
};
public void UpdateTours(TravelCompanyDatabase context, ExcursionGroupBindingModel model)
{
var excursionGroupTours = context.ExcursionGroupTours.Where(rec => rec.ExcursionGroupId == model.Id).ToList();
if (excursionGroupTours != null && excursionGroupTours.Count > 0)
{
context.ExcursionGroupTours.RemoveRange(excursionGroupTours.Where(rec => !model.ExcursionGroupTours.ContainsKey(rec.TourId)));
context.SaveChanges();
}
var excursionGroup = context.ExcursionGroups.First(x => x.Id == Id);
foreach (var et in model.ExcursionGroupTours)
{
context.ExcursionGroupTours.Add(new ExcursionGroupTour
{
ExcursionGroup = excursionGroup,
Tour = context.Tours.First(x => x.Id == et.Key)
});
context.SaveChanges();
}
_excursionGroupTours = null;
}
}
}

View File

@ -11,7 +11,7 @@ using TravelCompanyDataModels.Models.Contractor;
using Microsoft.EntityFrameworkCore;
using TravelCompanyDatabaseImplement.Models.GuarantorModels;
namespace TravelCompanyDatabaseImplement.Models.ContractorModels
namespace TravelCompanyDatabaseImplement.Models
{
public class Excursion : IExcursionModel
{

View File

@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TravelCompanyContracts.BindingModels.Contractor;
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDataModels.Models.Contractor;
using Microsoft.EntityFrameworkCore;
using TravelCompanyDatabaseImplement.Models.GuarantorModels;
namespace TravelCompanyDatabaseImplement.Models
{
public class ExcursionGroup : IExcursionGroupModel
{
public int Id { get; set; }
[Required]
public string ExcursionGroupName { get; set; } = string.Empty;
[Required]
public int PeopleAmount { get; set; }
[Required]
public int ContractorID { get; set; }
[DeleteBehavior(DeleteBehavior.Restrict)]
public virtual Contractor Contractor { get; set; }
}
private Dictionary<int, ITourModel>? _excursionGroupTours = null;
[NotMapped]
public Dictionary<int, ITourModel> ExcursionGroupTours
{
get
{
if (_excursionGroupTours == null)
{
_excursionGroupTours = Tours
.ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel);
}
return _excursionGroupTours;
}
}
[ForeignKey("ExcursionGroupId")]
public virtual List<ExcursionGroupTour> Tours { get; set; } = new();
public static ExcursionGroup? Create(TravelCompanyDatabase context, ExcursionGroupBindingModel? model)
{
if (model == null)
{
return null;
}
return new ExcursionGroup()
{
Id = model.Id,
ExcursionGroupName = model.ExcursionGroupName,
PeopleAmount = model.PeopleAmount,
ContractorID = model.ContractorID,
Tours = model.ExcursionGroupTours.Select(x => new ExcursionGroupTour
{
Tour = context.Tours.First(y => y.Id == x.Key)
}).ToList()
};
}
public void Update(ExcursionGroupBindingModel? model)
{
if (model == null)
{
return;
}
ExcursionGroupName = model.ExcursionGroupName;
PeopleAmount = model.PeopleAmount;
}
public ExcursionGroupViewModel GetViewModel => new()
{
Id = Id,
ExcursionGroupName = ExcursionGroupName,
PeopleAmount = PeopleAmount,
ContractorID = ContractorID,
ExcursionGroupTours = ExcursionGroupTours
};
public void UpdateTours(TravelCompanyDatabase context, ExcursionGroupBindingModel model)
{
var excursionGroupTours = context.ExcursionGroupTours.Where(rec => rec.ExcursionGroupId == model.Id).ToList();
if (excursionGroupTours != null && excursionGroupTours.Count > 0)
{
context.ExcursionGroupTours.RemoveRange(excursionGroupTours.Where(rec => !model.ExcursionGroupTours.ContainsKey(rec.TourId)));
context.SaveChanges();
}
var excursionGroup = context.ExcursionGroups.First(x => x.Id == Id);
foreach (var et in model.ExcursionGroupTours)
{
context.ExcursionGroupTours.Add(new ExcursionGroupTour
{
ExcursionGroup = excursionGroup,
Tour = context.Tours.First(x => x.Id == et.Key)
});
context.SaveChanges();
}
_excursionGroupTours = null;
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
namespace TravelCompanyDatabaseImplement.Models.ContractorModels
namespace TravelCompanyDatabaseImplement.Models
{
public class ExcursionGroupTour
{

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
namespace TravelCompanyDatabaseImplement.Models.ContractorModels
namespace TravelCompanyDatabaseImplement.Models
{
public class ExcursionTour
{

View File

@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Guarantor;
using TravelCompanyContracts.ViewModels.Guarantor.ViewModels;
using TravelCompanyDataModels.Models.Guarantor;
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
namespace TravelCompanyDatabaseImplement.Models
{
public class Guarantor : IGuarantorModel
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
namespace TravelCompanyDatabaseImplement.Models
{
internal class Guide
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
namespace TravelCompanyDatabaseImplement.Models
{
internal class Place
{

View File

@ -10,7 +10,7 @@ using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
using TravelCompanyDataModels.Models.Contractor;
using Microsoft.EntityFrameworkCore;
namespace TravelCompanyDatabaseImplement.Models.ContractorModels
namespace TravelCompanyDatabaseImplement.Models
{
public class Tour : ITourModel
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
namespace TravelCompanyDatabaseImplement.Models
{
internal class Trip
{

View File

@ -3,11 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TravelCompanyDatabaseImplement.Models.ContractorModels;
using TravelCompanyDatabaseImplement.Models.GuarantorModels;
using Microsoft.EntityFrameworkCore;
using System.Security.Principal;
using TravelCompanyDatabaseImplement.Models;
namespace TravelCompanyDatabaseImplement
{

View File

@ -20,4 +20,9 @@
<ProjectReference Include="..\TravelCompanyDataModels\TravelCompanyDataModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\ContractorModels\" />
<Folder Include="Models\GuarantorModels\" />
</ItemGroup>
</Project>