:)
This commit is contained in:
parent
a186d4c3cd
commit
31b6c507a0
BIN
.vs/ProjectEvaluation/sportcompetitions.metadata.v7.bin
Normal file
BIN
.vs/ProjectEvaluation/sportcompetitions.metadata.v7.bin
Normal file
Binary file not shown.
BIN
.vs/ProjectEvaluation/sportcompetitions.projects.v7.bin
Normal file
BIN
.vs/ProjectEvaluation/sportcompetitions.projects.v7.bin
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -10,6 +10,7 @@ namespace SportCompetitionsContracts.BindingModels
|
|||||||
public class ResultBindingModel : IResultModel
|
public class ResultBindingModel : IResultModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public string? ResultName { get; set; }
|
||||||
public int CompetitionId { get; set; }
|
public int CompetitionId { get; set; }
|
||||||
public int TeamId { get; set; }
|
public int TeamId { get; set; }
|
||||||
public int ResultPosition { get; set; }
|
public int ResultPosition { get; set; }
|
||||||
|
@ -9,5 +9,6 @@ namespace SportCompetitionsContracts.SearchModels
|
|||||||
public class ResultSearchModel
|
public class ResultSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
public string ResultName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ namespace SportCompetitionsContracts.ViewModels
|
|||||||
public class ResultViewModel : IResultModel
|
public class ResultViewModel : IResultModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название результата")]
|
||||||
|
public string? ResultName { get; set; }
|
||||||
[DisplayName("Соревнование")]
|
[DisplayName("Соревнование")]
|
||||||
public int CompetitionId { get; set; }
|
public int CompetitionId { get; set; }
|
||||||
[DisplayName("Команда")]
|
[DisplayName("Команда")]
|
||||||
|
Binary file not shown.
@ -8,6 +8,7 @@ namespace SportCompetitionsDataModels.Models
|
|||||||
{
|
{
|
||||||
public interface IResultModel : IId
|
public interface IResultModel : IId
|
||||||
{
|
{
|
||||||
|
string ResultName { get; set; }
|
||||||
int CompetitionId { get; set; }
|
int CompetitionId { get; set; }
|
||||||
int TeamId { get; set; }
|
int TeamId { get; set; }
|
||||||
int ResultPosition { get; set; }
|
int ResultPosition { get; set; }
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
using SportCompetitionsContracts.BindingModels;
|
||||||
|
using SportCompetitionsContracts.SearchModels;
|
||||||
|
using SportCompetitionsContracts.StoragesContracts;
|
||||||
|
using SportCompetitionsContracts.ViewModels;
|
||||||
|
using SportCompetitionsDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SportCompetitionsDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class CompetitionStorage : ICompetitionStorage
|
||||||
|
{
|
||||||
|
public List<CompetitionViewModel> GetFilteredList(CompetitionSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.CompetitionName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Competitions.Where(x => x.CompetitionName.Contains(model.CompetitionName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CompetitionViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Competitions.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompetitionViewModel? Delete(CompetitionBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var element = context.Competitions.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Competitions.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompetitionViewModel? GetElement(CompetitionSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Competitions.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CompetitionName)) && x.CompetitionName == model.CompetitionName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompetitionViewModel? Insert(CompetitionBindingModel model)
|
||||||
|
{
|
||||||
|
var newCompetition = Competition.Create(model);
|
||||||
|
if (newCompetition == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
context.Competitions.Add(newCompetition);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newCompetition.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompetitionViewModel? Update(CompetitionBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var component = context.Competitions.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using SportCompetitionsContracts.BindingModels;
|
||||||
|
using SportCompetitionsContracts.SearchModels;
|
||||||
|
using SportCompetitionsContracts.StoragesContracts;
|
||||||
|
using SportCompetitionsContracts.ViewModels;
|
||||||
|
using SportCompetitionsDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SportCompetitionsDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class MemberStorage : IMemberStorage
|
||||||
|
{
|
||||||
|
public List<MemberViewModel> GetFilteredList(MemberSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.MemberFCs))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Members.Where(x => x.MemberFCs.Contains(model.MemberFCs)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MemberViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Members.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberViewModel? Delete(MemberBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var element = context.Members.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Members.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberViewModel? GetElement(MemberSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Members.FirstOrDefault(x => (!string.IsNullOrEmpty(model.MemberFCs)) && x.MemberFCs == model.MemberFCs || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberViewModel? Insert(MemberBindingModel model)
|
||||||
|
{
|
||||||
|
var newMember = Member.Create(model);
|
||||||
|
if (newMember == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
context.Members.Add(newMember);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newMember.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberViewModel? Update(MemberBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var component = context.Members.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using SportCompetitionsContracts.BindingModels;
|
||||||
|
using SportCompetitionsContracts.SearchModels;
|
||||||
|
using SportCompetitionsContracts.StoragesContracts;
|
||||||
|
using SportCompetitionsContracts.ViewModels;
|
||||||
|
using SportCompetitionsDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SportCompetitionsDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class RecordStorage : IRecordStorage
|
||||||
|
{
|
||||||
|
public RecordViewModel? Delete(RecordBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var element = context.Records.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Records.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecordViewModel? GetElement(RecordSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Records.FirstOrDefault(x => (!string.IsNullOrEmpty(model.RecordName.ToString())) && x.RecordName.ToString() == model.RecordName.ToString() || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RecordViewModel> GetFilteredList(RecordSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.RecordName.ToString()))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Records.Where(x => x.RecordName.ToString().Contains(model.RecordName.ToString())).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RecordViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Records.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecordViewModel? Insert(RecordBindingModel model)
|
||||||
|
{
|
||||||
|
var newRecord = Record.Create(model);
|
||||||
|
if (newRecord == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
context.Records.Add(newRecord);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newRecord.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecordViewModel? Update(RecordBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var component = context.Records.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using SportCompetitionsContracts.BindingModels;
|
||||||
|
using SportCompetitionsContracts.SearchModels;
|
||||||
|
using SportCompetitionsContracts.StoragesContracts;
|
||||||
|
using SportCompetitionsContracts.ViewModels;
|
||||||
|
using SportCompetitionsDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SportCompetitionsDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ResultStorage : IResultStorage
|
||||||
|
{
|
||||||
|
public ResultViewModel? Delete(ResultBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var element = context.Results.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Results.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultViewModel? GetElement(ResultSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Results.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ResultName)) && x.ResultName == model.ResultName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ResultViewModel> GetFilteredList(ResultSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ResultName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Results.Where(x => x.ResultName.Contains(model.ResultName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ResultViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Results.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultViewModel? Insert(ResultBindingModel model)
|
||||||
|
{
|
||||||
|
var newResult = Result.Create(model);
|
||||||
|
if (newResult == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
context.Results.Add(newResult);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newResult.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultViewModel? Update(ResultBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var component = context.Results.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
77
SportCompetitionsDatabaseImplement/Implements/TeamStorage.cs
Normal file
77
SportCompetitionsDatabaseImplement/Implements/TeamStorage.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using SportCompetitionsContracts.BindingModels;
|
||||||
|
using SportCompetitionsContracts.SearchModels;
|
||||||
|
using SportCompetitionsContracts.StoragesContracts;
|
||||||
|
using SportCompetitionsContracts.ViewModels;
|
||||||
|
using SportCompetitionsDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SportCompetitionsDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class TeamStorage : ITeamStorage
|
||||||
|
{
|
||||||
|
public List<TeamViewModel> GetFilteredList(TeamSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.TeamName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Teams.Where(x => x.TeamName.Contains(model.TeamName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TeamViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Teams.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeamViewModel? Delete(TeamBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var element = context.Teams.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Teams.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeamViewModel? GetElement(TeamSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
return context.Teams.FirstOrDefault(x => (!string.IsNullOrEmpty(model.TeamName)) && x.TeamName == model.TeamName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeamViewModel? Insert(TeamBindingModel model)
|
||||||
|
{
|
||||||
|
var newTeam = Team.Create(model);
|
||||||
|
if (newTeam == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
context.Teams.Add(newTeam);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newTeam.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeamViewModel? Update(TeamBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new SportCompetitionsDatabase();
|
||||||
|
var component = context.Teams.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,8 @@ namespace SportCompetitionsDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
public string? ResultName { get; set; }
|
||||||
|
[Required]
|
||||||
public int CompetitionId { get; set; }
|
public int CompetitionId { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int TeamId { get; set; }
|
public int TeamId { get; set; }
|
||||||
@ -26,6 +28,7 @@ namespace SportCompetitionsDatabaseImplement.Models
|
|||||||
return new Result()
|
return new Result()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
|
ResultName = model.ResultName,
|
||||||
CompetitionId = model.CompetitionId,
|
CompetitionId = model.CompetitionId,
|
||||||
TeamId = model.TeamId,
|
TeamId = model.TeamId,
|
||||||
ResultPosition = model.ResultPosition,
|
ResultPosition = model.ResultPosition,
|
||||||
@ -35,6 +38,7 @@ namespace SportCompetitionsDatabaseImplement.Models
|
|||||||
public void Update(ResultBindingModel model)
|
public void Update(ResultBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null) return;
|
if (model == null) return;
|
||||||
|
ResultName = model.ResultName;
|
||||||
CompetitionId = model.CompetitionId;
|
CompetitionId = model.CompetitionId;
|
||||||
TeamId = model.TeamId;
|
TeamId = model.TeamId;
|
||||||
ResultPosition = model.ResultPosition;
|
ResultPosition = model.ResultPosition;
|
||||||
@ -43,6 +47,7 @@ namespace SportCompetitionsDatabaseImplement.Models
|
|||||||
public ResultViewModel GetViewModel => new()
|
public ResultViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
ResultName = ResultName,
|
||||||
CompetitionId = CompetitionId,
|
CompetitionId = CompetitionId,
|
||||||
TeamId = TeamId,
|
TeamId = TeamId,
|
||||||
ResultPosition = ResultPosition
|
ResultPosition = ResultPosition
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user