MemberStorage и OrganiserStorage
This commit is contained in:
parent
90bb9a77db
commit
1450cceaa6
@ -2,6 +2,8 @@
|
|||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace HotelDataBaseImplement.Implemets
|
namespace HotelDataBaseImplement.Implemets
|
||||||
{
|
{
|
||||||
@ -9,32 +11,105 @@ namespace HotelDataBaseImplement.Implemets
|
|||||||
{
|
{
|
||||||
public MemberViewModel? Delete(MemberBindingModel model)
|
public MemberViewModel? Delete(MemberBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
var element = context.Members.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Members.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemberViewModel? GetElement(MemberSearchModel model)
|
public MemberViewModel? GetElement(MemberSearchModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (string.IsNullOrEmpty(model.MemberFIO) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
return context.Members
|
||||||
|
.Include(x => x.ConferenceMember)
|
||||||
|
.ThenInclude(x => x.Conference)
|
||||||
|
.Include(x => x.MealPlanMember)
|
||||||
|
.ThenInclude(x => x.MealPlan)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.MemberFIO) && x.MemberFIO == model.MemberFIO) || (model.Id.HasValue && x.Id == model.Id))?
|
||||||
|
.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MemberViewModel> GetFilteredList(MemberSearchModel model)
|
public List<MemberViewModel> GetFilteredList(MemberSearchModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (string.IsNullOrEmpty(model.MemberFIO))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
return context.Members
|
||||||
|
.Include(x => x.ConferenceMember)
|
||||||
|
.ThenInclude(x => x.Conference)
|
||||||
|
.Include(x => x.MealPlanMember)
|
||||||
|
.ThenInclude(x => x.MealPlan)
|
||||||
|
.Where(x => x.MemberFIO.Contains(model.MemberFIO))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MemberViewModel> GetFullList()
|
public List<MemberViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
return context.Members
|
||||||
|
.Include(x => x.ConferenceMember)
|
||||||
|
.ThenInclude(x => x.Conference)
|
||||||
|
.Include(x => x.MealPlanMember)
|
||||||
|
.ThenInclude(x => x.MealPlan)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemberViewModel? Insert(MemberBindingModel model)
|
public MemberViewModel? Insert(MemberBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
var newMember = Member.Create(model);
|
||||||
|
|
||||||
|
if (newMember == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Members.Add(newMember);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return newMember.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemberViewModel? Update(MemberBindingModel model)
|
public MemberViewModel? Update(MemberBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
var member = context.Members.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (member == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
member.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return member.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace HotelDataBaseImplement.Implemets
|
namespace HotelDataBaseImplement.Implemets
|
||||||
{
|
{
|
||||||
@ -9,32 +11,112 @@ namespace HotelDataBaseImplement.Implemets
|
|||||||
{
|
{
|
||||||
public OrganiserViewModel? Delete(OrganiserBindingModel model)
|
public OrganiserViewModel? Delete(OrganiserBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
var element = context.Organisers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Organisers.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrganiserViewModel? GetElement(OrganiserSearchModel model)
|
public OrganiserViewModel? GetElement(OrganiserSearchModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
return context.Organisers
|
||||||
|
.Include(x => x.MealPlans)
|
||||||
|
.Include(x => x.Members)
|
||||||
|
.Include(x => x.Conferences)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?
|
||||||
|
.GetViewModel;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(model.OrganiserLogin) && !string.IsNullOrEmpty(model.OrganiserPassword))
|
||||||
|
return context.Organisers
|
||||||
|
.Include(x => x.MealPlans)
|
||||||
|
.Include(x => x.Members)
|
||||||
|
.Include(x => x.Conferences)
|
||||||
|
.FirstOrDefault(x => x.OrganiserLogin.Equals(model.OrganiserLogin) && x.OrganiserPassword.Equals(model.OrganiserPassword))?
|
||||||
|
.GetViewModel;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(model.OrganiserLogin))
|
||||||
|
return context.Organisers
|
||||||
|
.Include(x => x.MealPlans)
|
||||||
|
.Include(x => x.Members)
|
||||||
|
.Include(x => x.Conferences)
|
||||||
|
.FirstOrDefault(x => x.OrganiserLogin.Equals(model.OrganiserLogin))?
|
||||||
|
.GetViewModel;
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrganiserViewModel> GetFilteredList(OrganiserSearchModel model)
|
public List<OrganiserViewModel> GetFilteredList(OrganiserSearchModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (string.IsNullOrEmpty(model.OrganiserFIO))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
return context.Organisers
|
||||||
|
.Include(x => x.MealPlans)
|
||||||
|
.Include(x => x.Members)
|
||||||
|
.Include(x => x.Conferences)
|
||||||
|
.Where(x => x.OrganiserLogin.Contains(model.OrganiserLogin) && x.OrganiserPassword == model.OrganiserPassword)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrganiserViewModel> GetFullList()
|
public List<OrganiserViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
return context.Organisers
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrganiserViewModel? Insert(OrganiserBindingModel model)
|
public OrganiserViewModel? Insert(OrganiserBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var newOrganiser = Organiser.Create(model);
|
||||||
|
|
||||||
|
if (newOrganiser == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
context.Organisers.Add(newOrganiser);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return newOrganiser.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrganiserViewModel? Update(OrganiserBindingModel model)
|
public OrganiserViewModel? Update(OrganiserBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
var organiser = context.Organisers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
if (organiser == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
organiser.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return organiser.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user