Доделанный Implements для роли организатор

This commit is contained in:
AnnZhimol 2023-04-05 23:31:18 +04:00
parent ae008bcd89
commit 78405c4c7c
5 changed files with 211 additions and 16 deletions

View File

@ -4,5 +4,8 @@
{
public int? Id { get; set; }
public string? ConferenceName { get; set; }
public int? OrganiserId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -2,6 +2,8 @@
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace HotelDataBaseImplement.Implemets
{
@ -9,32 +11,149 @@ namespace HotelDataBaseImplement.Implemets
{
public ConferenceViewModel? Delete(ConferenceBindingModel model)
{
throw new NotImplementedException();
using var context = new HotelDataBase();
var element = context.Conferences
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Conferences.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ConferenceViewModel? GetElement(ConferenceSearchModel model)
{
throw new NotImplementedException();
if (!model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
return context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public List<ConferenceViewModel> GetFilteredList(ConferenceSearchModel model)
{
throw new NotImplementedException();
if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.OrganiserId.HasValue)
{
return new();
}
using var context = new HotelDataBase();
if (model.DateFrom.HasValue)
{
return context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.Where(x => x.StartDate >= model.DateFrom && x.StartDate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.OrganiserId.HasValue)
return context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.Where(x => x.OrganiserId == model.OrganiserId)
.Select(x => x.GetViewModel)
.ToList();
return context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ConferenceViewModel> GetFullList()
{
throw new NotImplementedException();
using var context = new HotelDataBase();
return context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.Select(x => x.GetViewModel)
.ToList();
}
public ConferenceViewModel? Insert(ConferenceBindingModel model)
{
throw new NotImplementedException();
using var context = new HotelDataBase();
var newConference = Conference.Create(context,model);
if (newConference == null)
{
return null;
}
context.Conferences.Add(newConference);
context.SaveChanges();
return context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.FirstOrDefault(x => x.Id == newConference.Id)
?.GetViewModel;
}
public ConferenceViewModel? Update(ConferenceBindingModel model)
{
throw new NotImplementedException();
using var context = new HotelDataBase();
var order = context.Conferences
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.MealPlanMember)
.ThenInclude(x => x.MealPlan)
.Include(x => x.ConferenceBookings)
.Include(x => x.Organiser)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
}
}
}

View File

@ -2,6 +2,8 @@
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace HotelDataBaseImplement.Implemets
{
@ -9,32 +11,103 @@ namespace HotelDataBaseImplement.Implemets
{
public MealPlanViewModel? Delete(MealPlanBindingModel model)
{
throw new NotImplementedException();
using var context = new HotelDataBase();
var element = context.MealPlans
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.MealPlans.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public MealPlanViewModel? GetElement(MealPlanSearchModel model)
{
throw new NotImplementedException();
if (!model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
return context.MealPlans
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.ConferenceMember)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.Include(x => x.Organiser)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public List<MealPlanViewModel> GetFilteredList(MealPlanSearchModel model)
{
throw new NotImplementedException();
if (string.IsNullOrEmpty(model.MealPlanName))
{
return new();
}
using var context = new HotelDataBase();
return context.MealPlans
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.ConferenceMember)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.Include(x => x.Organiser)
.Where(x => x.MealPlanName.Contains(model.MealPlanName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<MealPlanViewModel> GetFullList()
{
throw new NotImplementedException();
using var context = new HotelDataBase();
return context.MealPlans
.Include(x => x.Members)
.ThenInclude(x => x.Member)
.ThenInclude(x => x.ConferenceMember)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.Include(x => x.Organiser)
.Select(x => x.GetViewModel)
.ToList();
}
public MealPlanViewModel? Insert(MealPlanBindingModel model)
{
throw new NotImplementedException();
using var context = new HotelDataBase();
var newMealPlan = MealPlan.Create(context,model);
if (newMealPlan == null)
{
return null;
}
context.MealPlans.Add(newMealPlan);
context.SaveChanges();
return newMealPlan.GetViewModel;
}
public MealPlanViewModel? Update(MealPlanBindingModel model)
{
throw new NotImplementedException();
using var context = new HotelDataBase();
var mealPlan = context.MealPlans.FirstOrDefault(x => x.Id == model.Id);
if (mealPlan == null)
{
return null;
}
mealPlan.Update(model);
context.SaveChanges();
return mealPlan.GetViewModel;
}
}
}

View File

@ -12,7 +12,7 @@ namespace HotelDataBaseImplement.Models
[Required]
public int ConferenceId { get; set; }
public virtual Conference Conference { get; set; } = new();
public virtual Member Member { get; set; } = new();
public virtual Conference Conference { get; set; }
public virtual Member Member { get; set; }
}
}

View File

@ -12,7 +12,7 @@ namespace HotelDataBaseImplement.Models
[Required]
public int MealPlanId { get; set; }
public virtual MealPlan MealPlan { get; set; } = new();
public virtual Member Member { get; set; } = new();
public virtual MealPlan MealPlan { get; set; }
public virtual Member Member { get; set; }
}
}