dev #17

Merged
mfnefd merged 4 commits from dev into registration 2024-06-22 21:17:05 +04:00
10 changed files with 258 additions and 238 deletions
Showing only changes of commit 536a8bfe91 - Show all commits

View File

@ -11,5 +11,6 @@ namespace BusinessLogic.Tools.Mail
public IEnumerable<string> To { get; set; } = null!; public IEnumerable<string> To { get; set; } = null!;
public string Title { get; set; } = null!; public string Title { get; set; } = null!;
public string Body { get; set; } = null!; public string Body { get; set; } = null!;
public bool IsSendable { get; set; } = true;
} }
} }

View File

@ -25,6 +25,8 @@ namespace BusinessLogic.Tools.Mail
public static void Send(Mail mail) public static void Send(Mail mail)
{ {
if (!mail.IsSendable) return;
using SmtpClient client = new SmtpClient(_smtpClientHost, _smtpClientPort); using SmtpClient client = new SmtpClient(_smtpClientHost, _smtpClientPort);
client.Credentials = new NetworkCredential(_email, _password); client.Credentials = new NetworkCredential(_email, _password);
client.EnableSsl = true; client.EnableSsl = true;

View File

@ -12,6 +12,10 @@ namespace BusinessLogic.Tools.Mail.MailTemplates
{ {
public MailRegistration(UserBindingModel user) public MailRegistration(UserBindingModel user)
{ {
if (user.OnlyImportantMails)
{
IsSendable = false;
}
To = [user.Email]; To = [user.Email];
Title = "Приветствуем Вас на нашем сайте!"; Title = "Приветствуем Вас на нашем сайте!";
Body = $"Спасибо, {user.SecondName} {user.FirstName}, что выбрали НАС.\n" + Body = $"Спасибо, {user.SecondName} {user.FirstName}, что выбрали НАС.\n" +

View File

@ -15,6 +15,7 @@ namespace Contracts.BindingModels
public string PasswordHash { get; set; } = string.Empty; public string PasswordHash { get; set; } = string.Empty;
public string? Password { get; set; } public string? Password { get; set; }
public DateTime Birthday { get; set; } public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; }
public RoleBindingModel Role { get; set; } = null!; public RoleBindingModel Role { get; set; } = null!;
} }
} }

View File

@ -17,6 +17,7 @@ namespace Contracts.Converters
SecondName = model.SecondName, SecondName = model.SecondName,
Email = model.Email, Email = model.Email,
Birthday = model.Birthday, Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails,
Role = RoleConverter.ToView(model.Role), Role = RoleConverter.ToView(model.Role),
}; };
@ -27,6 +28,7 @@ namespace Contracts.Converters
SecondName = model.SecondName, SecondName = model.SecondName,
Email = model.Email, Email = model.Email,
Birthday = model.Birthday, Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails,
Role = RoleConverter.ToBinding(model.Role), Role = RoleConverter.ToBinding(model.Role),
}; };
} }

View File

@ -10,5 +10,6 @@ namespace Contracts.SearchModels
{ {
public Guid? Id { get; set; } public Guid? Id { get; set; }
public string? Email { get; set; } public string? Email { get; set; }
public bool? OnlyImportantMails { get; set; }
} }
} }

View File

@ -13,6 +13,7 @@ namespace Contracts.ViewModels
public string SecondName { get; set; } = string.Empty; public string SecondName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
public DateTime Birthday { get; set; } public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; }
public RoleViewModel Role { get; set; } = null!; public RoleViewModel Role { get; set; } = null!;
} }
} }

View File

@ -13,5 +13,6 @@ namespace DataModels.Models
string PasswordHash { get; } string PasswordHash { get; }
string Email { get; } string Email { get; }
DateTime Birthday { get; } DateTime Birthday { get; }
bool OnlyImportantMails { get; }
} }
} }

View File

@ -60,14 +60,15 @@ namespace DatabaseImplement.Implements
.Include(u => u.Role) .Include(u => u.Role)
.Select(r => r.GetBindingModel()); .Select(r => r.GetBindingModel());
} }
if (model.Id is null && model.Email is null) if (model.Id is null && model.Email is null && !model.OnlyImportantMails is null)
{ {
return []; return [];
} }
return context.Users return context.Users
.Where(u => .Where(u =>
(model.Id.HasValue && u.Id == model.Id) (model.Id.HasValue && u.Id == model.Id)
|| (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email))) || (!string.IsNullOrEmpty(u.Email) && u.Email.Contains(model.Email))
|| (model.OnlyImportantMails.HasValue && u.OnlyImportantMails == model.OnlyImportantMails))
.Include(u => u.Role) .Include(u => u.Role)
.Select(r => r.GetBindingModel()); .Select(r => r.GetBindingModel());
} }

View File

@ -4,6 +4,7 @@ using Contracts.ViewModels;
using DataModels.Models; using DataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -32,6 +33,8 @@ namespace DatabaseImplement.Models
public Role? Role { get; set; } public Role? Role { get; set; }
public bool OnlyImportantMails { get; set; } = false;
public UserBindingModel GetBindingModel() => new() public UserBindingModel GetBindingModel() => new()
{ {
Id = Id, Id = Id,
@ -40,6 +43,7 @@ namespace DatabaseImplement.Models
Email = Email, Email = Email,
PasswordHash = PasswordHash, PasswordHash = PasswordHash,
Birthday = Birthday, Birthday = Birthday,
OnlyImportantMails = OnlyImportantMails,
Role = Role?.GetBindingModel() ?? new() Role = Role?.GetBindingModel() ?? new()
}; };
@ -61,6 +65,7 @@ namespace DatabaseImplement.Models
Email = model.Email, Email = model.Email,
PasswordHash = model.PasswordHash, PasswordHash = model.PasswordHash,
Birthday = model.Birthday, Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails,
Role = role Role = role
}; };
@ -71,12 +76,13 @@ namespace DatabaseImplement.Models
throw new ArgumentNullException("Update user: binding model is null"); throw new ArgumentNullException("Update user: binding model is null");
} }
Email = model.Email; Email = model.Email ?? Email;
FirstName = model.FirstName; FirstName = model.FirstName ?? FirstName;
SecondName = model.SecondName; SecondName = model.SecondName ?? SecondName;
PasswordHash = model.PasswordHash; PasswordHash = model.PasswordHash ?? PasswordHash;
Birthday = model.Birthday; Birthday = model.Birthday;
Role = role; OnlyImportantMails = model.OnlyImportantMails;
Role = role ?? Role;
} }
} }
} }