بلاخره تموم شد
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
namespace VizhTalk.BuildingBlocks.Domain.Contract;
|
||||
|
||||
public abstract record CommandBase<T> : ICommand<T>
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
protected CommandBase()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
}
|
||||
protected CommandBase(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract record CommandBase : ICommand
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
protected CommandBase()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
}
|
||||
protected CommandBase(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
public interface ICommand<out TResult>
|
||||
{
|
||||
Guid Id { get; }
|
||||
}
|
||||
|
||||
public interface ICommand
|
||||
{
|
||||
Guid Id { get; }
|
||||
}
|
||||
|
||||
@@ -37,4 +37,9 @@ public abstract class Entity<T>
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDeleted(bool val)
|
||||
=> IsDeleted = val;
|
||||
|
||||
public void SetActive(bool val)
|
||||
=> IsActive = val;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using VizhTalk.BuildingBlocks.Domain.Contract;
|
||||
|
||||
namespace VizhTalk.BuildingBlocks.Domain.Exceptions.GuardExceptions
|
||||
{
|
||||
public class MaxLengthException(string name, int length)
|
||||
: Exception($"The {name} field cannot be longer than {length} characters."), IGuardException
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,6 @@ using VizhTalk.BuildingBlocks.Domain.Contract;
|
||||
|
||||
namespace VizhTalk.BuildingBlocks.Domain.Exceptions.GuardExceptions;
|
||||
|
||||
public class NullOrEmptyException(string message) : Exception(message), IGuardException
|
||||
public class NullOrEmptyException(string name) : Exception($"{name} cannot be empty"), IGuardException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -4,5 +4,8 @@
|
||||
{
|
||||
public static void NullOrEmpty(this string value, string name)
|
||||
=> StringGuard.NullOrEmpty(value, name);
|
||||
|
||||
public static void MaxLength(this string value, string name, int length)
|
||||
=> StringGuard.MaxLength(value, length, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,15 @@ namespace VizhTalk.BuildingBlocks.Domain.Guards;
|
||||
|
||||
internal static class StringGuard
|
||||
{
|
||||
internal static void NullOrEmpty(string value,string name)
|
||||
internal static void NullOrEmpty(string value, string name)
|
||||
{
|
||||
if(string.IsNullOrEmpty(value))
|
||||
throw new NullOrEmptyException($"{name} cannot be empty");
|
||||
if (string.IsNullOrEmpty(value))
|
||||
throw new NullOrEmptyException(name);
|
||||
}
|
||||
internal static void MaxLength(string value, int length, string name)
|
||||
{
|
||||
if (value.Length > length)
|
||||
throw new MaxLengthException(name, length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
namespace VizhTalk.BuildingBlocks.Domain;
|
||||
|
||||
public interface IRepositoryBase<TDomain, TId>
|
||||
where TDomain : Entity<TId> where TId : ITypeIdValueBase
|
||||
public interface IRepositoryBase<T,TId>
|
||||
where T : Entity<TId> where TId : ITypeIdValueBase
|
||||
{
|
||||
Task<TDomain> CreateAsync(TDomain entity, CancellationToken cancellationToken = default);
|
||||
Task<TDomain> UpdateAsync(TDomain entity, CancellationToken cancellationToken = default);
|
||||
Task DeleteAsync(TId id, CancellationToken cancellationToken = default);
|
||||
Task<TDomain> GetByIdAsync(TId id, CancellationToken cancellationToken = default);
|
||||
Task<T> AddAsync(T entity,CancellationToken cancellationToken = default);
|
||||
Task UpdateAsync(T entity,CancellationToken cancellationToken = default);
|
||||
Task DeleteAsync(T entity,CancellationToken cancellationToken = default);
|
||||
Task DeleteById(TId id,CancellationToken cancellationToken = default);
|
||||
Task<T?> GetById(TId id,CancellationToken cancellationToken = default);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace VizhTalk.BuildingBlocks.Domain;
|
||||
using System;
|
||||
|
||||
namespace VizhTalk.BuildingBlocks.Domain;
|
||||
|
||||
public abstract class TypedIdValueBase<T> : IEquatable<TypedIdValueBase<T>> , ITypeIdValueBase
|
||||
{
|
||||
@@ -35,6 +37,11 @@ public abstract class TypedIdValueBase<T> : IEquatable<TypedIdValueBase<T>> , IT
|
||||
return EqualityComparer<T>.Default.Equals(this.Value, other.Value);
|
||||
}
|
||||
|
||||
public bool Equals(ITypeIdValueBase? other)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static bool operator ==(TypedIdValueBase<T>? obj1, TypedIdValueBase<T>? obj2)
|
||||
{
|
||||
if (object.Equals(obj1, null))
|
||||
|
||||
@@ -31,6 +31,7 @@ public abstract class ValueObject : IEquatable<ValueObject>
|
||||
return !(obj1 == obj2);
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(ValueObject? obj)
|
||||
{
|
||||
return Equals(obj as object);
|
||||
|
||||
Reference in New Issue
Block a user