feat: add view models for all entities
This commit is contained in:
@@ -8,6 +8,7 @@ using Client.Domain.Entities;
|
||||
using Client.Domain.Enums;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ValueObjects;
|
||||
using Client.Domain.ViewModels;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
@@ -23,15 +24,18 @@ namespace Client.Domain.Service
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
messages.Add(message);
|
||||
mainViewModel.AddChatMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public ChatMessageHandler(EntityFactoryInterface<ChatMessage> factory)
|
||||
public ChatMessageHandler(EntityFactoryInterface<ChatMessage> factory, MainViewModelInterface mainViewModel)
|
||||
{
|
||||
this.factory = factory;
|
||||
this.mainViewModel = mainViewModel;
|
||||
}
|
||||
|
||||
private readonly EntityFactoryInterface<ChatMessage> factory;
|
||||
private readonly MainViewModelInterface mainViewModel;
|
||||
private List<ChatMessage> messages = new List<ChatMessage>();
|
||||
}
|
||||
}
|
||||
|
30
Client/Domain/Service/DropHandler.cs
Normal file
30
Client/Domain/Service/DropHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class PlayerHandler : EntityHandler<Player>
|
||||
{
|
||||
public override void OnCreate(Player entity)
|
||||
{
|
||||
mainViewModel.AddPlayer(entity);
|
||||
}
|
||||
public override void OnDelete(Player entity)
|
||||
{
|
||||
mainViewModel.RemovePlayer(entity);
|
||||
}
|
||||
|
||||
public PlayerHandler(EntityFactoryInterface<Player> factory, MainViewModelInterface mainViewModel) : base(factory)
|
||||
{
|
||||
this.mainViewModel = mainViewModel;
|
||||
}
|
||||
|
||||
private readonly MainViewModelInterface mainViewModel;
|
||||
}
|
||||
}
|
@@ -23,13 +23,14 @@ namespace Client.Domain.Service
|
||||
}
|
||||
entities[entity.Id] = entity;
|
||||
|
||||
|
||||
OnCreate(entity);
|
||||
}
|
||||
else if (operation == MessageOperationEnum.Update)
|
||||
{
|
||||
if (entity != null && entities.ContainsKey(entity.Id))
|
||||
{
|
||||
factory.Update(entities[entity.Id], content);
|
||||
OnUpdate(entity);
|
||||
}
|
||||
}
|
||||
else if (operation == MessageOperationEnum.Delete)
|
||||
@@ -37,10 +38,26 @@ namespace Client.Domain.Service
|
||||
if (entity != null)
|
||||
{
|
||||
entities.Remove(entity.Id);
|
||||
OnDelete(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnCreate(T entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void OnUpdate(T entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void OnDelete(T entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EntityHandler(EntityFactoryInterface<T> factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
|
30
Client/Domain/Service/HeroHandler.cs
Normal file
30
Client/Domain/Service/HeroHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class HeroHandler : EntityHandler<Hero>
|
||||
{
|
||||
public override void OnCreate(Hero entity)
|
||||
{
|
||||
mainViewModel.CreateHero(entity);
|
||||
}
|
||||
public override void OnDelete(Hero entity)
|
||||
{
|
||||
mainViewModel.DeleteHero();
|
||||
}
|
||||
|
||||
public HeroHandler(EntityFactoryInterface<Hero> factory, MainViewModelInterface mainViewModel) : base(factory)
|
||||
{
|
||||
this.mainViewModel = mainViewModel;
|
||||
}
|
||||
|
||||
private readonly MainViewModelInterface mainViewModel;
|
||||
}
|
||||
}
|
30
Client/Domain/Service/NpcHandler.cs
Normal file
30
Client/Domain/Service/NpcHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class NpcHandler : EntityHandler<NPC>
|
||||
{
|
||||
public override void OnCreate(NPC entity)
|
||||
{
|
||||
mainViewModel.AddNpc(entity);
|
||||
}
|
||||
public override void OnDelete(NPC entity)
|
||||
{
|
||||
mainViewModel.RemoveNpc(entity);
|
||||
}
|
||||
|
||||
public NpcHandler(EntityFactoryInterface<NPC> factory, MainViewModelInterface mainViewModel) : base(factory)
|
||||
{
|
||||
this.mainViewModel = mainViewModel;
|
||||
}
|
||||
|
||||
private readonly MainViewModelInterface mainViewModel;
|
||||
}
|
||||
}
|
30
Client/Domain/Service/PlayerHandler.cs
Normal file
30
Client/Domain/Service/PlayerHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Client.Domain.Entities;
|
||||
using Client.Domain.Factories;
|
||||
using Client.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public class DropHandler : EntityHandler<Drop>
|
||||
{
|
||||
public override void OnCreate(Drop entity)
|
||||
{
|
||||
mainViewModel.AddDrop(entity);
|
||||
}
|
||||
public override void OnDelete(Drop entity)
|
||||
{
|
||||
mainViewModel.RemoveDrop(entity);
|
||||
}
|
||||
|
||||
public DropHandler(EntityFactoryInterface<Drop> factory, MainViewModelInterface mainViewModel) : base(factory)
|
||||
{
|
||||
this.mainViewModel = mainViewModel;
|
||||
}
|
||||
|
||||
private readonly MainViewModelInterface mainViewModel;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user