Merge pull request 'dev' (#17) from dev into registration

Reviewed-on: #17
This commit is contained in:
mfnefd 2024-06-22 21:17:04 +04:00
commit 116e501d63
15 changed files with 1055 additions and 238 deletions

View File

@ -11,5 +11,6 @@ namespace BusinessLogic.Tools.Mail
public IEnumerable<string> To { get; set; } = null!;
public string Title { 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)
{
if (!mail.IsSendable) return;
using SmtpClient client = new SmtpClient(_smtpClientHost, _smtpClientPort);
client.Credentials = new NetworkCredential(_email, _password);
client.EnableSsl = true;

View File

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

View File

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

View File

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

View File

@ -10,5 +10,6 @@ namespace Contracts.SearchModels
{
public Guid? Id { 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 Email { get; set; } = string.Empty;
public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; }
public RoleViewModel Role { get; set; } = null!;
}
}

View File

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

View File

@ -60,14 +60,15 @@ namespace DatabaseImplement.Implements
.Include(u => u.Role)
.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 context.Users
.Where(u =>
(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)
.Select(r => r.GetBindingModel());
}

View File

@ -0,0 +1,326 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240622162300_second")]
partial class second
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,221 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class second : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "OnlyImportantMails",
table: "Users",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.CreateTable(
name: "MediaFiles",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Location = table.Column<string>(type: "text", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MediaFiles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
Rate = table.Column<double>(type: "double precision", nullable: false),
IsBeingSold = table.Column<bool>(type: "boolean", nullable: false),
Amount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Purchases",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DatePurchase = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Purchases", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sells",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
DateSell = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Sells", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Suppliers",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Deals = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Suppliers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SupplierProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SupplierId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SupplierProducts", x => x.Id);
table.ForeignKey(
name: "FK_SupplierProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SupplierProducts_Suppliers_SupplierId",
column: x => x.SupplierId,
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Supplies",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
SupplierId = table.Column<Guid>(type: "uuid", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Supplies", x => x.Id);
table.ForeignKey(
name: "FK_Supplies_Suppliers_SupplierId",
column: x => x.SupplierId,
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SupplyProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SupplyId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SupplyProducts", x => x.Id);
table.ForeignKey(
name: "FK_SupplyProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SupplyProducts_Supplies_SupplyId",
column: x => x.SupplyId,
principalTable: "Supplies",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_SupplierProducts_ProductId",
table: "SupplierProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_SupplierProducts_SupplierId",
table: "SupplierProducts",
column: "SupplierId");
migrationBuilder.CreateIndex(
name: "IX_Supplies_SupplierId",
table: "Supplies",
column: "SupplierId");
migrationBuilder.CreateIndex(
name: "IX_SupplyProducts_ProductId",
table: "SupplyProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_SupplyProducts_SupplyId",
table: "SupplyProducts",
column: "SupplyId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MediaFiles");
migrationBuilder.DropTable(
name: "Purchases");
migrationBuilder.DropTable(
name: "Sells");
migrationBuilder.DropTable(
name: "SupplierProducts");
migrationBuilder.DropTable(
name: "SupplyProducts");
migrationBuilder.DropTable(
name: "Products");
migrationBuilder.DropTable(
name: "Supplies");
migrationBuilder.DropTable(
name: "Suppliers");
migrationBuilder.DropColumn(
name: "OnlyImportantMails",
table: "Users");
}
}
}

View File

@ -22,6 +22,72 @@ namespace DatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
@ -37,6 +103,115 @@ namespace DatabaseImplement.Migrations
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
@ -54,6 +229,9 @@ namespace DatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
@ -72,6 +250,55 @@ namespace DatabaseImplement.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
@ -80,6 +307,16 @@ namespace DatabaseImplement.Migrations
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}

View File

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

View File

@ -74,6 +74,13 @@
</label>
</div>
<div class="form-check d-flex justify-content-center mb-4">
<input asp-for="UserModel.OnlyImportantMails" class="form-check-input me-2" type="checkbox" id="policy" />
<label class="form-check-label" for="policy">
Send only important mails
</label>
</div>
<!-- Submit button -->
<button type="submit" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary btn-block mb-4">
Sign up

View File

@ -38,6 +38,12 @@
<label class="form-label" for="birthday">Birthday</label>
</div>
<!-- Sending Policy input -->
<div class="form-outline mb-4">
<input asp-for="UserModel.OnlyImportantMails" type="checkbox" id="policy" />
<label class="form-label" for="policy">Send only important mails</label>
</div>
<!-- Hidden inputs -->
<input type="hidden" asp-for="UserModel.Id" />
<input type="hidden" asp-for="UserModel.Role.Id" />