Main
This commit is contained in:
parent
bed8ee9b95
commit
48fefe4fb7
@ -24,7 +24,7 @@ namespace TourCompanyContracts.BindingModels
|
||||
|
||||
public int TuorId { get; set; }
|
||||
|
||||
public Dictionary<int, ITourModel> ExecurtionTours { get; set; } = new();
|
||||
public Dictionary<int, IGidModel> ExecurtionGids { get; set; } = new();
|
||||
public Dictionary<int, (ITourModel, decimal)> ExecurtionTours { get; set; } = new();
|
||||
public Dictionary<int, (IGidModel, string)> ExecurtionGids { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace TourCompanyContracts.BindingModels
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IPlaceVisitModel, int)> TripPlaceVisits
|
||||
public Dictionary<int, (IPlaceVisitModel, string)> TripPlaceVisits
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -20,7 +20,7 @@ namespace TourCompanyContracts.ViewModels
|
||||
public int UserId { get; set; }
|
||||
public int TourId { get; set; }
|
||||
|
||||
public Dictionary<int, ITourModel> ExecurtionTours { get; set; } = new();
|
||||
public Dictionary<int, IGidModel> ExecurtionGids { get; set; } = new();
|
||||
public Dictionary<int, (ITourModel, decimal)> ExecurtionTours { get; set; } = new();
|
||||
public Dictionary<int, (IGidModel, string)> ExecurtionGids { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace TourCompanyContracts.ViewModels
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IPlaceVisitModel, int)> TripPlaceVisits
|
||||
public Dictionary<int, (IPlaceVisitModel, string)> TripPlaceVisits
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using TourCompanyContracts.BindingModels;
|
||||
using TourCompanyContracts.ViewModels;
|
||||
using TourCompanyDataModels.Models;
|
||||
@ -22,31 +24,31 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public int UserId { get; set; }
|
||||
public int TourId { get; set; }
|
||||
|
||||
public Dictionary<int, ITourModel>? _execurtionTours = null;
|
||||
public Dictionary<int, IGidModel>? _execurtionGids = null;
|
||||
public Dictionary<int, (ITourModel, decimal)>? _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> ExecurtionGids
|
||||
public Dictionary<int, (IGidModel, string)> ExecurtionGids
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_execurtionGids == null)
|
||||
{
|
||||
_execurtionGids = Gids
|
||||
.ToDictionary(recPC => recPC.GidId, recPC => recPC.Gid as IGidModel);
|
||||
.ToDictionary(recPC => recPC.GidId, recPC => (recPC.Gid as IGidModel, recPC.Gid.FIO));
|
||||
}
|
||||
return _execurtionGids;
|
||||
}
|
||||
}
|
||||
public Dictionary<int, ITourModel> ExecurtionTours
|
||||
public Dictionary<int, (ITourModel, decimal)> ExecurtionTours
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_execurtionTours == null)
|
||||
{
|
||||
_execurtionTours = Tours
|
||||
.ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel);
|
||||
.ToDictionary(recPC => recPC.TourId, recPC => (recPC.Tour as ITourModel, recPC.Tour.Price));
|
||||
}
|
||||
return _execurtionTours;
|
||||
}
|
||||
@ -61,7 +63,8 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
UserId = model.UserId,
|
||||
Gids = model.ExecurtionGids.Select(x => new GidExecurtion
|
||||
{
|
||||
Gid = context.Gids.First(y => y.Id == x.Key)
|
||||
Gid = context.Gids.First(y => y.Id == x.Key),
|
||||
GidFIO = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
@ -88,15 +91,15 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public void UpdateGids(TourCompanyDatabase context, ExecurtionBindingModel model)
|
||||
{
|
||||
var execurtionGids = context.ExecurtionGids.Where(rec => rec.ExecurtionId == model.Id).ToList();
|
||||
if (execurtionGids != null && execurtionGids.dateExecurtion != null)
|
||||
if (execurtionGids != null && execurtionGids.GidFIO != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ExecurtionGids.RemoveRange(execurtionGids.Where(rec => !model.ExecurtionGids.ContainsKey(rec.GidId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var UpdateExecurtion in execurtionGids)
|
||||
foreach (var UpGidFIO in execurtionGids)
|
||||
{
|
||||
UpdateExecurtion.dateExecurtion = model.ExecurtionGids[UpdateExecurtion.GidId].Item2;
|
||||
model.ExecurtionGids.Remove(UpdateExecurtion.GidId);
|
||||
UpGidFIO.GidFIO = model.ExecurtionGids[UpGidFIO.GidId].Item2;
|
||||
model.ExecurtionGids.Remove(UpGidFIO.GidId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
@ -106,7 +109,8 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
context.ExecurtionGids.Add(new GidExecurtion
|
||||
{
|
||||
Execurtion = execurtion,
|
||||
Gid = context.Gids.First(x => x.Id == pc.Key)
|
||||
Gid = context.Gids.First(x => x.Id == pc.Key),
|
||||
GidFIO = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public int GidId { get; set; }
|
||||
public string GidFIO { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ExecurtionId { get; set; }
|
||||
|
@ -3,10 +3,101 @@ 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 PlaceVisit
|
||||
public class PlaceVisit
|
||||
{
|
||||
}
|
||||
public int Id { get; set; }
|
||||
|
||||
public string PlaceVisitName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TourGroupId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
// Dictionary<ID, (Название, Цена)>
|
||||
public Dictionary<int, (ITripModel, decimal)>? _placeVisitTrips = null;
|
||||
public virtual List<PlaceVisitTrip> Trips { get; set; } = new();
|
||||
public Dictionary<int, (ITripModel, decimal)> PlaceVisitTrips
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_placeVisitTrips == null)
|
||||
{
|
||||
_placeVisitTrips = Trips
|
||||
.ToDictionary(recPC => recPC.TripId, recPC => (recPC.Trip as ITripModel, recPC.Trip.Price));
|
||||
}
|
||||
return _placeVisitTrips;
|
||||
}
|
||||
}
|
||||
public static PlaceVisit Create(TourCompanyDatabase context, PlaceVisitBindingModel model)
|
||||
{
|
||||
return new PlaceVisit()
|
||||
{
|
||||
Id = model.Id,
|
||||
PlaceVisitName = model.PlaceVisitName,
|
||||
Date = model.Date,
|
||||
UserId = model.UserId,
|
||||
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,;
|
||||
Date = model.Date;
|
||||
}
|
||||
public PlaceVisitViewModel GetViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
using var context = new TourCompanyDatabase();
|
||||
return new PlaceVisitViewModel
|
||||
{
|
||||
Id = Id,
|
||||
PlaceVisitName = PlaceVisitName,
|
||||
Date = Date,
|
||||
UserId = UserId,
|
||||
PlaceVisitTrips = PlaceVisitTrips
|
||||
};
|
||||
}
|
||||
}
|
||||
public void UpdateTrips(TourCompanyDatabase context, PlaceVisitBindingModel model)
|
||||
{
|
||||
var placeVisitTrips = context.PlaceVisitTrips.Where(rec => rec.PlaceVisitId == model.Id).ToList();
|
||||
if (placeVisitTrips != null && placeVisitTrips.Price != 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();
|
||||
}
|
||||
var placeVisit = context.PlaceVisits.First(x => x.Id == Id);
|
||||
foreach (var pc in model.PlaceVisitTrips)
|
||||
{
|
||||
context.PlaceVisitTrips.Add(new PlaceVisitTrip
|
||||
{
|
||||
PlaceVisit = placeVisit,
|
||||
Trip = context.Trips.First(x => x.Id == pc.Key),
|
||||
Price = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_placeVisitTrips = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
TourCompanyDatabaseImplement/Models/PlaceVisitTrip.cs
Normal file
12
TourCompanyDatabaseImplement/Models/PlaceVisitTrip.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class PlaceVisitTrip
|
||||
{
|
||||
}
|
||||
}
|
@ -124,7 +124,7 @@ namespace TourCompanyDatabaseImplement.Models
|
||||
public void UpdateTourGroups(TourCompanyDatabase context, TourBindingModel model)
|
||||
{
|
||||
var tourTourGroups = context.TourTourGroups.Where(rec => rec.TourId == model.Id).ToList();
|
||||
if (tourTourGroups != null && tourTourGroups.dateExecurtion != null)
|
||||
if (tourTourGroups != null && tourTourGroups.TourGroupName != null)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.TourTourGroups.RemoveRange(tourTourGroups.Where(rec => !model.TourTourGroups.ContainsKey(rec.TourGroupId)));
|
||||
context.SaveChanges();
|
||||
|
12
TourCompanyDatabaseImplement/Models/Trip.cs
Normal file
12
TourCompanyDatabaseImplement/Models/Trip.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TourCompanyDatabaseImplement.Models
|
||||
{
|
||||
internal class Trip
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user