молодой белый
This commit is contained in:
parent
c751e67f1b
commit
654f87f888
@ -11,8 +11,8 @@ namespace TravelCompanyContracts.SearchModels.Guarantor
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string NamePlace { get; set; } = string.Empty;
|
||||
public string? NamePlace { get; set; } = string.Empty;
|
||||
|
||||
public string DescriptionPlace { get; set; } = string.Empty;
|
||||
public string? DescriptionPlace { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace TravelCompanyContracts.SearchModels.Guarantor
|
||||
{
|
||||
internal class TripSearchModel
|
||||
public class TripSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? TripName { get; set; } = string.Empty;
|
||||
public DateTime? TripDate { get; set; }
|
||||
public int? GuarantorID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyContracts.BindingModels;
|
||||
using TravelCompanyContracts.BindingModels.Guarantor;
|
||||
using TravelCompanyContracts.SearchModels.Guarantor;
|
||||
using TravelCompanyContracts.ViewModels.Guarantor.ViewModels;
|
||||
|
||||
@ -18,10 +18,10 @@ namespace TravelCompanyContracts.StoragesModels.Guarantor
|
||||
|
||||
GuarantorViewModel? GetElement(GuarantorSearchModel model);
|
||||
|
||||
GuarantorViewModel? Insert(GuarantorSearchModel model);
|
||||
GuarantorViewModel? Insert(GuarantorBindingModel model);
|
||||
|
||||
GuarantorViewModel? Update(GuarantorSearchModel model);
|
||||
GuarantorViewModel? Update(GuarantorBindingModel model);
|
||||
|
||||
GuarantorViewModel? Delete(GuarantorSearchModel model);
|
||||
GuarantorViewModel? Delete(GuarantorBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyContracts.BindingModels;
|
||||
using TravelCompanyContracts.BindingModels.Guarantor;
|
||||
using TravelCompanyContracts.SearchModels.Guarantor;
|
||||
using TravelCompanyContracts.ViewModels.Guarantor.ViewModels;
|
||||
|
||||
@ -18,10 +19,10 @@ namespace TravelCompanyContracts.StoragesModels.Guarantor
|
||||
|
||||
GuideViewModel? GetElement(GuideSearchModel model);
|
||||
|
||||
GuideViewModel? Insert(GuideSearchModel model);
|
||||
GuideViewModel? Insert(GuideBindingModel model);
|
||||
|
||||
GuideViewModel? Update(GuideSearchModel model);
|
||||
GuideViewModel? Update(GuideBindingModel model);
|
||||
|
||||
GuideViewModel? Delete(GuideSearchModel model);
|
||||
GuideViewModel? Delete(GuideBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyContracts.BindingModels.Guarantor;
|
||||
using TravelCompanyContracts.SearchModels.Guarantor;
|
||||
using TravelCompanyContracts.ViewModels.Guarantor.ViewModels;
|
||||
|
||||
@ -17,10 +18,10 @@ namespace TravelCompanyContracts.StoragesModels.Guarantor
|
||||
|
||||
PlaceViewModel? GetElement(PlaceSearchModel model);
|
||||
|
||||
PlaceViewModel? Insert(PlaceSearchModel model);
|
||||
PlaceViewModel? Insert(PlaceBindingModel model);
|
||||
|
||||
PlaceViewModel? Update(PlaceSearchModel model);
|
||||
PlaceViewModel? Update(PlaceBindingModel model);
|
||||
|
||||
PlaceViewModel? Delete(PlaceSearchModel model);
|
||||
PlaceViewModel? Delete(PlaceBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,24 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyContracts.BindingModels.Guarantor;
|
||||
using TravelCompanyContracts.SearchModels.Guarantor;
|
||||
using TravelCompanyContracts.ViewModels.Guarantor.ViewModels;
|
||||
|
||||
namespace TravelCompanyContracts.StoragesModels.Guarantor
|
||||
{
|
||||
internal class ITripStorage
|
||||
public interface ITripStorage
|
||||
{
|
||||
List<TripViewModel> GetFullList();
|
||||
|
||||
List<TripViewModel> GetFilteredList(TripSearchModel model);
|
||||
|
||||
TripViewModel? GetElement(TripSearchModel model);
|
||||
|
||||
TripViewModel? Insert(TripBindingModel model);
|
||||
|
||||
TripViewModel? Update(TripBindingModel model);
|
||||
|
||||
TripViewModel? Delete(TripBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,108 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TravelCompanyContracts.BindingModels.Contractor;
|
||||
using TravelCompanyContracts.BindingModels.Guarantor;
|
||||
using TravelCompanyContracts.SearchModels.Contractor;
|
||||
using TravelCompanyContracts.SearchModels.Guarantor;
|
||||
using TravelCompanyContracts.StoragesModels.Guarantor;
|
||||
using TravelCompanyContracts.ViewModels.Contractor.ViewModels;
|
||||
using TravelCompanyContracts.ViewModels.Guarantor.ViewModels;
|
||||
using TravelCompanyDatabaseImplement.Models;
|
||||
using TravelCompanyDatabaseImplement.Models.ContractorModels;
|
||||
|
||||
namespace TravelCompanyDatabaseImplement.Implements.GuarantorImplements
|
||||
{
|
||||
internal class GuarantorStorage
|
||||
public class GuarantorStorage : IGuarantorStorage
|
||||
{
|
||||
public List<GuarantorViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TravelCompanyDatabase();
|
||||
return context.Guarantors
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TravelCompanyDatabase();
|
||||
return context.Guarantors
|
||||
.Where(x => x.Surname.Contains(model.Surname))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public GuarantorViewModel? GetElement(GuarantorSearchModel model)
|
||||
{
|
||||
using var context = new TravelCompanyDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Guarantors
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return context.Guarantors
|
||||
.FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return context.Guarantors
|
||||
.FirstOrDefault(x => x.Email.Equals(model.Email))
|
||||
?.GetViewModel;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.MobilePhone))
|
||||
{
|
||||
return context.Guarantors
|
||||
.FirstOrDefault(x => x.MobilePhone.Equals(model.MobilePhone))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GuarantorViewModel? Insert(GuarantorBindingModel model)
|
||||
{
|
||||
var newGuarantor = Guarantor.Create(model);
|
||||
if (newGuarantor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TravelCompanyDatabase();
|
||||
context.Guarantors.Add(newGuarantor);
|
||||
context.SaveChanges();
|
||||
return newGuarantor.GetViewModel;
|
||||
}
|
||||
|
||||
public GuarantorViewModel? Update(GuarantorBindingModel model)
|
||||
{
|
||||
using var context = new TravelCompanyDatabase();
|
||||
var guarantor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (guarantor == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
guarantor.Update(model);
|
||||
context.SaveChanges();
|
||||
return guarantor.GetViewModel;
|
||||
}
|
||||
|
||||
public GuarantorViewModel? Delete(GuarantorBindingModel model)
|
||||
{
|
||||
using var context = new TravelCompanyDatabase();
|
||||
var element = context.Guarantors.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Guarantors.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
@ -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
|
||||
{
|
@ -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
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
|
||||
namespace TravelCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class Guide
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
|
||||
namespace TravelCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class Place
|
||||
{
|
@ -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
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TravelCompanyDatabaseImplement.Models.GuarantorModels
|
||||
namespace TravelCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class Trip
|
||||
{
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user