From 51d26c58d7fb1733ee7b923e7315551afb02f52f Mon Sep 17 00:00:00 2001 From: mfnefd Date: Tue, 4 Jun 2024 23:43:15 +0400 Subject: [PATCH] view binding converters --- Contracts/Converters/RoleConverter.cs | 25 ++++++++++++++++++++ Contracts/Converters/UserConverter.cs | 33 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Contracts/Converters/RoleConverter.cs create mode 100644 Contracts/Converters/UserConverter.cs diff --git a/Contracts/Converters/RoleConverter.cs b/Contracts/Converters/RoleConverter.cs new file mode 100644 index 0000000..37aa7e0 --- /dev/null +++ b/Contracts/Converters/RoleConverter.cs @@ -0,0 +1,25 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Converters +{ + public static class RoleConverter + { + public static RoleViewModel ToView(RoleBindingModel model) => new() + { + Id = model.Id, + Name = model.Name, + }; + + public static RoleBindingModel ToBinding(RoleViewModel model) => new() + { + Id = model.Id, + Name = model.Name, + }; + } +} \ No newline at end of file diff --git a/Contracts/Converters/UserConverter.cs b/Contracts/Converters/UserConverter.cs new file mode 100644 index 0000000..b951d11 --- /dev/null +++ b/Contracts/Converters/UserConverter.cs @@ -0,0 +1,33 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Converters +{ + public static class UserConverter + { + public static UserViewModel ToView(UserBindingModel model) => new() + { + Id = model.Id, + FirstName = model.FirstName, + SecondName = model.SecondName, + Email = model.Email, + Birthday = model.Birthday, + Role = RoleConverter.ToView(model.Role), + }; + + public static UserBindingModel ToBinding(UserViewModel model) => new() + { + Id = model.Id, + FirstName = model.FirstName, + SecondName = model.SecondName, + Email = model.Email, + Birthday = model.Birthday, + Role = RoleConverter.ToBinding(model.Role), + }; + } +} \ No newline at end of file