refactoring, improvements, fixes, etc...
This commit is contained in:
parent
53b717ecf4
commit
d9f79bd474
|
|
@ -1,23 +0,0 @@
|
|||
using AyCode.Core.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using TIAM.Core.Interfaces;
|
||||
|
||||
namespace TIAM.Core;
|
||||
|
||||
public static class SerializeObjectToJsonExtensions
|
||||
{
|
||||
private static string SerializeObjectToJson<T>(T source)
|
||||
{
|
||||
JsonSerializerSettings options = new()
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
return JsonConvert.SerializeObject(source, options);
|
||||
}
|
||||
|
||||
public static string ToJson<T>(this T source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
||||
public static string ToJson<T>(this IQueryable<T> source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
||||
public static string ToJson<T>(this IEnumerable<T> source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
using AyCode.Database.DbSets.Users;
|
||||
using AyCode.Core.Extensions;
|
||||
using AyCode.Database.DbSets.Messages;
|
||||
using AyCode.Database.DbSets.Users;
|
||||
using AyCode.Models.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Core;
|
||||
|
|
@ -90,16 +92,15 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
|
||||
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
|
||||
|
||||
public UserModelDtoDetail? GetUserModelDtoDetailById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
|
||||
public Task<UserModelDtoDetail?> GetUserModelDtoDetailByIdAsync(Guid userId, bool onlyConfirmed) => SessionAsync(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
|
||||
public UserModelDtoDetail? GetUserModelDtoDetailByEmail(string email, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailByEmail(email, onlyConfirmed));
|
||||
|
||||
public TUserModelDto? GetUserModelDtoById<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
=> Session(ctx => ctx.GetUserModelDtoById<TUserModelDto>(userId, onlyConfirmed));
|
||||
=> Session(ctx => ctx.GetUserModelDtoById<TUserModelDto, User>(userId, onlyConfirmed));
|
||||
public Task<TUserModelDto?> GetUserModelDtoByIdAsync<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
=> SessionAsync(ctx => ctx.GetUserModelDtoById<TUserModelDto>(userId, onlyConfirmed));
|
||||
=> SessionAsync(ctx => ctx.GetUserModelDtoById<TUserModelDto, User>(userId, onlyConfirmed));
|
||||
|
||||
public UserModelDto? GetUserModelDtoByEmail(string email, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoByEmail(email, onlyConfirmed));
|
||||
public TUserModelDto? GetUserModelDtoByEmail<TUserModelDto>(string email, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
=> Session(ctx => ctx.GetUserModelDtoByEmail<TUserModelDto, User>(email, onlyConfirmed));
|
||||
public Task<TUserModelDto?> GetUserModelDtoByEmailAsync<TUserModelDto>(string email, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
=> SessionAsync(ctx => ctx.GetUserModelDtoByEmail<TUserModelDto, User>(email, onlyConfirmed));
|
||||
|
||||
public string? GetUserJsonById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserById(userId, onlyConfirmed)?.ToJson());
|
||||
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
|
||||
|
|
@ -202,8 +203,8 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
public Task<List<EmailMessage>> GetEmailMessagesByContextIdAsync(Guid contextId) => SessionAsync(ctx => ctx.GetEmailMessagesByContextId(contextId).ToList());
|
||||
public Task<List<EmailMessage>> GetEmailMessagesBySenderIdAsync(Guid senderId) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderId(senderId).ToList());
|
||||
public Task<List<EmailMessage>> GetEmailMessagesBySenderEmailAddressAsync(string emailAddress) => SessionAsync(ctx => ctx.GetEmailMessagesBySenderEmailAddress(emailAddress).ToList());
|
||||
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages(userId, userProductMappingId).ToList());
|
||||
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid contextId, Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages(contextId, userId, userProductMappingId).ToList());
|
||||
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages<EmailMessage, EmailRecipient>(userId, userProductMappingId).ToList());
|
||||
public Task<List<EmailMessage>> GetEmailMessagesAsync(Guid contextId, Guid userId, Guid userProductMappingId) => SessionAsync(ctx => ctx.GetEmailMessages<EmailMessage, EmailRecipient>(contextId, userId, userProductMappingId).ToList());
|
||||
|
||||
|
||||
public Task<bool> AddEmailMessageAsync(EmailMessage emailMessage)
|
||||
|
|
|
|||
|
|
@ -29,19 +29,6 @@ namespace TIAM.Database.DataLayers.Users
|
|||
{
|
||||
}
|
||||
|
||||
public UserModelDtoDetail? GetUserModelDtoDetailById(Guid userId, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
|
||||
public Task<UserModelDtoDetail?> GetUserModelDtoDetailByIdAsync(Guid userId, bool onlyConfirmed) => SessionAsync(ctx => ctx.GetUserModelDtoDetailById(userId, onlyConfirmed));
|
||||
public UserModelDtoDetail? GetUserModelDtoDetailByEmail(string email, bool onlyConfirmed) => Session(ctx => ctx.GetUserModelDtoDetailByEmail(email, onlyConfirmed));
|
||||
|
||||
public TUserModelDto? GetUserModelDtoById<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
=> Session(ctx => ctx.GetUserModelDtoById<TUserModelDto>(userId, onlyConfirmed));
|
||||
public Task<TUserModelDto?> GetUserModelDtoByIdAsync<TUserModelDto>(Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
=> SessionAsync(ctx => ctx.GetUserModelDtoById<TUserModelDto>(userId, onlyConfirmed));
|
||||
|
||||
public Task<UserModelDto?> GetUserModelDtoByEmailAsync(string email, bool onlyConfirmed) => SessionAsync(x => x.GetUserModelDtoByEmail(email, onlyConfirmed));
|
||||
public Task<List<UserModelDto>> GetAllUsersModelDtoAsync() => SessionAsync(x => x.GetAllUsersModelDto().ToList());
|
||||
public Task<List<UserModelDtoDetail>> GetAllUsersModelDtoDetailAsync() => SessionAsync(x => x.GetAllUsersModelDetailDto().ToList());
|
||||
|
||||
public async Task<bool> CreateUserAsync(User user)
|
||||
{
|
||||
Context.Users.Add(user);
|
||||
|
|
|
|||
|
|
@ -4,47 +4,47 @@ using TIAM.Entities.Products;
|
|||
|
||||
namespace TIAM.Database.DbSets.Emails;
|
||||
|
||||
public static class EmailMessageDbSetExtension
|
||||
{
|
||||
public static EmailMessage? GetEmailMessageById(this IEmailMessageDbSet ctx, Guid emailMessageId)
|
||||
=> ctx.EmailMessages.FirstOrDefault(x => x.Id == emailMessageId);
|
||||
//public static class EmailMessageDbSetExtension
|
||||
//{
|
||||
// public static EmailMessage? GetEmailMessageById(this IEmailMessageDbSet ctx, Guid emailMessageId)
|
||||
// => ctx.EmailMessages.FirstOrDefault(x => x.Id == emailMessageId);
|
||||
|
||||
public static IQueryable<EmailMessage> GetEmailMessagesByContextId(this IEmailMessageDbSet ctx, Guid contextId)
|
||||
=> ctx.EmailMessages.Where(x => x.ContextId == contextId);
|
||||
// public static IQueryable<EmailMessage> GetEmailMessagesByContextId(this IEmailMessageDbSet ctx, Guid contextId)
|
||||
// => ctx.EmailMessages.Where(x => x.ContextId == contextId);
|
||||
|
||||
public static IQueryable<EmailMessage> GetEmailMessagesBySenderId(this IEmailMessageDbSet ctx, Guid senderId)
|
||||
=> ctx.EmailMessages.Where(x => x.SenderId == senderId);
|
||||
// public static IQueryable<EmailMessage> GetEmailMessagesBySenderId(this IEmailMessageDbSet ctx, Guid senderId)
|
||||
// => ctx.EmailMessages.Where(x => x.SenderId == senderId);
|
||||
|
||||
public static IQueryable<EmailMessage> GetEmailMessagesBySenderEmailAddress(this IEmailMessageDbSet ctx, string senderEmailAddress)
|
||||
=> ctx.EmailMessages.Where(x => x.EmailAddress == senderEmailAddress);
|
||||
// public static IQueryable<EmailMessage> GetEmailMessagesBySenderEmailAddress(this IEmailMessageDbSet ctx, string senderEmailAddress)
|
||||
// => ctx.EmailMessages.Where(x => x.EmailAddress == senderEmailAddress);
|
||||
|
||||
private static IQueryable<EmailMessage> GetEmailMessages(this IQueryable<EmailMessage> queryableEmails, Guid userId, Guid userProductMappingId)
|
||||
=> queryableEmails.Where(x => x.SenderId == userId || x.SenderId == userProductMappingId || x.Recipients.Any(recipient => recipient.RecipientId == userId || recipient.RecipientId == userProductMappingId));
|
||||
// private static IQueryable<EmailMessage> GetEmailMessages(this IQueryable<EmailMessage> queryableEmails, Guid userId, Guid userProductMappingId)
|
||||
// => queryableEmails.Where(x => x.SenderId == userId || x.SenderId == userProductMappingId || x.Recipients.Any(recipient => recipient.RecipientId == userId || recipient.RecipientId == userProductMappingId));
|
||||
|
||||
public static IQueryable<EmailMessage> GetEmailMessages(this IEmailMessageDbSet ctx, Guid userId, Guid userProductMappingId)
|
||||
=> ctx.EmailMessages.GetEmailMessages(userId, userProductMappingId);
|
||||
// public static IQueryable<EmailMessage> GetEmailMessages(this IEmailMessageDbSet ctx, Guid userId, Guid userProductMappingId)
|
||||
// => ctx.EmailMessages.GetEmailMessages(userId, userProductMappingId);
|
||||
|
||||
public static IQueryable<EmailMessage> GetEmailMessages(this IEmailMessageDbSet ctx, Guid contextId, Guid userId, Guid userProductMappingId)
|
||||
=> ctx.GetEmailMessagesByContextId(contextId).GetEmailMessages(userId, userProductMappingId);
|
||||
// public static IQueryable<EmailMessage> GetEmailMessages(this IEmailMessageDbSet ctx, Guid contextId, Guid userId, Guid userProductMappingId)
|
||||
// => ctx.GetEmailMessagesByContextId(contextId).GetEmailMessages(userId, userProductMappingId);
|
||||
|
||||
#region Add, Update, Remove
|
||||
// #region Add, Update, Remove
|
||||
|
||||
public static bool AddEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
|
||||
=> ctx.EmailMessages.Add(emailMessage).State == EntityState.Added;
|
||||
// public static bool AddEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
|
||||
// => ctx.EmailMessages.Add(emailMessage).State == EntityState.Added;
|
||||
|
||||
public static bool UpdateEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
|
||||
=> ctx.EmailMessages.Update(emailMessage).State == EntityState.Modified;
|
||||
// public static bool UpdateEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
|
||||
// => ctx.EmailMessages.Update(emailMessage).State == EntityState.Modified;
|
||||
|
||||
public static bool RemoveEmailMessage(this IEmailMessageDbSet ctx, Guid emailMessageId)
|
||||
{
|
||||
var emailMessage = ctx.GetEmailMessageById(emailMessageId);
|
||||
// public static bool RemoveEmailMessage(this IEmailMessageDbSet ctx, Guid emailMessageId)
|
||||
// {
|
||||
// var emailMessage = ctx.GetEmailMessageById(emailMessageId);
|
||||
|
||||
return emailMessage == null || ctx.RemoveEmailMessage(emailMessage);
|
||||
}
|
||||
// return emailMessage == null || ctx.RemoveEmailMessage(emailMessage);
|
||||
// }
|
||||
|
||||
public static bool RemoveEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
|
||||
=> ctx.EmailMessages.Remove(emailMessage).State == EntityState.Deleted;
|
||||
// public static bool RemoveEmailMessage(this IEmailMessageDbSet ctx, EmailMessage emailMessage)
|
||||
// => ctx.EmailMessages.Remove(emailMessage).State == EntityState.Deleted;
|
||||
|
||||
#endregion Add, Update, Remove
|
||||
// #endregion Add, Update, Remove
|
||||
|
||||
}
|
||||
//}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using AyCode.Database.DbSets.Messages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Entities.Emails;
|
||||
using TIAM.Entities.Permissions;
|
||||
|
||||
namespace TIAM.Database.DbSets.Emails;
|
||||
|
||||
public interface IEmailMessageDbSet
|
||||
{
|
||||
public DbSet<EmailMessage> EmailMessages { get; set; }
|
||||
}
|
||||
public interface IEmailMessageDbSet : IAcEmailMessageDbSet<EmailMessage>
|
||||
{ }
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using AyCode.Database.DbSets.Users;
|
||||
using AyCode.Database.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAM.Models.Dtos.Users;
|
||||
|
|
@ -20,27 +21,4 @@ public static class UserDbSetExtensions
|
|||
|
||||
public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude)
|
||||
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email);
|
||||
|
||||
public static TUserModelDto? GetUserModelDtoById<TUserModelDto>(this IUserDbSet ctx, Guid userId, bool onlyConfirmed) where TUserModelDto : class, IUserModelDtoMinBase
|
||||
{
|
||||
var user = ctx.GetUsersById(userId, onlyConfirmed).FirstOrDefault();
|
||||
return Activator.CreateInstance(typeof(TUserModelDto), user) as TUserModelDto;
|
||||
}
|
||||
//=> ctx.GetUsersById(userId, onlyConfirmed).Select(user => new UserModelDto(user)).FirstOrDefault();
|
||||
|
||||
public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email, bool onlyConfirmed)
|
||||
=> ctx.GetUsersByEmail(email, onlyConfirmed).Select(user => new UserModelDto(user)).FirstOrDefault();
|
||||
|
||||
public static IQueryable<UserModelDto> GetAllUsersModelDto(this IUserDbSet ctx)
|
||||
=> ctx.Users.Select(user => new UserModelDto(user));
|
||||
|
||||
public static UserModelDtoDetail? GetUserModelDtoDetailById(this IUserDbSet ctx, Guid userId, bool onlyConfirmed)
|
||||
=> ctx.GetUsersById(userId, onlyConfirmed).Select(user => new UserModelDtoDetail(user)).FirstOrDefault();
|
||||
|
||||
public static UserModelDtoDetail? GetUserModelDtoDetailByEmail(this IUserDbSet ctx, string email, bool onlyConfirmed)
|
||||
=> ctx.GetUsersByEmail(email, onlyConfirmed).Select(user => new UserModelDtoDetail(user)).FirstOrDefault();
|
||||
|
||||
public static IQueryable<UserModelDtoDetail> GetAllUsersModelDetailDto(this IUserDbSet ctx)
|
||||
=> ctx.Users.Select(user => new UserModelDtoDetail(user));
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
namespace TIAM.Entities.Emails;
|
||||
using AyCode.Interfaces.Messages;
|
||||
|
||||
public interface IEmailMessageForeignKey<T>
|
||||
{
|
||||
public T EmailMessageId { get; set; }
|
||||
}
|
||||
namespace TIAM.Entities.Emails;
|
||||
|
||||
public interface IEmailMessageForeignKey : IEmailMessageForeignKey<Guid>
|
||||
public interface IEmailMessageForeignKey : IAcEmailMessageForeignKey
|
||||
{ }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
namespace TIAM.Entities.Emails;
|
||||
using AyCode.Interfaces.Messages;
|
||||
|
||||
public interface IEmailMessageRelation : IEmailMessageForeignKey
|
||||
{
|
||||
public EmailMessage EmailMessage{ get; set; }
|
||||
}
|
||||
namespace TIAM.Entities.Emails;
|
||||
|
||||
public interface IEmailMessageRelation : IEmailMessageRelation<EmailMessage>
|
||||
{ }
|
||||
|
||||
public interface IEmailMessageRelation<TEmailMessage> : IAcEmailMessageRelation<TEmailMessage>, IEmailMessageForeignKey where TEmailMessage : IAcEmailMessageBase
|
||||
{ }
|
||||
|
|
@ -1,6 +1,12 @@
|
|||
namespace TIAM.Entities.Emails;
|
||||
using AyCode.Entities.Messages;
|
||||
using AyCode.Interfaces.Messages;
|
||||
|
||||
public interface IEmailRecipientsRelation
|
||||
namespace TIAM.Entities.Emails;
|
||||
|
||||
public interface IEmailRecipientsRelation : IEmailRecipientsRelation<EmailRecipient>
|
||||
{
|
||||
}
|
||||
|
||||
public interface IEmailRecipientsRelation<TEmailRecipient> : IAcEmailRecipientsRelation<TEmailRecipient> where TEmailRecipient : IAcEmailRecipientBase
|
||||
{
|
||||
public List<EmailRecipient> Recipients { get; set; }
|
||||
}
|
||||
|
|
@ -1,7 +1,13 @@
|
|||
using AyCode.Interfaces.Messages;
|
||||
using AyCode.Entities.Messages;
|
||||
using AyCode.Interfaces.Messages;
|
||||
|
||||
namespace TIAM.Entities.Emails;
|
||||
|
||||
public interface IMessageSenderService : IAcMessageSenderService<EmailMessage, EmailRecipient>
|
||||
public interface IMessageSenderService : IMessageSenderService<EmailMessage, EmailRecipient>
|
||||
{}
|
||||
|
||||
public interface IMessageSenderService<TEmailMessage, TEmailRecipient> : IAcMessageSenderService<TEmailMessage, TEmailRecipient>
|
||||
where TEmailMessage : IAcEmailMessage<TEmailRecipient>
|
||||
where TEmailRecipient : IAcEmailRecipientBase
|
||||
{
|
||||
}
|
||||
|
|
@ -319,7 +319,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
userToCreate.Profile.Address.Latitude = null; //Math.Round(90 + rnd.NextDouble(), 8);
|
||||
userToCreate.Profile.Address.Longitude = null; //Math.Round(180 + rnd.NextDouble(), 8);
|
||||
result = await _userDal.AddUserAsync(userToCreate);
|
||||
guestUser = await _userDal.GetUserModelDtoDetailByIdAsync(userId, false);
|
||||
guestUser = await _userDal.GetUserModelDtoByIdAsync<UserModelDtoDetail>(userId, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +334,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
{
|
||||
//var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync();
|
||||
//return users;
|
||||
return _userDal.GetAllUsersModelDtoAsync();
|
||||
return _userDal.GetAllUserModelDtoAsync<UserModelDto>();
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -345,7 +345,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
Console.WriteLine("GetUsersWithDetails called");
|
||||
//var users = await _userDal.Ctx.Users.ToListAsync();//.GetUsersAsync();
|
||||
//return users;
|
||||
return _userDal.GetAllUsersModelDtoDetailAsync();
|
||||
return _userDal.GetAllUserModelDtoAsync<UserModelDtoDetail>();
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -356,7 +356,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
Logger.Info($"GetUserByEmail called with email: {email}");
|
||||
Console.WriteLine($@"GetUserByEmail called with email: {email}");
|
||||
|
||||
return _userDal.GetUserModelDtoByEmailAsync(email, false);
|
||||
return _userDal.GetUserModelDtoByEmailAsync<UserModelDto>(email, false);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -374,7 +374,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
public Task<UserModelDtoDetail?> GetUserDetailById([FromBody] Guid id)
|
||||
{
|
||||
Logger.Info($"GetUserDetailById called with id: {id}");
|
||||
return _userDal.GetUserModelDtoDetailByIdAsync(id, true);
|
||||
return _userDal.GetUserModelDtoByIdAsync<UserModelDtoDetail>(id, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue