Add project files.
This commit is contained in:
18
0_Framework/0_Framework.csproj
Normal file
18
0_Framework/0_Framework.csproj
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RootNamespace>_0_Framework</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="IPE.SmsIR" Version="1.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.1.34" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="PersianTools.Core" Version="2.0.4" />
|
||||||
|
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
11
0_Framework/Application/ApplicationMessages.cs
Normal file
11
0_Framework/Application/ApplicationMessages.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class ApplicationMessages
|
||||||
|
{
|
||||||
|
public const string DuplicatedRecord = "امکان ثبت رکورد تکراری وجود ندارد.";
|
||||||
|
public const string RecordNotFound = "رکورد با اطلاعات درخواست شده یافت نشد.";
|
||||||
|
public static string PasswordsNotMatch = "پسورد و تکرار آن با هم مطابقت ندارند";
|
||||||
|
public static string WrongUserPass = "نام کاربری یا کلمه عبور اشتباه است";
|
||||||
|
public static string EmptyUsername = "نام کاربری نمیتواند خالی باشد";
|
||||||
|
public static string EmptyPassword = "پسورد نمیتواند خالی باشد";
|
||||||
|
}
|
||||||
197
0_Framework/Application/AuthHelper.cs
Normal file
197
0_Framework/Application/AuthHelper.cs
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using _0_Framework.Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class AuthHelper : IAuthHelper
|
||||||
|
{
|
||||||
|
private readonly IHttpContextAccessor _contextAccessor;
|
||||||
|
|
||||||
|
public AuthHelper(IHttpContextAccessor contextAccessor)
|
||||||
|
{
|
||||||
|
_contextAccessor = contextAccessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthViewModel CurrentAccountInfo()
|
||||||
|
{
|
||||||
|
var result = new AuthViewModel();
|
||||||
|
if (!IsAuthenticated())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var claims = _contextAccessor.HttpContext.User.Claims.ToList();
|
||||||
|
result.Id = long.Parse(claims.FirstOrDefault(x => x.Type == "AccountId").Value);
|
||||||
|
result.Username = claims.FirstOrDefault(x => x.Type == "Username")?.Value;
|
||||||
|
result.ProfilePhoto = claims.FirstOrDefault(x => x.Type == "ProfilePhoto")?.Value;
|
||||||
|
result.RoleId = long.Parse(claims.FirstOrDefault(x => x.Type == ClaimTypes.Role)?.Value);
|
||||||
|
result.Fullname = claims.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value;
|
||||||
|
result.Role = claims.FirstOrDefault(x => x.Type == "RoleName")?.Value;
|
||||||
|
result.ClientAriaPermission =claims.FirstOrDefault(x => x.Type == "ClientAriaPermission").Value;
|
||||||
|
result.AdminAreaPermission = claims.FirstOrDefault(x => x.Type == "AdminAreaPermission").Value;
|
||||||
|
result.PositionValue = !string.IsNullOrWhiteSpace(claims.FirstOrDefault(x => x.Type == "PositionValue")?.Value) ? int.Parse(claims.FirstOrDefault(x => x.Type == "PositionValue")?.Value) : 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<int> GetPermissions()
|
||||||
|
{
|
||||||
|
if (!IsAuthenticated())
|
||||||
|
return new List<int>();
|
||||||
|
|
||||||
|
var permissions = _contextAccessor.HttpContext.User.Claims.FirstOrDefault(x => x.Type == "permissions")
|
||||||
|
?.Value;
|
||||||
|
return JsonConvert.DeserializeObject<List<int>>(permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long CurrentAccountId()
|
||||||
|
{
|
||||||
|
return IsAuthenticated()
|
||||||
|
? long.Parse(_contextAccessor.HttpContext.User.Claims.First(x => x.Type == "AccountId")?.Value)
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CurrentAccountMobile()
|
||||||
|
{
|
||||||
|
return IsAuthenticated()
|
||||||
|
? _contextAccessor.HttpContext.User.Claims.First(x => x.Type == "Mobile")?.Value
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Vafa
|
||||||
|
|
||||||
|
public void UpdateWorkshopSlugClaim(string workshopSlug)
|
||||||
|
{
|
||||||
|
var user = _contextAccessor.HttpContext.User;
|
||||||
|
|
||||||
|
if (user.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
var claimsIdentity = (ClaimsIdentity)user.Identity;
|
||||||
|
var existingClaim = claimsIdentity.FindFirst("WorkshopSlug");
|
||||||
|
|
||||||
|
if (existingClaim != null)
|
||||||
|
{
|
||||||
|
claimsIdentity.RemoveClaim(existingClaim);
|
||||||
|
}
|
||||||
|
|
||||||
|
claimsIdentity.AddClaim(new Claim("WorkshopSlug", workshopSlug));
|
||||||
|
|
||||||
|
var authProperties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1)
|
||||||
|
};
|
||||||
|
|
||||||
|
_contextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
|
||||||
|
new ClaimsPrincipal(claimsIdentity),
|
||||||
|
authProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public string CurrentAccountRole()
|
||||||
|
{
|
||||||
|
if (IsAuthenticated())
|
||||||
|
return _contextAccessor.HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role)?.Value;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAuthenticated()
|
||||||
|
{
|
||||||
|
return _contextAccessor.HttpContext.User.Identity.IsAuthenticated;
|
||||||
|
//var claims = _contextAccessor.HttpContext.User.Claims.ToList();
|
||||||
|
//if (claims.Count > 0)
|
||||||
|
// return true;
|
||||||
|
//return false;
|
||||||
|
//return claims.Count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Signin(AuthViewModel account)
|
||||||
|
{
|
||||||
|
var permissions = JsonConvert.SerializeObject(account.Permissions);
|
||||||
|
var claims = new List<Claim>
|
||||||
|
{
|
||||||
|
new Claim("AccountId", account.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, account.Fullname),
|
||||||
|
new Claim(ClaimTypes.Role, account.RoleId.ToString()),
|
||||||
|
new Claim("Username", account.Username), // Or Use ClaimTypes.NameIdentifier
|
||||||
|
new Claim("permissions", permissions),
|
||||||
|
new Claim("Mobile", account.Mobile),
|
||||||
|
new Claim("ProfilePhoto", account.ProfilePhoto ),
|
||||||
|
new Claim("RoleName", account.RoleName),
|
||||||
|
new Claim("AdminAreaPermission", account.AdminAreaPermission.ToString()),
|
||||||
|
new Claim("ClientAriaPermission", account.ClientAriaPermission.ToString()),
|
||||||
|
new Claim("IsCamera", "false"),
|
||||||
|
new Claim("PositionValue",account.PositionValue.ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
|
var authProperties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1)
|
||||||
|
};
|
||||||
|
|
||||||
|
_contextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
|
||||||
|
new ClaimsPrincipal(claimsIdentity),
|
||||||
|
authProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Camera
|
||||||
|
public void CameraSignIn(CameraAuthViewModel account)
|
||||||
|
{
|
||||||
|
var claims = new List<Claim>
|
||||||
|
{
|
||||||
|
new Claim("AccountId", account.Id.ToString()),
|
||||||
|
new Claim("Username", account.Username), // Or Use ClaimTypes.NameIdentifier
|
||||||
|
new Claim("WorkshopId", account.WorkshopId.ToString()),
|
||||||
|
new Claim("WorkshopName", account.WorkshopName),
|
||||||
|
new Claim("Mobile", account.Mobile),
|
||||||
|
new Claim("AccountId", account.AccountId.ToString()),
|
||||||
|
new Claim("IsActiveString", account.IsActiveString),
|
||||||
|
new Claim("IsCamera", "true"),
|
||||||
|
|
||||||
|
};
|
||||||
|
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
|
||||||
|
var authProperties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1)
|
||||||
|
};
|
||||||
|
|
||||||
|
_contextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
|
||||||
|
new ClaimsPrincipal(claimsIdentity),
|
||||||
|
authProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraAuthViewModel CameraAccountInfo()
|
||||||
|
{
|
||||||
|
var result = new CameraAuthViewModel();
|
||||||
|
if (!IsAuthenticated())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var claims = _contextAccessor.HttpContext.User.Claims.ToList();
|
||||||
|
result.Id = long.Parse(claims.FirstOrDefault(x => x.Type == "AccountId").Value);
|
||||||
|
result.Username = claims.FirstOrDefault(x => x.Type == "Username")?.Value;
|
||||||
|
result.WorkshopId = long.Parse(claims.FirstOrDefault(x => x.Type == "WorkshopId")?.Value);
|
||||||
|
result.WorkshopName = claims.FirstOrDefault(x => x.Type == "WorkshopName").Value;
|
||||||
|
result.Mobile = claims.FirstOrDefault(x => x.Type == "Mobile").Value;
|
||||||
|
result.AccountId = long.Parse(claims.FirstOrDefault(x => x.Type == "AccountId")?.Value);
|
||||||
|
result.IsActiveString = claims.FirstOrDefault(x => x.Type == "IsActiveString").Value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public void SignOut()
|
||||||
|
{
|
||||||
|
_contextAccessor.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
40
0_Framework/Application/AuthViewModel.cs
Normal file
40
0_Framework/Application/AuthViewModel.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class AuthViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long RoleId { get; set; }
|
||||||
|
public string Role { get; set; }
|
||||||
|
public string Fullname { get; set; }
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
public string RoleName { get; set; }
|
||||||
|
public string ProfilePhoto { get; set; }
|
||||||
|
public List<int> Permissions { get; set; }
|
||||||
|
public string AdminAreaPermission { get; set; }
|
||||||
|
public string ClientAriaPermission { get; set; }
|
||||||
|
public int? PositionValue { get; set; }
|
||||||
|
|
||||||
|
public AuthViewModel(long id, long roleId, string fullname, string username, string mobile,string profilePhoto,
|
||||||
|
List<int> permissions, string roleName, string adminAreaPermission, string clientAriaPermission, int? positionValue)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
RoleId = roleId;
|
||||||
|
Fullname = fullname;
|
||||||
|
Username = username;
|
||||||
|
Mobile = mobile;
|
||||||
|
ProfilePhoto = profilePhoto;
|
||||||
|
Permissions = permissions;
|
||||||
|
RoleName = roleName;
|
||||||
|
AdminAreaPermission = adminAreaPermission;
|
||||||
|
ClientAriaPermission = clientAriaPermission;
|
||||||
|
PositionValue = positionValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthViewModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
29
0_Framework/Application/CameraAuthViewModel.cs
Normal file
29
0_Framework/Application/CameraAuthViewModel.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class CameraAuthViewModel
|
||||||
|
{
|
||||||
|
public CameraAuthViewModel(long id, long workshopId, string username, string mobile, string workshopName, long accountId, string isActiveString)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
WorkshopId = workshopId;
|
||||||
|
Username = username;
|
||||||
|
Mobile = mobile;
|
||||||
|
WorkshopName = workshopName;
|
||||||
|
AccountId = accountId;
|
||||||
|
IsActiveString = isActiveString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long WorkshopId { get; set; }
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
public string WorkshopName { get; set; }
|
||||||
|
public long AccountId { get; set; }
|
||||||
|
public string IsActiveString { get; set; }
|
||||||
|
public CameraAuthViewModel()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
36
0_Framework/Application/CodeGenerator.cs
Normal file
36
0_Framework/Application/CodeGenerator.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class CodeGenerator
|
||||||
|
{
|
||||||
|
public static string Generate(string symbol)
|
||||||
|
{
|
||||||
|
return $"{symbol}{RandomString()}{RandomNumber()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string RandomString()
|
||||||
|
{
|
||||||
|
const int length = 2;
|
||||||
|
|
||||||
|
var strBuild = new StringBuilder();
|
||||||
|
var random = new Random();
|
||||||
|
|
||||||
|
for (var i = 0; i <= length; i++)
|
||||||
|
{
|
||||||
|
var flt = random.NextDouble();
|
||||||
|
var shift = Convert.ToInt32(Math.Floor(25 * flt));
|
||||||
|
var letter = Convert.ToChar(shift + 65);
|
||||||
|
strBuild.Append(letter);
|
||||||
|
}
|
||||||
|
|
||||||
|
return strBuild.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string RandomNumber()
|
||||||
|
{
|
||||||
|
var random = new Random();
|
||||||
|
return random.Next(100, 999).ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
316
0_Framework/Application/ConvertTo.cs
Normal file
316
0_Framework/Application/ConvertTo.cs
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// <copyright file="ConvertTo.cs">
|
||||||
|
// By: MOHSEN DORPARASTI - 1391
|
||||||
|
// </copyright>
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
public enum TextEncoding
|
||||||
|
{
|
||||||
|
Arabic1256 = 1256,
|
||||||
|
CP1252 = 1252
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConvertTo
|
||||||
|
{
|
||||||
|
#region private Members (3)
|
||||||
|
|
||||||
|
// متغیری برای نگهداری اعدادی که در رشته ایران سیستم وجود دارند
|
||||||
|
static Stack<string> NumbersInTheString;
|
||||||
|
|
||||||
|
// کد کاراکترها در ایران سیستم و معادل آنها در عربی 1256
|
||||||
|
static Dictionary<byte, byte> CharactersMapper = new Dictionary<byte, byte>
|
||||||
|
{
|
||||||
|
{128,48}, // 0
|
||||||
|
{129,49}, // 1
|
||||||
|
{130,50}, // 2
|
||||||
|
{131,51}, // 3
|
||||||
|
{132,52}, // 4
|
||||||
|
{133,53}, // 5
|
||||||
|
{134,54}, // 6
|
||||||
|
{135,55}, // 7
|
||||||
|
{136,56}, // 8
|
||||||
|
{137,57}, // 9
|
||||||
|
{138,161}, // ،
|
||||||
|
{139,220}, // -
|
||||||
|
{140,191}, // ؟
|
||||||
|
{141,194}, // آ
|
||||||
|
{142,196}, // ﺋ
|
||||||
|
{143,154}, // ء
|
||||||
|
{144,199}, // ﺍ
|
||||||
|
{145,199}, // ﺎ
|
||||||
|
{146,200}, // ﺏ
|
||||||
|
{147,200}, // ﺑ
|
||||||
|
{148,129}, // ﭖ
|
||||||
|
{149,129}, // ﭘ
|
||||||
|
{150,202}, // ﺕ
|
||||||
|
{151,202}, // ﺗ
|
||||||
|
{152,203}, // ﺙ
|
||||||
|
{153,203}, // ﺛ
|
||||||
|
{154,204}, //ﺝ
|
||||||
|
{155,204},// ﺟ
|
||||||
|
{156,141},//ﭼ
|
||||||
|
{157,141},//ﭼ
|
||||||
|
{158,205},//ﺡ
|
||||||
|
{159,205},//ﺣ
|
||||||
|
{160,206},//ﺥ
|
||||||
|
{161,206},//ﺧ
|
||||||
|
{162,207},//د
|
||||||
|
{163,208},//ذ
|
||||||
|
{164,209},//ر
|
||||||
|
{165,210},//ز
|
||||||
|
{166,142},//ژ
|
||||||
|
{167,211},//ﺱ
|
||||||
|
{168,211},//ﺳ
|
||||||
|
{169,212},//ﺵ
|
||||||
|
{170,212},//ﺷ
|
||||||
|
{171,213},//ﺹ
|
||||||
|
{172,213},//ﺻ
|
||||||
|
{173,214},//ﺽ
|
||||||
|
{174,214},//ﺿ
|
||||||
|
{175,216},//ط
|
||||||
|
{224,217},//ظ
|
||||||
|
{225,218},//ﻉ
|
||||||
|
{226,218},//ﻊ
|
||||||
|
{227,218},//ﻌ
|
||||||
|
{228,218},//ﻋ
|
||||||
|
{229,219},//ﻍ
|
||||||
|
{230,219},//ﻎ
|
||||||
|
{231,219},//ﻐ
|
||||||
|
{232,219},//ﻏ
|
||||||
|
{233,221},//ﻑ
|
||||||
|
{234,221},//ﻓ
|
||||||
|
{235,222},//ﻕ
|
||||||
|
{236,222},//ﻗ
|
||||||
|
{237,152},//ﮎ
|
||||||
|
{238,152},//ﮐ
|
||||||
|
{239,144},//ﮒ
|
||||||
|
{240,144},//ﮔ
|
||||||
|
{241,225},//ﻝ
|
||||||
|
{242,225},//ﻻ
|
||||||
|
{243,225},//ﻟ
|
||||||
|
{244,227},//ﻡ
|
||||||
|
{245,227},//ﻣ
|
||||||
|
{246,228},//ﻥ
|
||||||
|
{247,228},//ﻧ
|
||||||
|
{248,230},//و
|
||||||
|
{249,229},//ﻩ
|
||||||
|
{250,229},//ﻬ
|
||||||
|
{251,170},//ﻫ
|
||||||
|
{252,236},//ﯽ
|
||||||
|
{253,237},//ﯼ
|
||||||
|
{254,237},//ﯾ
|
||||||
|
{255,160} // فاصله
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// لیست کاراکترهایی که بعد از آنها باید یک فاصله اضافه شود
|
||||||
|
/// </summary>
|
||||||
|
static byte[] charactersWithSpaceAfter = {
|
||||||
|
146, // ب
|
||||||
|
148, // پ
|
||||||
|
150, // ت
|
||||||
|
152, // ث
|
||||||
|
154, // ج
|
||||||
|
156, // چ
|
||||||
|
158, // ح
|
||||||
|
160, // خ
|
||||||
|
167, // س
|
||||||
|
169, // ش
|
||||||
|
171, // ص
|
||||||
|
173, // ض
|
||||||
|
225, // ع
|
||||||
|
229, // غ
|
||||||
|
233, // ف
|
||||||
|
235, // ق
|
||||||
|
237, // ک
|
||||||
|
239, // گ
|
||||||
|
241, // ل
|
||||||
|
244, // م
|
||||||
|
246, // ن
|
||||||
|
249, // ه
|
||||||
|
252, //ﯽ
|
||||||
|
253 // ی
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// تبدیل یک رشته ایران سیستم به یونیکد با استفاده از عربی 1256
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="iranSystemEncodedString">رشته ایران سیستم</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Obsolete("بهتر است از UnicodeFrom استفاده کنید")]
|
||||||
|
public static string Unicode(string iranSystemEncodedString)
|
||||||
|
{
|
||||||
|
return UnicodeFrom(TextEncoding.Arabic1256, iranSystemEncodedString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// تبدیل یک رشته ایران سیستم به یونیکد
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="textEncoding">کدپیج رشته ایران سیستم</param>
|
||||||
|
/// <param name="iranSystemEncodedString">رشته ایران سیستم</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string UnicodeFrom(TextEncoding textEncoding, string iranSystemEncodedString)
|
||||||
|
{
|
||||||
|
// حذف فاصله های موجود در رشته
|
||||||
|
iranSystemEncodedString = iranSystemEncodedString.Replace(" ", "");
|
||||||
|
|
||||||
|
/// بازگشت در صورت خالی بودن رشته
|
||||||
|
if (string.IsNullOrWhiteSpace(iranSystemEncodedString))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// در صورتی که رشته تماماً عدد نباشد
|
||||||
|
if (!IsNumber(iranSystemEncodedString))
|
||||||
|
{
|
||||||
|
/// تغییر ترتیب کاراکترها از آخر به اول
|
||||||
|
iranSystemEncodedString = Reverse(iranSystemEncodedString);
|
||||||
|
|
||||||
|
/// خارج کردن اعداد درون رشته
|
||||||
|
iranSystemEncodedString = ExcludeNumbers(iranSystemEncodedString);
|
||||||
|
}
|
||||||
|
|
||||||
|
// وهله سازی از انکودینگ صحیح برای تبدیل رشته ایران سیستم به بایت
|
||||||
|
Encoding encoding = Encoding.GetEncoding((int)textEncoding);
|
||||||
|
|
||||||
|
// تبدیل رشته به بایت
|
||||||
|
byte[] stringBytes = encoding.GetBytes(iranSystemEncodedString.Trim());
|
||||||
|
|
||||||
|
|
||||||
|
// آرایه ای که بایت های معادل را در آن قرار می دهیم
|
||||||
|
// مجموع تعداد بایت های رشته + بایت های اضافی محاسبه شده
|
||||||
|
byte[] newStringBytes = new byte[stringBytes.Length + CountCharactersRequireTwoBytes(stringBytes)];
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
// بررسی هر بایت و پیدا کردن بایت (های) معادل آن
|
||||||
|
for (int i = 0; i < stringBytes.Length; ++i)
|
||||||
|
{
|
||||||
|
byte charByte = stringBytes[i];
|
||||||
|
|
||||||
|
// اگر جز 128 بایت اول باشد که نیازی به تبدیل ندارد چون کد اسکی است
|
||||||
|
if (charByte < 128)
|
||||||
|
{
|
||||||
|
newStringBytes[index] = charByte;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// اگر جز حروف یا اعداد بود معادلش رو قرار می دیم
|
||||||
|
if (CharactersMapper.ContainsKey(charByte))
|
||||||
|
{
|
||||||
|
newStringBytes[index] = CharactersMapper[charByte];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// اگر کاراکتر ایران سیستم "لا" بود چون کاراکتر متناظرش در عربی 1256 "ل" است و باید یک "ا" هم بعدش اضافه کنیم
|
||||||
|
if (charByte == 242)
|
||||||
|
{
|
||||||
|
newStringBytes[++index] = 199;
|
||||||
|
}
|
||||||
|
|
||||||
|
// اگر کاراکتر یکی از انواعی بود که بعدشان باید یک فاصله باشد
|
||||||
|
// و در عین حال آخرین کاراکتر رشته نبود
|
||||||
|
if (charactersWithSpaceAfter.Contains(charByte) && Array.IndexOf(stringBytes, charByte) != stringBytes.Length - 1)
|
||||||
|
{
|
||||||
|
// یک فاصله بعد ان اضافه می کنیم
|
||||||
|
newStringBytes[++index] = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// تبدیل به رشته و ارسال به فراخواننده
|
||||||
|
byte[] unicodeContent = Encoding.Convert(encoding, Encoding.Unicode, newStringBytes);
|
||||||
|
|
||||||
|
string convertedString = Encoding.Unicode.GetString(unicodeContent).Trim();
|
||||||
|
|
||||||
|
return IncludeNumbers(convertedString);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Private Methods (4)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// رشته ارسال شده تنها حاوی اعداد است یا نه
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static bool IsNumber(string str)
|
||||||
|
{
|
||||||
|
return Regex.IsMatch(str, @"^[\d]+$");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// محاسبه تعداد کاراکترهایی که بعد از آنها یک کاراکتر باید اضافه شود
|
||||||
|
/// شامل کاراکتر لا
|
||||||
|
/// و کاراکترهای غیرچسبان تنها در صورتی که کاراکتر پایانی رشته نباشند
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static int CountCharactersRequireTwoBytes(byte[] irTextBytes)
|
||||||
|
{
|
||||||
|
return (from b in irTextBytes
|
||||||
|
where (
|
||||||
|
charactersWithSpaceAfter.Contains(b) // یکی از حروف غیرچسبان باشد
|
||||||
|
&& Array.IndexOf(irTextBytes, b) != irTextBytes.Length - 1) // و کاراکتر آخر هم نباشد
|
||||||
|
|| b == 242 // یا کاراکتر لا باشد
|
||||||
|
select b).Count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// خارج کردن اعدادی که در رشته ایران سیستم قرار دارند
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="iranSystemString"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static string ExcludeNumbers(string iranSystemString)
|
||||||
|
{
|
||||||
|
/// گرفتن لیستی از اعداد درون رشته
|
||||||
|
NumbersInTheString = new Stack<string>(Regex.Split(iranSystemString, @"\D+"));
|
||||||
|
|
||||||
|
/// جایگزین کردن اعداد با یک علامت جایگزین
|
||||||
|
/// در نهایت بعد از تبدیل رشته اعداد به رشته اضافه می شوند
|
||||||
|
return Regex.Replace(iranSystemString, @"\d+", "#");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// اضافه کردن اعداد جدا شده پس از تبدیل رشته
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="convertedString"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static string IncludeNumbers(string convertedString)
|
||||||
|
{
|
||||||
|
while (convertedString.IndexOf("#") >= 0)
|
||||||
|
{
|
||||||
|
string number = Reverse(NumbersInTheString.Pop());
|
||||||
|
if(!string.IsNullOrWhiteSpace(number))
|
||||||
|
{
|
||||||
|
int index = convertedString.IndexOf("#");
|
||||||
|
|
||||||
|
convertedString = convertedString.Remove(index, 1);
|
||||||
|
convertedString = convertedString.Insert(index, number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertedString;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string Reverse(string s)
|
||||||
|
{
|
||||||
|
char[] charArray = s.ToCharArray();
|
||||||
|
Array.Reverse(charArray);
|
||||||
|
return new string(charArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
365
0_Framework/Application/ConvertToIranSystem.cs
Normal file
365
0_Framework/Application/ConvertToIranSystem.cs
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// نحوهي تبديل اعداد
|
||||||
|
/// </summary>
|
||||||
|
public enum IranSystemNumbers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// اعداد موجود به فرمت ايران سيستم تبديل نشوند و به همان شكل اصلي باقي بمانند
|
||||||
|
/// </summary>
|
||||||
|
DontConvert,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// اعداد موجود هم به قالب ايران سيستم تبديل شوند
|
||||||
|
/// </summary>
|
||||||
|
Convert
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConvertToIranSystem
|
||||||
|
{
|
||||||
|
const byte AlefChasban = 145;
|
||||||
|
const byte LaaArabic = 242;
|
||||||
|
const byte LaamAvval = 243;
|
||||||
|
const byte QuestionMark = 191;
|
||||||
|
|
||||||
|
private static readonly IDictionary<byte, byte> _charMapperCharIsNotFinal =
|
||||||
|
new Dictionary<byte, byte>
|
||||||
|
{
|
||||||
|
{48 , 128}, // 0
|
||||||
|
{49 , 129}, // 1
|
||||||
|
{50 , 130}, // 2
|
||||||
|
{51 , 131}, // 3
|
||||||
|
{52 , 132}, // 4
|
||||||
|
{53 , 133}, // 5
|
||||||
|
{54 , 134}, // 6
|
||||||
|
{55 , 135}, // 7
|
||||||
|
{56 , 136}, // 8
|
||||||
|
{57 , 137}, // 9
|
||||||
|
{161, 138}, // ،
|
||||||
|
{191, 140}, // ؟
|
||||||
|
{193,143}, //
|
||||||
|
{194,141}, // آ
|
||||||
|
{195,145}, // ﺎ
|
||||||
|
{196, /*248*/ 142}, //
|
||||||
|
{197,145}, //
|
||||||
|
{198,254}, //
|
||||||
|
{199,145}, //
|
||||||
|
{200,147}, //
|
||||||
|
{201,250}, //
|
||||||
|
{202,151}, //
|
||||||
|
{203,153}, //
|
||||||
|
{204,155}, //
|
||||||
|
{205,159}, //
|
||||||
|
{206,161}, //
|
||||||
|
{207,162}, //
|
||||||
|
{208,163}, //
|
||||||
|
{209,164}, //
|
||||||
|
{210,165}, //ز
|
||||||
|
{211,168}, //
|
||||||
|
{212,170}, //
|
||||||
|
{213,172}, //
|
||||||
|
{214,174}, //
|
||||||
|
{216,175}, //
|
||||||
|
{217,224}, //
|
||||||
|
{218,227}, //
|
||||||
|
{219,231}, //
|
||||||
|
{220,139}, // -
|
||||||
|
{221,234}, //
|
||||||
|
{222,236}, //
|
||||||
|
{223,238}, //
|
||||||
|
{225,243}, //
|
||||||
|
{227,245}, //
|
||||||
|
{228,247}, //
|
||||||
|
{229,250}, //
|
||||||
|
{230,248}, //
|
||||||
|
{236,254}, //
|
||||||
|
{237,254}, //
|
||||||
|
{129,149}, //
|
||||||
|
{141,157}, //
|
||||||
|
{142,166}, //
|
||||||
|
{152,238}, //
|
||||||
|
{144,240} //
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly IDictionary<byte, byte> _charMapperNextCharFinal =
|
||||||
|
new Dictionary<byte, byte>
|
||||||
|
{
|
||||||
|
{198, 252}, //
|
||||||
|
{200, 146}, //
|
||||||
|
{201, 249}, //
|
||||||
|
{202, 150}, //
|
||||||
|
{203, 152}, //
|
||||||
|
{204, 154}, //
|
||||||
|
{205, 158}, //
|
||||||
|
{206, 160}, //
|
||||||
|
{211, 167}, //
|
||||||
|
{212, 169}, //
|
||||||
|
{213, 171}, //
|
||||||
|
{214, 173}, //
|
||||||
|
{218, 226}, //
|
||||||
|
{219, 230}, //
|
||||||
|
{221, 233}, //
|
||||||
|
{222, 235}, //
|
||||||
|
{223, 237}, //
|
||||||
|
{225, 241}, //
|
||||||
|
{227, 244 /*245*/}, //
|
||||||
|
{228, 246}, //
|
||||||
|
{229, 249}, //
|
||||||
|
{236, 252}, //
|
||||||
|
{237, 252}, //
|
||||||
|
{129, 148}, //
|
||||||
|
{141, 156}, //
|
||||||
|
{142, 166}, //
|
||||||
|
{152, 237}, //
|
||||||
|
{144, 239} //
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly IDictionary<byte, byte> _charMapperPreviousCharFinal =
|
||||||
|
new Dictionary<byte, byte>
|
||||||
|
{
|
||||||
|
{195, 144},//أ
|
||||||
|
{197, 144},//إ
|
||||||
|
{199, 144},//ا
|
||||||
|
{201, 251},//ة
|
||||||
|
{218, 228},//ع
|
||||||
|
{219, 232},//غ
|
||||||
|
{229, 251},//ه
|
||||||
|
{170, 251}//ﻫ
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly IDictionary<byte, byte> _charMapperPreviousCharNextCharFinal =
|
||||||
|
new Dictionary<byte, byte>
|
||||||
|
{
|
||||||
|
{195, 144}, // أ
|
||||||
|
{197, 144}, //إ
|
||||||
|
{199, 144},//ا
|
||||||
|
{200, 146}, //ب
|
||||||
|
{201, 249}, //ة
|
||||||
|
{202, 150}, //ت
|
||||||
|
{203, 152}, //ث
|
||||||
|
{204, 154}, //ﺝ
|
||||||
|
{205, 158}, //ﺡ
|
||||||
|
{206, 160}, //ﺥ
|
||||||
|
{211, 167},//س
|
||||||
|
{212, 169},//ش
|
||||||
|
{213, 171}, //ص
|
||||||
|
{214, 173}, //ض
|
||||||
|
{218, 225}, //ع
|
||||||
|
{219, 229}, //غ
|
||||||
|
{221, 233},//ف
|
||||||
|
{222, 235},//ق
|
||||||
|
{223, 237},//ك
|
||||||
|
{225, 241},//ل
|
||||||
|
{227, 244},//م
|
||||||
|
{228, 246},//ن
|
||||||
|
{229, 249},//ه
|
||||||
|
{236, /*253*/ 252},//ى
|
||||||
|
{237, 253},//ی
|
||||||
|
{129, 148},//پ
|
||||||
|
{141, 156},//چ
|
||||||
|
{152, 237},//ک
|
||||||
|
{144, 239}//گ
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly Encoding _encoding1256 = Encoding.GetEncoding("windows-1256");
|
||||||
|
|
||||||
|
private static readonly byte[] _singles = _encoding1256.GetBytes("ءآأؤإادذرزژو");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// تبديل رشتهي يونيكد به رشتهي ايران سيستمي
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">رشتهي يونيكد</param>
|
||||||
|
/// <param name="iranSystemNumbers">تبديل اعداد</param>
|
||||||
|
/// <returns>رشتهي ايران سيستمي</returns>
|
||||||
|
public static string ToIranSystem(
|
||||||
|
this string text,
|
||||||
|
IranSystemNumbers iranSystemNumbers = IranSystemNumbers.DontConvert)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
////var array = iranSystemBytes.ToArray();
|
||||||
|
////string s = Encoding.GetEncoding(1256).GetString(array);
|
||||||
|
////byte[] Utf8Data = Encoding.UTF8.GetBytes(s);
|
||||||
|
|
||||||
|
text = reverseNumbersAndLetters(text);
|
||||||
|
var iranSystemBytes = getUnicodeToIranSystem(text, iranSystemNumbers);
|
||||||
|
var iranSystemText = _encoding1256.GetString(iranSystemBytes.ToArray()).Trim();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char last_char = text[text.Length - 1];
|
||||||
|
if (last_char == 'خ')
|
||||||
|
{
|
||||||
|
iranSystemText = iranSystemText + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new string(iranSystemText.Reverse().ToArray());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getLattinLetter(byte c)
|
||||||
|
{
|
||||||
|
return char.IsNumber((char)c) ? (byte)(c + 80) : getMirroredCharacter(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getMapperCharIsNotFinal(byte currentChar)
|
||||||
|
{
|
||||||
|
byte value;
|
||||||
|
return _charMapperCharIsNotFinal.TryGetValue(currentChar, out value) ? value : currentChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getMapperNextCharFinal(byte currentChar)
|
||||||
|
{
|
||||||
|
byte value;
|
||||||
|
return _charMapperNextCharFinal.TryGetValue(currentChar, out value) ? value : getMapperCharIsNotFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getMapperPreviousCharFinal(byte currentChar)
|
||||||
|
{
|
||||||
|
byte value;
|
||||||
|
return _charMapperPreviousCharFinal.TryGetValue(currentChar, out value) ? value : getMapperCharIsNotFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getMapperPreviousCharNextCharFinal(byte currentChar)
|
||||||
|
{
|
||||||
|
byte value;
|
||||||
|
return _charMapperPreviousCharNextCharFinal.TryGetValue(currentChar, out value) ? value : getMapperCharIsNotFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getMirroredCharacter(byte c)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case (byte)'(': return (byte)')';
|
||||||
|
case (byte)'{': return (byte)'}';
|
||||||
|
case (byte)'[': return (byte)']';
|
||||||
|
case (byte)')': return (byte)'(';
|
||||||
|
case (byte)'}': return (byte)'{';
|
||||||
|
case (byte)']': return (byte)'[';
|
||||||
|
default: return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<byte> getUnicodeToIranSystem(string text, IranSystemNumbers iranSystemNumbers)
|
||||||
|
{
|
||||||
|
var unicodeString = string.Format(" {0} ", text);
|
||||||
|
var textBytes = _encoding1256.GetBytes(unicodeString);
|
||||||
|
|
||||||
|
byte pre = 0;
|
||||||
|
var length = textBytes.Length;
|
||||||
|
var results = new List<byte>(length);
|
||||||
|
|
||||||
|
for (var i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
byte cur;
|
||||||
|
var currentChar = textBytes[i];
|
||||||
|
|
||||||
|
if (isNumber(currentChar) && iranSystemNumbers == IranSystemNumbers.DontConvert)
|
||||||
|
{
|
||||||
|
cur = currentChar;
|
||||||
|
results.Add(cur);
|
||||||
|
pre = cur;
|
||||||
|
}
|
||||||
|
else if (isLattinLetter(currentChar))
|
||||||
|
{
|
||||||
|
cur = getLattinLetter(currentChar);
|
||||||
|
results.Add(cur);
|
||||||
|
pre = cur;
|
||||||
|
}
|
||||||
|
else if (i != 0 && i != length - 1)
|
||||||
|
{
|
||||||
|
cur = getUnicodeToIranSystemChar(textBytes[i - 1], currentChar, textBytes[i + 1]);
|
||||||
|
if (cur == AlefChasban) // برای بررسی استثنای لا
|
||||||
|
{
|
||||||
|
if (pre == LaamAvval)
|
||||||
|
{
|
||||||
|
results.RemoveAt(results.Count - 1);
|
||||||
|
results.Add(LaaArabic);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
results.Add(cur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
results.Add(cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre = cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte getUnicodeToIranSystemChar(byte previousChar, byte currentChar, byte nextChar)
|
||||||
|
{
|
||||||
|
var isPreviousCharFinal =
|
||||||
|
isWhitespaceOrLattinOrQuestionMark(previousChar) ||
|
||||||
|
isFinalLetter(previousChar);
|
||||||
|
|
||||||
|
var isNextCharFinal = isWhitespaceOrLattinOrQuestionMark(nextChar);
|
||||||
|
|
||||||
|
if (isPreviousCharFinal && isNextCharFinal)
|
||||||
|
{
|
||||||
|
return getMapperPreviousCharNextCharFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPreviousCharFinal)
|
||||||
|
{
|
||||||
|
return getMapperPreviousCharFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNextCharFinal)
|
||||||
|
{
|
||||||
|
return getMapperNextCharFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMapperCharIsNotFinal(currentChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool isFinalLetter(byte c)
|
||||||
|
{
|
||||||
|
return _singles.Contains(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool isLattinLetter(byte c)
|
||||||
|
{
|
||||||
|
return c < 128 && c > 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool isNumber(byte currentChar)
|
||||||
|
{
|
||||||
|
return currentChar >= 48 && currentChar <= 57;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool isWhiteSpaceLetter(byte c)
|
||||||
|
{
|
||||||
|
return c == 8 || c == 09 || c == 10 || c == 13 || c == 27 || c == 32 || c == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool isWhitespaceOrLattinOrQuestionMark(byte c)
|
||||||
|
{
|
||||||
|
return isWhiteSpaceLetter(c) || isLattinLetter(c) || c == QuestionMark;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string reverseNumbersAndLetters(string text)
|
||||||
|
{
|
||||||
|
return Regex.Replace(text, @"[a-zA-Z0-9]+", match =>
|
||||||
|
{
|
||||||
|
return new string(match.Value.Reverse().ToArray());
|
||||||
|
}).Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
32
0_Framework/Application/FileExtentionLimitationAttribute.cs
Normal file
32
0_Framework/Application/FileExtentionLimitationAttribute.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//using Microsoft.AspNetCore.Http;
|
||||||
|
//using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||||
|
//using System;
|
||||||
|
//using System.ComponentModel.DataAnnotations;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
|
||||||
|
//namespace _0_Framework.Application
|
||||||
|
//{
|
||||||
|
// public class FileExtentionLimitationAttribute : ValidationAttribute, IClientModelValidator
|
||||||
|
// {
|
||||||
|
// private readonly string[] _validExtentions;
|
||||||
|
// public FileExtentionLimitationAttribute(string[] validExtentions)
|
||||||
|
// {
|
||||||
|
// _validExtentions = validExtentions;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public override bool IsValid(object value)
|
||||||
|
// {
|
||||||
|
// var file = value as IFormFile;
|
||||||
|
// if (file == null) return true;
|
||||||
|
// var fileExtention = Path.GetExtension(file.FileName);
|
||||||
|
// return _validExtentions.Contains(fileExtention);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public void AddValidation(ClientModelValidationContext context)
|
||||||
|
// {
|
||||||
|
// //context.Attributes.Add("data-val", "true");
|
||||||
|
// context.Attributes.Add("data-val-fileExtentionLimit", ErrorMessage);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
6
0_Framework/Application/HashingOptions.cs
Normal file
6
0_Framework/Application/HashingOptions.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public sealed class HashingOptions
|
||||||
|
{
|
||||||
|
public int Iterations { get; set; } = 10000;
|
||||||
|
}
|
||||||
23
0_Framework/Application/IAuthHelper.cs
Normal file
23
0_Framework/Application/IAuthHelper.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public interface IAuthHelper
|
||||||
|
{
|
||||||
|
void SignOut();
|
||||||
|
bool IsAuthenticated();
|
||||||
|
void Signin(AuthViewModel account);
|
||||||
|
void CameraSignIn(CameraAuthViewModel account);
|
||||||
|
CameraAuthViewModel CameraAccountInfo();
|
||||||
|
string CurrentAccountRole();
|
||||||
|
AuthViewModel CurrentAccountInfo();
|
||||||
|
List<int> GetPermissions();
|
||||||
|
long CurrentAccountId();
|
||||||
|
string CurrentAccountMobile();
|
||||||
|
|
||||||
|
#region Vafa
|
||||||
|
|
||||||
|
void UpdateWorkshopSlugClaim(string workshopSlug);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
8
0_Framework/Application/IFileUploader.cs
Normal file
8
0_Framework/Application/IFileUploader.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public interface IFileUploader
|
||||||
|
{
|
||||||
|
string Upload(IFormFile file, string path);
|
||||||
|
}
|
||||||
9
0_Framework/Application/IPasswordHasher.cs
Normal file
9
0_Framework/Application/IPasswordHasher.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public interface IPasswordHasher
|
||||||
|
{
|
||||||
|
string Hash(string password);
|
||||||
|
(bool Verified, bool NeedsUpgrade) Check(string hash, string password);
|
||||||
|
string SlugHasher(long slug);
|
||||||
|
long SlugDecrypt(string slug);
|
||||||
|
}
|
||||||
29
0_Framework/Application/MaxFileSizeAttribute.cs
Normal file
29
0_Framework/Application/MaxFileSizeAttribute.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//using Microsoft.AspNetCore.Http;
|
||||||
|
//using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||||
|
//using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
//namespace _0_Framework.Application
|
||||||
|
//{
|
||||||
|
// public class MaxFileSizeAttribute : ValidationAttribute, IClientModelValidator
|
||||||
|
// {
|
||||||
|
// private readonly int _maxFileSize;
|
||||||
|
|
||||||
|
// public MaxFileSizeAttribute(int maxFileSize)
|
||||||
|
// {
|
||||||
|
// _maxFileSize = maxFileSize;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public override bool IsValid(object value)
|
||||||
|
// {
|
||||||
|
// var file = value as IFormFile;
|
||||||
|
// if (file == null) return true;
|
||||||
|
// return file.Length <= _maxFileSize;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public void AddValidation(ClientModelValidationContext context)
|
||||||
|
// {
|
||||||
|
// context.Attributes.Add("data-val", "true");
|
||||||
|
// context.Attributes.Add("data-val-maxFileSize", ErrorMessage);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
33
0_Framework/Application/OperationResult.cs
Normal file
33
0_Framework/Application/OperationResult.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class OperationResult
|
||||||
|
{
|
||||||
|
|
||||||
|
public bool IsSuccedded { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
|
public long SendId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public OperationResult()
|
||||||
|
{
|
||||||
|
IsSuccedded = false;
|
||||||
|
}
|
||||||
|
public OperationResult Succcedded(long sendId=-1,string message ="عملیات با موفقیت انجام شد")
|
||||||
|
{
|
||||||
|
IsSuccedded = true;
|
||||||
|
Message = message;
|
||||||
|
SendId = sendId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Failed(string message)
|
||||||
|
{
|
||||||
|
IsSuccedded = false;
|
||||||
|
Message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
31
0_Framework/Application/OperationResult2.cs
Normal file
31
0_Framework/Application/OperationResult2.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class OperationResult2
|
||||||
|
{
|
||||||
|
public long EntityId { get; set; }
|
||||||
|
public bool IsSuccedded { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
public OperationResult2()
|
||||||
|
{
|
||||||
|
IsSuccedded = false;
|
||||||
|
}
|
||||||
|
public OperationResult2 Succcedded(long entityId = -1, string message ="عملیات با موفقیت انجام شد")
|
||||||
|
{
|
||||||
|
EntityId = entityId;
|
||||||
|
IsSuccedded = true;
|
||||||
|
Message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult2 Failed(string message)
|
||||||
|
{
|
||||||
|
IsSuccedded = false;
|
||||||
|
Message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
97
0_Framework/Application/PasswordHasher.cs
Normal file
97
0_Framework/Application/PasswordHasher.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class PasswordHasher : IPasswordHasher
|
||||||
|
{
|
||||||
|
private const int SaltSize = 16; // 128 bit
|
||||||
|
private const int KeySize = 32; // 256 bit
|
||||||
|
|
||||||
|
public PasswordHasher(IOptions<HashingOptions> options)
|
||||||
|
{
|
||||||
|
Options = options.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashingOptions Options { get; }
|
||||||
|
|
||||||
|
public string Hash(string password)
|
||||||
|
{
|
||||||
|
using var algorithm = new Rfc2898DeriveBytes(password, SaltSize, Options.Iterations, HashAlgorithmName.SHA256);
|
||||||
|
var key = Convert.ToBase64String(algorithm.GetBytes(KeySize));
|
||||||
|
var salt = Convert.ToBase64String(algorithm.Salt);
|
||||||
|
|
||||||
|
return $"{Options.Iterations}.{salt}.{key}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public (bool Verified, bool NeedsUpgrade) Check(string hash, string password)
|
||||||
|
{
|
||||||
|
var parts = hash.Split('.', 3);
|
||||||
|
|
||||||
|
if (parts.Length != 3)
|
||||||
|
{
|
||||||
|
return (false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var iterations = Convert.ToInt32(parts[0]);
|
||||||
|
var salt = Convert.FromBase64String(parts[1]);
|
||||||
|
var key = Convert.FromBase64String(parts[2]);
|
||||||
|
|
||||||
|
var needsUpgrade = iterations != Options.Iterations;
|
||||||
|
|
||||||
|
using var algorithm = new Rfc2898DeriveBytes(password, salt, iterations, HashAlgorithmName.SHA256);
|
||||||
|
var keyToCheck = algorithm.GetBytes(KeySize);
|
||||||
|
|
||||||
|
var verified = keyToCheck.SequenceEqual(key);
|
||||||
|
|
||||||
|
return (verified, needsUpgrade);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
public string SlugHasher(long slug)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var test = slug.ToString();
|
||||||
|
UTF8Encoding encoder = new UTF8Encoding();
|
||||||
|
|
||||||
|
byte[] hashedDataBytes = encoder.GetBytes(test);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return Convert.ToBase64String(hashedDataBytes);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long SlugDecrypt(string slug)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(slug) || slug.Trim() == "0")
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] bytes = Convert.FromBase64String(slug);
|
||||||
|
|
||||||
|
string result = System.Text.Encoding.UTF8.GetString(bytes);
|
||||||
|
|
||||||
|
return long.Parse(result);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
20
0_Framework/Application/Sms/ApiResultViewModel.cs
Normal file
20
0_Framework/Application/Sms/ApiResultViewModel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application.Sms;
|
||||||
|
|
||||||
|
public class ApiResultViewModel
|
||||||
|
{
|
||||||
|
public int MessageId { get; set; }
|
||||||
|
public long LineNumber { get; set; }
|
||||||
|
public long Mobile { get; set; }
|
||||||
|
public string MessageText { get; set; }
|
||||||
|
public string SendUnixTime { get; set; }
|
||||||
|
public string DeliveryState { get; set; }
|
||||||
|
public string DeliveryUnixTime { get; set; }
|
||||||
|
public string DeliveryColor { get; set; }
|
||||||
|
public string FullName { get; set; }
|
||||||
|
}
|
||||||
18
0_Framework/Application/Sms/ISmsService.cs
Normal file
18
0_Framework/Application/Sms/ISmsService.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application.Sms;
|
||||||
|
|
||||||
|
public interface ISmsService
|
||||||
|
{
|
||||||
|
void Send(string number, string message);
|
||||||
|
bool VerifySend(string number, string message);
|
||||||
|
bool LoginSend(string number, string message);
|
||||||
|
bool SendAccountsInfo(string number,string fullName, string userName);
|
||||||
|
Task<ApiResultViewModel> GetByMessageId(int messId);
|
||||||
|
Task<List<ApiResultViewModel>> GetApiResult(string startDate, string endDate);
|
||||||
|
string DeliveryStatus(byte? dv);
|
||||||
|
string DeliveryColorStatus(byte? dv);
|
||||||
|
string UnixTimeStampToDateTime(int? unixTimeStamp);
|
||||||
|
}
|
||||||
288
0_Framework/Application/Sms/SmsService.cs
Normal file
288
0_Framework/Application/Sms/SmsService.cs
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
using System.Security.AccessControl;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using IPE.SmsIrClient;
|
||||||
|
using IPE.SmsIrClient.Models.Requests;
|
||||||
|
using IPE.SmsIrClient.Models.Results;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
|
||||||
|
namespace _0_Framework.Application.Sms;
|
||||||
|
|
||||||
|
public class SmsService : ISmsService
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
|
public SmsService(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Send(string number, string message)
|
||||||
|
{
|
||||||
|
//var token = GetToken();
|
||||||
|
//var lines = new SmsLine().GetSmsLines(token);
|
||||||
|
//if (lines == null) return;
|
||||||
|
|
||||||
|
//var line = lines.SMSLines.Last().LineNumber.ToString();
|
||||||
|
//var data = new MessageSendObject
|
||||||
|
//{
|
||||||
|
// Messages = new List<string>
|
||||||
|
// {message}.ToArray(),
|
||||||
|
// MobileNumbers = new List<string> {number}.ToArray(),
|
||||||
|
// LineNumber = line,
|
||||||
|
// SendDateTime = DateTime.Now,
|
||||||
|
// CanContinueInCaseOfError = true
|
||||||
|
//};
|
||||||
|
//var messageSendResponseObject =
|
||||||
|
// new MessageSend().Send(token, data);
|
||||||
|
|
||||||
|
//if (messageSendResponseObject.IsSuccessful) return;
|
||||||
|
|
||||||
|
//line = lines.SMSLines.First().LineNumber.ToString();
|
||||||
|
//data.LineNumber = line;
|
||||||
|
//new MessageSend().Send(token, data);
|
||||||
|
}
|
||||||
|
public bool VerifySend(string number, string message)
|
||||||
|
{
|
||||||
|
|
||||||
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
||||||
|
|
||||||
|
//var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" });
|
||||||
|
|
||||||
|
var verificationSendResult = smsIr.VerifySendAsync(number, 768382, new VerifySendParameter[] { new VerifySendParameter("VerificationCode", message) });
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
if (verificationSendResult.IsCompletedSuccessfully)
|
||||||
|
{
|
||||||
|
|
||||||
|
var resStartStatus = verificationSendResult.Result;
|
||||||
|
var b = resStartStatus.Status;
|
||||||
|
var resResult = verificationSendResult.Status;
|
||||||
|
var a = verificationSendResult.IsCompleted;
|
||||||
|
var reseExceptiont = verificationSendResult.Exception;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
var resStartStatus = verificationSendResult.Status;
|
||||||
|
var resResult = verificationSendResult.Status;
|
||||||
|
var reseExceptiont = verificationSendResult.Exception;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LoginSend(string number, string message)
|
||||||
|
{
|
||||||
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
||||||
|
|
||||||
|
//var bulkSendResult = smsIr.BulkSendAsync(95007079000006, "your text message", new string[] { "9120000000" });
|
||||||
|
|
||||||
|
var verificationSendResult = smsIr.VerifySendAsync(number, 635330, new VerifySendParameter[] { new VerifySendParameter("LOGINCODE", message) });
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
if (verificationSendResult.IsCompletedSuccessfully)
|
||||||
|
{
|
||||||
|
|
||||||
|
var resStartStatus = verificationSendResult.Result;
|
||||||
|
var b = resStartStatus.Status;
|
||||||
|
var resResult = verificationSendResult.Status;
|
||||||
|
var a = verificationSendResult.IsCompleted;
|
||||||
|
var reseExceptiont = verificationSendResult.Exception;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
var resStartStatus = verificationSendResult.Status;
|
||||||
|
var resResult = verificationSendResult.Status;
|
||||||
|
var reseExceptiont = verificationSendResult.Exception;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SendAccountsInfo(string number, string fullName, string userName)
|
||||||
|
{
|
||||||
|
|
||||||
|
var checkLength = fullName.Length;
|
||||||
|
if (checkLength > 25)
|
||||||
|
fullName = fullName.Substring(0, 24);
|
||||||
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
||||||
|
|
||||||
|
var sendResult = smsIr.VerifySendAsync(number, 725814, new VerifySendParameter[] { new VerifySendParameter("FULLNAME", fullName), new VerifySendParameter("USERNAME", userName), new VerifySendParameter("PASSWORD", userName) });
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine(userName + " - " + sendResult.Result.Status);
|
||||||
|
if (sendResult.IsCompletedSuccessfully)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ApiResultViewModel> GetByMessageId(int messId)
|
||||||
|
{
|
||||||
|
|
||||||
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
||||||
|
var response = await smsIr.GetReportAsync(messId);
|
||||||
|
MessageReportResult messages = response.Data;
|
||||||
|
|
||||||
|
var appendData = new ApiResultViewModel()
|
||||||
|
{
|
||||||
|
MessageId = messages.MessageId,
|
||||||
|
LineNumber = messages.LineNumber,
|
||||||
|
Mobile = messages.Mobile,
|
||||||
|
MessageText = messages.MessageText,
|
||||||
|
SendUnixTime = UnixTimeStampToDateTime(messages.SendDateTime),
|
||||||
|
DeliveryState = DeliveryStatus(messages.DeliveryState),
|
||||||
|
DeliveryUnixTime = UnixTimeStampToDateTime(messages.DeliveryDateTime),
|
||||||
|
DeliveryColor = DeliveryColorStatus(messages.DeliveryState),
|
||||||
|
};
|
||||||
|
return appendData;
|
||||||
|
}
|
||||||
|
public async Task<List<ApiResultViewModel>> GetApiResult(string startDate, string endDate)
|
||||||
|
{
|
||||||
|
var st = new DateTime(2024, 6, 2);
|
||||||
|
var ed = new DateTime(2024, 7, 1);
|
||||||
|
if (!string.IsNullOrWhiteSpace(startDate) && startDate.Length == 10)
|
||||||
|
{
|
||||||
|
st = startDate.ToGeorgianDateTime();
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(endDate) && endDate.Length == 10)
|
||||||
|
{
|
||||||
|
ed = endDate.ToGeorgianDateTime();
|
||||||
|
}
|
||||||
|
var res = new List<ApiResultViewModel>();
|
||||||
|
Int32 unixTimestamp = (int)st.Subtract(new DateTime(1970,1,1)).TotalSeconds;
|
||||||
|
Int32 unixTimestamp2 = (int)ed.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
int? fromDateUnixTime = null; // unix time - for instance: 1700598600
|
||||||
|
int? toDateUnixTime = null; // unix time - for instance: 1703190600
|
||||||
|
int pageNumber = 2;
|
||||||
|
int pageSize = 100; // max: 100
|
||||||
|
SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
||||||
|
var response = await smsIr.GetArchivedReportAsync(pageNumber, pageSize, unixTimestamp, unixTimestamp2);
|
||||||
|
|
||||||
|
|
||||||
|
MessageReportResult[] messages = response.Data;
|
||||||
|
foreach (var message in messages)
|
||||||
|
{
|
||||||
|
var appendData = new ApiResultViewModel()
|
||||||
|
{
|
||||||
|
MessageId = message.MessageId,
|
||||||
|
LineNumber = message.LineNumber,
|
||||||
|
Mobile = message.Mobile,
|
||||||
|
MessageText = message.MessageText,
|
||||||
|
SendUnixTime = UnixTimeStampToDateTime(message.SendDateTime),
|
||||||
|
DeliveryState = DeliveryStatus(message.DeliveryState),
|
||||||
|
DeliveryUnixTime = UnixTimeStampToDateTime(message.DeliveryDateTime),
|
||||||
|
DeliveryColor = DeliveryColorStatus(message.DeliveryState),
|
||||||
|
};
|
||||||
|
res.Add(appendData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DeliveryStatus(byte? dv)
|
||||||
|
{
|
||||||
|
string mess = "";
|
||||||
|
switch (dv)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
mess = "رسیده به گوشی";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mess = "نرسیده به گوشی";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
mess = "پردازش در مخابرات";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
mess = "نرسیده به مخابرات";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
mess = "سیده به مخابرات";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
mess = "خطا";
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
mess = "لیست سیاه";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mess="";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return mess;
|
||||||
|
}
|
||||||
|
public string DeliveryColorStatus(byte? dv)
|
||||||
|
{
|
||||||
|
string mess = "";
|
||||||
|
switch (dv)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
mess = "successSend";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mess = "errSend";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
mess = "pSend";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
mess = "noSend";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
mess = "itcSend";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
mess = "redSend";
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
mess = "blockSend";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mess = "";
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return mess;
|
||||||
|
}
|
||||||
|
public string UnixTimeStampToDateTime(int? unixTimeStamp)
|
||||||
|
{
|
||||||
|
if (unixTimeStamp != null)
|
||||||
|
{
|
||||||
|
// Unix timestamp is seconds past epoch
|
||||||
|
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
dateTime = dateTime.AddSeconds(Convert.ToDouble(unixTimeStamp)).ToLocalTime();
|
||||||
|
var time = dateTime.ToFarsiFull();
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
private string GetToken()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
//var smsSecrets = _configuration.GetSection("SmsSecrets");
|
||||||
|
//var tokenService = new Token();
|
||||||
|
//return tokenService.GetToken("x-api-key", "Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa");
|
||||||
|
}
|
||||||
|
}
|
||||||
1151
0_Framework/Application/Tools.cs
Normal file
1151
0_Framework/Application/Tools.cs
Normal file
File diff suppressed because it is too large
Load Diff
9
0_Framework/Application/ValidationMessages.cs
Normal file
9
0_Framework/Application/ValidationMessages.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public class ValidationMessages
|
||||||
|
{
|
||||||
|
public const string IsRequired = "این مقدار نمی تواند خالی باشد";
|
||||||
|
public const string MaxFileSize = "فایل حجیم تر از حد مجاز است";
|
||||||
|
public const string InvalidFileFormat = "فرمت فایل مجاز نیست";
|
||||||
|
public const string MaxLenght = "مقدار وارد شده بیش از طول مجاز است";
|
||||||
|
}
|
||||||
22
0_Framework/Application/Version.cs
Normal file
22
0_Framework/Application/Version.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace _0_Framework.Application;
|
||||||
|
|
||||||
|
public static class Version
|
||||||
|
{
|
||||||
|
static Version()
|
||||||
|
{
|
||||||
|
StyleVersion = "2.11.24";
|
||||||
|
AdminVersion = "2.5.8";
|
||||||
|
CameraVersion = "1.0.3";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string StyleVersion { get; set; }
|
||||||
|
public static string AdminVersion { get; set; }
|
||||||
|
public static string CameraVersion { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
15
0_Framework/Domain/EntityBase.cs
Normal file
15
0_Framework/Domain/EntityBase.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace _0_Framework.Domain;
|
||||||
|
|
||||||
|
public class EntityBase
|
||||||
|
{
|
||||||
|
public long id { get; set; }
|
||||||
|
public DateTime CreationDate { get; set; }
|
||||||
|
|
||||||
|
public EntityBase()
|
||||||
|
{
|
||||||
|
CreationDate=DateTime.Now;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
10
0_Framework/Domain/EntityBaseWithoutCreationDate.cs
Normal file
10
0_Framework/Domain/EntityBaseWithoutCreationDate.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace _0_Framework.Domain;
|
||||||
|
|
||||||
|
public class EntityBaseWithoutCreationDate
|
||||||
|
{
|
||||||
|
public long id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
0_Framework/Domain/IRepository.cs
Normal file
19
0_Framework/Domain/IRepository.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace _0_Framework.Domain;
|
||||||
|
|
||||||
|
public interface IRepository<TKey, T> where T:class
|
||||||
|
{
|
||||||
|
T Get(TKey id);
|
||||||
|
List<T> Get();
|
||||||
|
void Create(T entity);
|
||||||
|
|
||||||
|
bool Exists(Expression<Func<T, bool>> expression);
|
||||||
|
void SaveChanges();
|
||||||
|
Task SaveChangesAsync();
|
||||||
|
}
|
||||||
14
0_Framework/InfraStructure/NeedsPermissionAttribute.cs
Normal file
14
0_Framework/InfraStructure/NeedsPermissionAttribute.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace _0_Framework.Infrastructure
|
||||||
|
{
|
||||||
|
public class NeedsPermissionAttribute : Attribute
|
||||||
|
{
|
||||||
|
public int Permission { get; set; }
|
||||||
|
|
||||||
|
public NeedsPermissionAttribute(int permission)
|
||||||
|
{
|
||||||
|
Permission = permission;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
0_Framework/InfraStructure/PermissionDto.cs
Normal file
14
0_Framework/InfraStructure/PermissionDto.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace _0_Framework.Infrastructure
|
||||||
|
{
|
||||||
|
public class PermissionDto
|
||||||
|
{
|
||||||
|
public int Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public PermissionDto(int code, string name)
|
||||||
|
{
|
||||||
|
Code = code;
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
0_Framework/InfraStructure/RepositoryBase.cs
Normal file
59
0_Framework/InfraStructure/RepositoryBase.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace _0_Framework.InfraStructure
|
||||||
|
{
|
||||||
|
public class RepositoryBase<TKey, T> : IRepository<TKey, T> where T:class
|
||||||
|
{
|
||||||
|
private readonly DbContext _context;
|
||||||
|
|
||||||
|
public RepositoryBase(DbContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Create(T entity)
|
||||||
|
{
|
||||||
|
_context.Add(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Exists(Expression<Func<T, bool>> expression)
|
||||||
|
{
|
||||||
|
return _context.Set<T>().Any(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get(TKey id)
|
||||||
|
{
|
||||||
|
return _context.Find<T>(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> Get()
|
||||||
|
{
|
||||||
|
return _context.Set<T>().ToList();
|
||||||
|
}
|
||||||
|
public void Remove(T entity)
|
||||||
|
{
|
||||||
|
_context.Set<T>().Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveRange(IEnumerable<T> entities)
|
||||||
|
{
|
||||||
|
_context.Set<T>().RemoveRange(entities);
|
||||||
|
}
|
||||||
|
public void SaveChanges()
|
||||||
|
{
|
||||||
|
_context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SaveChangesAsync()
|
||||||
|
{
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
48
0_Framework/InfraStructure/Roles.cs
Normal file
48
0_Framework/InfraStructure/Roles.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace _0_Framework.Infrastructure
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public static class Roles
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public const string Administrator = "1";
|
||||||
|
public static readonly IList<string> role = new ReadOnlyCollection<string>(new List<string>
|
||||||
|
{
|
||||||
|
"1","2","3","4","5","6","7","8","9","10",
|
||||||
|
"11","12","13","14","15","16","17","18","19","20",
|
||||||
|
"21","22","23","24","25","26","27","28","29","30",
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//public const string SystemUser = "2";
|
||||||
|
//public const string ContentUploader = "10";
|
||||||
|
//public const string ColleagueUser = "10002";
|
||||||
|
|
||||||
|
//public static string GetRoleBy(long id)
|
||||||
|
//{
|
||||||
|
// switch (id)
|
||||||
|
// {
|
||||||
|
// case 1:
|
||||||
|
// return "مدیرسیستم";
|
||||||
|
// case 2:
|
||||||
|
// return "کاربر عادی";
|
||||||
|
// case 10:
|
||||||
|
// return "test 4";
|
||||||
|
// default:
|
||||||
|
// return "";
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class AccountSearchModel
|
||||||
|
{
|
||||||
|
public string Fullname { get; set; }
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
public long RoleId { get; set; }
|
||||||
|
public string RoleName { get; set; }
|
||||||
|
public string VerifyCode { get; set; }
|
||||||
|
public string IsActiveString { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class AccountViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Fullname { get; set; }
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
public long RoleId { get; set; }
|
||||||
|
public string Role { get; set; }
|
||||||
|
public string ProfilePhoto { get; set; }
|
||||||
|
public string CreationDate { get; set; }
|
||||||
|
public string RoleName { get; set; }
|
||||||
|
public string VerifyCode { get; set; }
|
||||||
|
public string IsActiveString { get; set; }
|
||||||
|
public DateTime CreationDateGr { get; set; }
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
public int PositionValue { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class ChangePassword
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
public string RePassword { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using _0_Framework.Application;
|
||||||
|
//using AccountManagement.Application.Contracts.Role;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using AccountManagement.Application.Contracts.Role;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class CreateAccount
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = ValidationMessages.IsRequired)]
|
||||||
|
public string Fullname { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = ValidationMessages.IsRequired)]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = ValidationMessages.IsRequired)]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "این مقدار نمی تواند خالی باشد")]
|
||||||
|
|
||||||
|
[RegularExpression("^[0-9]*$", ErrorMessage = "لطفا فقط عدد وارد کنید")]
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
|
||||||
|
public long RoleId { get; set; }
|
||||||
|
|
||||||
|
public IFormFile ProfilePhoto { get; set; }
|
||||||
|
public string ProfilePhotoStr { get; set; }
|
||||||
|
public List<RoleViewModel> Roles { get; set; }
|
||||||
|
|
||||||
|
public string AdminAreaPermission { get; set; }
|
||||||
|
public string ClientAriaPermission { get; set; }
|
||||||
|
public string NationalCode { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string VerifyCode { get; set; }
|
||||||
|
public string IsActiveString { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class EditAccount : CreateAccount
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class EditClientAccount : RegisterAccount
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using _0_Framework.Application;
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public interface IAccountApplication
|
||||||
|
{
|
||||||
|
AccountViewModel GetAccountBy(long id);
|
||||||
|
OperationResult Create(CreateAccount command);
|
||||||
|
OperationResult RegisterClient(RegisterAccount command);
|
||||||
|
OperationResult Edit(EditAccount command);
|
||||||
|
OperationResult EditClient(EditClientAccount command);
|
||||||
|
OperationResult ChangePassword(ChangePassword command);
|
||||||
|
OperationResult Login(Login command);
|
||||||
|
OperationResult LoginWithMobile(long id);
|
||||||
|
EditAccount GetDetails(long id);
|
||||||
|
List<AccountViewModel> Search(AccountSearchModel searchModel);
|
||||||
|
void Logout();
|
||||||
|
List<AccountViewModel> GetAccounts();
|
||||||
|
List<AccountViewModel> GetClientsAccount();
|
||||||
|
Task<OperationResult> SetVerifyCode(string phone, long id);
|
||||||
|
Task<OperationResult> SendVerifyCodeToChangingPass(string phone, long id);
|
||||||
|
EditAccount GetByVerifyCode(string code, string phone);
|
||||||
|
EditAccount GetByUserNameAndId(long id, string username);
|
||||||
|
OperationResult Active(long id);
|
||||||
|
OperationResult DeActive(long id);
|
||||||
|
OperationResult DirectLogin(long id);
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
List<AccountViewModel> AccountsForAssign(long accountId);
|
||||||
|
List<AccountViewModel> GetAccountsByPositionId(long positionId);
|
||||||
|
|
||||||
|
List<AccountViewModel> GetAccountLowerPositionvalue();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
8
AccountManagement.Application.Contracts/Account/Login.cs
Normal file
8
AccountManagement.Application.Contracts/Account/Login.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class Login
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Account
|
||||||
|
{
|
||||||
|
public class RegisterAccount
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "نام و نام خانوادگی نمی تواند خالی باشد")]
|
||||||
|
public string Fullname { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "نام کاربری نمی تواند خالی باشد")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "گذرواژه نمیتواند خالی باشد")]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "شماره موبایل نمی تواند خالی باشد")]
|
||||||
|
|
||||||
|
[RegularExpression("^[0-9]*$", ErrorMessage = "شماره موبایل معتبر وارد کنید")]
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "کد ملی نمی تواند خالی باشد")]
|
||||||
|
public string NationalCode { get; set; }
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public IFormFile ProfilePhoto { get; set; }
|
||||||
|
|
||||||
|
public long ContractingPartyId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\0_Framework\0_Framework.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
13
AccountManagement.Application.Contracts/Assign/AssignList.cs
Normal file
13
AccountManagement.Application.Contracts/Assign/AssignList.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
public class AssignList
|
||||||
|
{
|
||||||
|
public List<AssignViewModel> AssignViewModels { get; set; }
|
||||||
|
public int PosValue { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
public class AssignViewModel:EditAssign
|
||||||
|
{
|
||||||
|
public string AssignedName { get; set; }
|
||||||
|
public int AssignedPositionValue { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
public class CreateAssign
|
||||||
|
{
|
||||||
|
public long AssignerId { get; set; }
|
||||||
|
public List<long> AssignedId { get; set; }
|
||||||
|
public long TaskId { get; set; }
|
||||||
|
public int AssignerPositionValue { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
public class EditAssign:CreateAssign
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
|
||||||
|
public class CameraAccountSearchModel : EditCameraAccount
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
|
||||||
|
public class CameraAccountViewModel : EditCameraAccount
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
|
||||||
|
public class CreateCameraAccount
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
public string Mobile { get; set; }
|
||||||
|
public long WorkshopId { get; set; }
|
||||||
|
public string WorkshopName { get; set; }
|
||||||
|
public long AccountId { get; set; }
|
||||||
|
public string IsActiveString { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
|
||||||
|
public class EditCameraAccount : CreateCameraAccount
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
|
||||||
|
public interface ICameraAccountApplication
|
||||||
|
{
|
||||||
|
|
||||||
|
OperationResult Create(CreateCameraAccount command);
|
||||||
|
OperationResult Edit(EditCameraAccount command);
|
||||||
|
EditCameraAccount GetDetails(long id);
|
||||||
|
OperationResult Active(long id);
|
||||||
|
OperationResult DeActive(long id);
|
||||||
|
OperationResult ChangePass(ChangePassword command);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Media;
|
||||||
|
|
||||||
|
public class MediaViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace TaskManager.Application.Contract.Position;
|
||||||
|
|
||||||
|
public class CreatePosition
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int Value { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TaskManager.Application.Contract.Position;
|
||||||
|
|
||||||
|
public class EditPosition:CreatePosition
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
|
||||||
|
namespace TaskManager.Application.Contract.Position;
|
||||||
|
|
||||||
|
public interface IPositionApplication
|
||||||
|
{
|
||||||
|
OperationResult Create(CreatePosition command);
|
||||||
|
OperationResult SaveAccountPosition(List<AccountViewModel> command, long positionId);
|
||||||
|
List<AccountViewModel> GetNoPositionAccounts();
|
||||||
|
OperationResult Remove(long id);
|
||||||
|
OperationResult Edit(EditPosition command);
|
||||||
|
List<PositionViewModel> GetPositions();
|
||||||
|
OperationResult Save();
|
||||||
|
OperationResult RemoveAccountFromPosition(long positionId,long AccountId);
|
||||||
|
OperationResult RemoveAccountListFromPosition(List<long> accountIdList, long PositionId);
|
||||||
|
List<PositionViewModel> GetLowerPosition();
|
||||||
|
int GetLastPositionValue();
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TaskManager.Application.Contract.Position;
|
||||||
|
|
||||||
|
public class PositionViewModel:EditPosition
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
14
AccountManagement.Application.Contracts/Role/CreateRole.cs
Normal file
14
AccountManagement.Application.Contracts/Role/CreateRole.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Role
|
||||||
|
{
|
||||||
|
public class CreateRole
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = ValidationMessages.IsRequired)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
public List<int> Permissions { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
AccountManagement.Application.Contracts/Role/EditRole.cs
Normal file
18
AccountManagement.Application.Contracts/Role/EditRole.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Infrastructure;
|
||||||
|
|
||||||
|
//using _0_Framework.Infrastructure;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Role
|
||||||
|
{
|
||||||
|
public class EditRole : CreateRole
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public List<PermissionDto> MappedPermissions { get; set; }
|
||||||
|
|
||||||
|
public EditRole()
|
||||||
|
{
|
||||||
|
Permissions = new List<int>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using _0_Framework.Application;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Role
|
||||||
|
{
|
||||||
|
public interface IRoleApplication
|
||||||
|
{
|
||||||
|
OperationResult Create(CreateRole command);
|
||||||
|
OperationResult Edit(EditRole command);
|
||||||
|
List<RoleViewModel> List();
|
||||||
|
EditRole GetDetails(long id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Role
|
||||||
|
{
|
||||||
|
public class RoleViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string CreationDate { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public class CompleteTaskViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
}
|
||||||
27
AccountManagement.Application.Contracts/Task/CreateTask.cs
Normal file
27
AccountManagement.Application.Contracts/Task/CreateTask.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public class CreateTask
|
||||||
|
{
|
||||||
|
public long SenderId { get; set; }
|
||||||
|
public List<long> ReceiverId { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string EndTaskDate { get; set; }
|
||||||
|
public string EndTaskTime { get; set; }
|
||||||
|
public string ContractingPartyName { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public IFormFile Document1 { get; set; }
|
||||||
|
public IFormFile Document2 { get; set; }
|
||||||
|
public IFormFile Document3 { get; set; }
|
||||||
|
public IFormFile Document4 { get; set; }
|
||||||
|
public IFormFile Document5 { get; set; }
|
||||||
|
public IFormFile Document6 { get; set; }
|
||||||
|
public List<long> PositionId { get; set; }
|
||||||
|
|
||||||
|
public IFormFile Voice{ get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
public class CreateTaskCancel
|
||||||
|
{
|
||||||
|
public long TaskId { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public class CreateTaskTimeRequest
|
||||||
|
{
|
||||||
|
public long TaskId { get; set; }
|
||||||
|
public string RequestTime { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
9
AccountManagement.Application.Contracts/Task/EditTask.cs
Normal file
9
AccountManagement.Application.Contracts/Task/EditTask.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using AccountManagement.Application.Contracts.Media;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
public class EditTask:CreateTask
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public List<MediaViewModel> medias { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public interface ITaskApplication
|
||||||
|
{
|
||||||
|
OperationResult DeActiveTask(long TaskId);
|
||||||
|
OperationResult RemoveTask(long TaskId);
|
||||||
|
OperationResult RemoveFile(long MediaId);
|
||||||
|
OperationResult Edit(EditTask command);
|
||||||
|
|
||||||
|
OperationResult CreateAssign(CreateAssign command);
|
||||||
|
|
||||||
|
OperationResult CreateTask(CreateTask command);
|
||||||
|
OperationResult CreateTaskByPosition(CreateTask command);
|
||||||
|
EditTask GetDetails(long taskId);
|
||||||
|
//گرفتن تمامی وظایف
|
||||||
|
List<TaskViewModel> GetTasks(TaskSearchModel searchModel);
|
||||||
|
// گرفتن مهلت برای یک وظیفه
|
||||||
|
OperationResult CreateRequestTime(CreateTaskTimeRequest command);
|
||||||
|
//تایید مهلت وظیفه
|
||||||
|
OperationResult AcceptRequestDatetime(long taskId);
|
||||||
|
OperationResult RejectTimeRequest(long taskId);
|
||||||
|
//درخواست انصراف وظیفه
|
||||||
|
OperationResult CreateCancelRequest(CreateTaskCancel command);
|
||||||
|
//تایید اانصراف وظیفه
|
||||||
|
OperationResult AcceptCancelRequest(long taskId);
|
||||||
|
OperationResult RejectCancelRequest(long taskId);
|
||||||
|
|
||||||
|
OperationResult CompleteTask(CompleteTaskViewModel command);
|
||||||
|
OperationResult CreateTaskByPosition(CreateTask command, List<long> positionIds);
|
||||||
|
List<TaskViewModel> GetAllRequestedTasks(TaskSearchModel searchModel);
|
||||||
|
int GetRequestedTasksCount();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public class OperationModalViewModel
|
||||||
|
{
|
||||||
|
public List<AccountViewModel> Accounts { get; set; }
|
||||||
|
public long TaskId { get; set; }
|
||||||
|
public CreateAssign CreateAssign { get; set; }
|
||||||
|
public CreateTaskCancel CreateTaskCancel { get; set; }
|
||||||
|
public CreateTaskTimeRequest CreateTaskTimeRequest { get; set; }
|
||||||
|
public CompleteTaskViewModel CompleteTaskViewModel { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public class TaskSearchModel
|
||||||
|
{
|
||||||
|
public int PageIndex { get; set; }
|
||||||
|
public string StartDate { get; set; }
|
||||||
|
public string EndDate { get; set; }
|
||||||
|
public long AccountId { get; set; }
|
||||||
|
public string IsDone { get; set; }
|
||||||
|
public string IsCanceled { get; set; }
|
||||||
|
public string IsCancelRequest { get; set; }
|
||||||
|
public string IsTimeRequest { get; set; }
|
||||||
|
public string TimeRequestAccepted { get; set; }
|
||||||
|
public string TypeOfTicket { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
public class TaskViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public List<AssignViewModel> AssignViewModels { get; set; }
|
||||||
|
public List<AssignList> AssignList { get; set; }
|
||||||
|
public List<long> Assigned { get; set; }
|
||||||
|
public List<AccountViewModel> AssignedViewModel { get; set; }
|
||||||
|
public string CreateDate { get; set; }
|
||||||
|
public string EndTaskDateFA { get; set; }
|
||||||
|
public string EndTaskTime { get; set; }
|
||||||
|
public bool IsDone { get; set; }
|
||||||
|
public bool RequestCancel { get; set; }
|
||||||
|
public bool RequestTime { get; set; }
|
||||||
|
public bool IsCancel { get; set; }
|
||||||
|
public bool IsCancelRequest { get; set; }
|
||||||
|
public int AcceptedTimeRequest { get; set; }
|
||||||
|
public DateTime EndTaskDateGE { get; set; }
|
||||||
|
public DateTime CreateTaskDateGE { get; set; }
|
||||||
|
public string ContractingPartyName { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public AccountViewModel Sender { get; set; }
|
||||||
|
|
||||||
|
public string SelfName { get; set; }
|
||||||
|
public long SenderId { get; set; }
|
||||||
|
public string Color { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
public bool HasAttachment { get; set; }
|
||||||
|
public int MediaCount { get; set; }
|
||||||
|
public bool SelfAssigner { get; set; }
|
||||||
|
public bool SelfAssigned { get; set; }
|
||||||
|
public long AssignerId { get; set; }
|
||||||
|
public long AssignedId { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application.Contracts.TaskSubject;
|
||||||
|
|
||||||
|
public interface ITaskSubjectApplication
|
||||||
|
{
|
||||||
|
OperationResult Create(string subject);
|
||||||
|
OperationResult Edit(TaskSubjectViewModel command);
|
||||||
|
OperationResult Delete(long id);
|
||||||
|
List<TaskSubjectViewModel> GetAll();
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace AccountManagement.Application.Contracts.TaskSubject;
|
||||||
|
|
||||||
|
public class TaskSubjectViewModel
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string Subject { get; set; }
|
||||||
|
}
|
||||||
425
AccountManagement.Application/AccountApplication.cs
Normal file
425
AccountManagement.Application/AccountApplication.cs
Normal file
@@ -0,0 +1,425 @@
|
|||||||
|
using System;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Application.Sms;
|
||||||
|
using AccountManagement.Domain.CameraAccountAgg;
|
||||||
|
using AccountManagement.Domain.RoleAgg;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||||||
|
using TaskManager.Domain.PositionAgg;
|
||||||
|
//using AccountManagement.Domain.RoleAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application;
|
||||||
|
|
||||||
|
public class AccountApplication : IAccountApplication
|
||||||
|
{
|
||||||
|
private readonly IFileUploader _fileUploader;
|
||||||
|
private readonly IPasswordHasher _passwordHasher;
|
||||||
|
private readonly IAccountRepository _accountRepository;
|
||||||
|
private readonly IAuthHelper _authHelper;
|
||||||
|
private readonly IRoleRepository _roleRepository;
|
||||||
|
private readonly ISmsService _smsService;
|
||||||
|
private readonly ICameraAccountRepository _cameraAccountRepository;
|
||||||
|
private readonly IPositionRepository _positionRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public AccountApplication(IAccountRepository accountRepository, IPasswordHasher passwordHasher,
|
||||||
|
IFileUploader fileUploader, IAuthHelper authHelper, IRoleRepository roleRepository, IWorker worker, ISmsService smsService, ICameraAccountRepository cameraAccountRepository, IPositionRepository positionRepository)
|
||||||
|
{
|
||||||
|
_authHelper = authHelper;
|
||||||
|
_roleRepository = roleRepository;
|
||||||
|
_smsService = smsService;
|
||||||
|
_cameraAccountRepository = cameraAccountRepository;
|
||||||
|
_positionRepository = positionRepository;
|
||||||
|
_fileUploader = fileUploader;
|
||||||
|
_passwordHasher = passwordHasher;
|
||||||
|
_accountRepository = accountRepository;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult EditClient(EditClientAccount command)
|
||||||
|
{
|
||||||
|
var opreation = new OperationResult();
|
||||||
|
var editAccount = _accountRepository.Get(command.Id);
|
||||||
|
if (editAccount == null)
|
||||||
|
return opreation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
if (string.IsNullOrWhiteSpace(command.Fullname) || string.IsNullOrWhiteSpace(command.Username)
|
||||||
|
|| string.IsNullOrWhiteSpace(command.Mobile) ||
|
||||||
|
string.IsNullOrWhiteSpace(command.NationalCode))
|
||||||
|
return opreation.Failed("پر کردنموارد ستاره دار الزامی است");
|
||||||
|
|
||||||
|
if (_accountRepository.Exists(x =>
|
||||||
|
(x.Username == command.Username && x.id != command.Id)))
|
||||||
|
return opreation.Failed("نام کاربری تکراری است");
|
||||||
|
if (_accountRepository.Exists(x =>
|
||||||
|
(x.Mobile == command.Mobile && x.id != command.Id)))
|
||||||
|
return opreation.Failed("شماره موبایل تکراری است");
|
||||||
|
if (_accountRepository.Exists(x =>
|
||||||
|
(x.NationalCode == command.NationalCode && !string.IsNullOrWhiteSpace(x.NationalCode) && x.id != command.Id)))
|
||||||
|
return opreation.Failed("کد ملی تکراری است");
|
||||||
|
if (_accountRepository.Exists(x =>
|
||||||
|
(x.Email == command.Email && !string.IsNullOrWhiteSpace(x.Email) && x.id != command.Id)))
|
||||||
|
return opreation.Failed("ایمیل تکراری است");
|
||||||
|
|
||||||
|
var path = $"profilePhotos";
|
||||||
|
var picturePath = _fileUploader.Upload(command.ProfilePhoto, path);
|
||||||
|
editAccount.EditClient(command.Fullname,command.Username,command.Mobile,picturePath,command.Email,command.NationalCode);
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return opreation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult ChangePassword(ChangePassword command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.Get(command.Id);
|
||||||
|
if (account == null)
|
||||||
|
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
|
||||||
|
if (command.Password != command.RePassword)
|
||||||
|
return operation.Failed(ApplicationMessages.PasswordsNotMatch);
|
||||||
|
|
||||||
|
var password = _passwordHasher.Hash(command.Password);
|
||||||
|
account.ChangePassword(password);
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountViewModel GetAccountBy(long id)
|
||||||
|
{
|
||||||
|
var account = _accountRepository.Get(id);
|
||||||
|
return new AccountViewModel()
|
||||||
|
{
|
||||||
|
Fullname = account.Fullname,
|
||||||
|
Mobile = account.Mobile
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Create(CreateAccount command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
|
||||||
|
if (_accountRepository.Exists(x => x.Username == command.Username || x.Mobile == command.Mobile))
|
||||||
|
return operation.Failed(ApplicationMessages.DuplicatedRecord);
|
||||||
|
|
||||||
|
var password = _passwordHasher.Hash(command.Password);
|
||||||
|
var roleName = _roleRepository.GetDetails(command.RoleId);
|
||||||
|
var path = $"profilePhotos";
|
||||||
|
if (_fileUploader != null)
|
||||||
|
{
|
||||||
|
var picturePath = _fileUploader.Upload(command.ProfilePhoto, path);
|
||||||
|
var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId,
|
||||||
|
picturePath, roleName.Name,"true","false");
|
||||||
|
_accountRepository.Create(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult RegisterClient(RegisterAccount command)
|
||||||
|
{
|
||||||
|
var opreation = new OperationResult();
|
||||||
|
if (string.IsNullOrWhiteSpace(command.Fullname) || string.IsNullOrWhiteSpace(command.Username)
|
||||||
|
|| string.IsNullOrWhiteSpace(command.Mobile) ||
|
||||||
|
string.IsNullOrWhiteSpace(command.NationalCode)
|
||||||
|
|| string.IsNullOrWhiteSpace(command.Password))
|
||||||
|
return opreation.Failed("پر کردن تمامی فیلدها الزامی است");
|
||||||
|
if (_accountRepository.Exists(x => x.Username == command.Username))
|
||||||
|
return opreation.Failed("نام کاربری تکراری است");
|
||||||
|
if (_accountRepository.Exists(x => x.Mobile == command.Mobile ||
|
||||||
|
(x.NationalCode == command.NationalCode && !string.IsNullOrWhiteSpace(x.NationalCode))))
|
||||||
|
return opreation.Failed("مقادیر وارد شده تکراری است");
|
||||||
|
|
||||||
|
//var nationalCodeValidation = command.NationalCode.NationalCodeValid();
|
||||||
|
//switch (nationalCodeValidation)
|
||||||
|
//{
|
||||||
|
// case "incorrect":
|
||||||
|
// return opreation.Failed("اعداد وارد شده برای کد ملی صحیح نیست");
|
||||||
|
// break;
|
||||||
|
// case "invalid":
|
||||||
|
// return opreation.Failed("کد ملی وارد شده معتبر نیست");
|
||||||
|
// break;
|
||||||
|
// case "lessThan10":
|
||||||
|
// return opreation.Failed("کد ملی وارد شده کمتر از 10 رقم است");
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
var password = _passwordHasher.Hash(command.Password);
|
||||||
|
var register =new Account(command.Fullname,command.Username, password, command.Mobile, command.NationalCode);
|
||||||
|
_accountRepository.Create(register);
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
|
||||||
|
return opreation.Succcedded(register.id,message: "ثبت نام شما با موفقیت انجام شد");
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Edit(EditAccount command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.Get(command.Id);
|
||||||
|
if (account == null)
|
||||||
|
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
|
||||||
|
if (_accountRepository.Exists(x =>
|
||||||
|
(x.Username == command.Username || x.Mobile == command.Mobile) && x.id != command.Id))
|
||||||
|
return operation.Failed(ApplicationMessages.DuplicatedRecord);
|
||||||
|
|
||||||
|
var roleName = _roleRepository.GetDetails(command.RoleId);
|
||||||
|
var path = $"profilePhotos";
|
||||||
|
var picturePath = _fileUploader.Upload(command.ProfilePhoto, path);
|
||||||
|
account.Edit(command.Fullname, command.Username, command.Mobile, command.RoleId, picturePath, roleName.Name);
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditAccount GetDetails(long id)
|
||||||
|
{
|
||||||
|
return _accountRepository.GetDetails(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Login(Login command)
|
||||||
|
{
|
||||||
|
long idAutoriz = 0;
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.GetBy(command.Username);
|
||||||
|
var cameraAccount = _cameraAccountRepository.GetBy(command.Username);
|
||||||
|
if (account == null && cameraAccount == null)
|
||||||
|
return operation.Failed(ApplicationMessages.WrongUserPass);
|
||||||
|
|
||||||
|
if (account != null)
|
||||||
|
{
|
||||||
|
(bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(account.Password, command.Password);
|
||||||
|
if (!result.Verified)
|
||||||
|
return operation.Failed(ApplicationMessages.WrongUserPass);
|
||||||
|
var permissions = _roleRepository.Get(account.RoleId)
|
||||||
|
.Permissions
|
||||||
|
.Select(x => x.Code)
|
||||||
|
.ToList();
|
||||||
|
int? positionValue;
|
||||||
|
if (account.PositionId != null)
|
||||||
|
{
|
||||||
|
positionValue = _positionRepository.Get((long)account.PositionId).PositionValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
positionValue = null;
|
||||||
|
}
|
||||||
|
var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname
|
||||||
|
, account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, positionValue);
|
||||||
|
|
||||||
|
_authHelper.Signin(authViewModel);
|
||||||
|
|
||||||
|
if ((account.AdminAreaPermission == "true" && account.ClientAriaPermission == "true" && account.IsActiveString == "true") || (account.AdminAreaPermission == "true" && account.ClientAriaPermission == "false" && account.IsActiveString == "true"))
|
||||||
|
idAutoriz = 1;
|
||||||
|
|
||||||
|
if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false" && account.IsActiveString == "true")
|
||||||
|
idAutoriz = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cameraAccount != null)
|
||||||
|
{
|
||||||
|
(bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(cameraAccount.Password, command.Password);
|
||||||
|
if (!result.Verified)
|
||||||
|
return operation.Failed(ApplicationMessages.WrongUserPass);
|
||||||
|
|
||||||
|
var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile;
|
||||||
|
var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId,
|
||||||
|
cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId,cameraAccount.IsActiveSting);
|
||||||
|
if (cameraAccount.IsActiveSting == "true")
|
||||||
|
{
|
||||||
|
_authHelper.CameraSignIn(authViewModel);
|
||||||
|
idAutoriz = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
idAutoriz = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return operation.Succcedded(idAutoriz);
|
||||||
|
}
|
||||||
|
public OperationResult LoginWithMobile(long id)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.GetById(id);
|
||||||
|
if (account == null)
|
||||||
|
return operation.Failed(ApplicationMessages.WrongUserPass);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var permissions = _roleRepository.Get(account.RoleId)
|
||||||
|
.Permissions
|
||||||
|
.Select(x => x.Code)
|
||||||
|
.ToList();
|
||||||
|
int? positionValue;
|
||||||
|
if (account.PositionId != null)
|
||||||
|
{
|
||||||
|
positionValue = _positionRepository.Get((long)account.PositionId).PositionValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
positionValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname
|
||||||
|
, account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, positionValue);
|
||||||
|
|
||||||
|
_authHelper.Signin(authViewModel);
|
||||||
|
long idAutoriz = 0;
|
||||||
|
if (account.AdminAreaPermission == "true" && account.ClientAriaPermission == "true" || account.AdminAreaPermission == "true" && account.ClientAriaPermission == "false")
|
||||||
|
idAutoriz = 1;
|
||||||
|
|
||||||
|
if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false")
|
||||||
|
idAutoriz = 2;
|
||||||
|
return operation.Succcedded(idAutoriz);
|
||||||
|
}
|
||||||
|
public void Logout()
|
||||||
|
{
|
||||||
|
_authHelper.SignOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountViewModel> GetAccounts()
|
||||||
|
{
|
||||||
|
return _accountRepository.GetAccounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountViewModel> GetClientsAccount()
|
||||||
|
{
|
||||||
|
return _accountRepository.GetClientsAccount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<OperationResult> SendVerifyCodeToChangingPass(string phone, long id)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.Get(id);
|
||||||
|
if (account == null)
|
||||||
|
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
//var verifyCodeHash = _passwordHasher.Hash(verifyCode);
|
||||||
|
Random generator = new Random();
|
||||||
|
String r = generator.Next(1, 1000000).ToString("D6");
|
||||||
|
account.SetVerifyCode(r);
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
_smsService.VerifySend(phone, r);
|
||||||
|
|
||||||
|
TimeSpan delay = TimeSpan.FromSeconds(130);
|
||||||
|
await Task.Delay(delay);
|
||||||
|
|
||||||
|
account.SetVerifyCode("");
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
public EditAccount GetByVerifyCode(string code, string phone)
|
||||||
|
{
|
||||||
|
return _accountRepository.GetByVerifyCode(code, phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditAccount GetByUserNameAndId(long id, string username)
|
||||||
|
{
|
||||||
|
return _accountRepository.GetByUserNameAndId(id, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task <OperationResult> SetVerifyCode(string phone, long id)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.Get(id);
|
||||||
|
if (account == null || account.IsActiveString == "false")
|
||||||
|
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
//var verifyCodeHash = _passwordHasher.Hash(verifyCode);
|
||||||
|
Random generator = new Random();
|
||||||
|
String r = generator.Next(1, 1000000).ToString("D6");
|
||||||
|
account.SetVerifyCode(r);
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
_smsService.LoginSend(phone, r);
|
||||||
|
|
||||||
|
TimeSpan delay = TimeSpan.FromSeconds(130);
|
||||||
|
await Task.Delay(delay);
|
||||||
|
|
||||||
|
account.SetVerifyCode("");
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<AccountViewModel> Search(AccountSearchModel searchModel)
|
||||||
|
{
|
||||||
|
return _accountRepository.Search(searchModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Active(long id)
|
||||||
|
{
|
||||||
|
var opration = new OperationResult();
|
||||||
|
var acc = _accountRepository.Get(id);
|
||||||
|
if (acc == null)
|
||||||
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
||||||
|
|
||||||
|
acc.Active();
|
||||||
|
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return opration.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult DeActive(long id)
|
||||||
|
{
|
||||||
|
var opration = new OperationResult();
|
||||||
|
var acc = _accountRepository.Get(id);
|
||||||
|
if (acc == null)
|
||||||
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
||||||
|
|
||||||
|
acc.DeActive();
|
||||||
|
|
||||||
|
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return opration.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult DirectLogin(long id)
|
||||||
|
{
|
||||||
|
var prAcc = _authHelper.CurrentAccountInfo();
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _accountRepository.GetById(id);
|
||||||
|
if (account == null)
|
||||||
|
return operation.Failed("این اکان وجود ندارد");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var permissions = _roleRepository.Get(account.RoleId)
|
||||||
|
.Permissions
|
||||||
|
.Select(x => x.Code)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
|
||||||
|
_authHelper.SignOut();
|
||||||
|
var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname
|
||||||
|
, account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, "false", "true",null);
|
||||||
|
_authHelper.Signin(authViewModel);
|
||||||
|
return operation.Succcedded(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountViewModel> AccountsForAssign(long accountId)
|
||||||
|
{
|
||||||
|
return _accountRepository.AccountsForAssign(accountId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountViewModel> GetAccountsByPositionId(long positionId)
|
||||||
|
{
|
||||||
|
if (!_positionRepository.Exists(x => x.id == positionId))
|
||||||
|
{
|
||||||
|
return new List<AccountViewModel>();
|
||||||
|
}
|
||||||
|
return _accountRepository.GetAccountsByPositionId(positionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountViewModel> GetAccountLowerPositionvalue()
|
||||||
|
{
|
||||||
|
return _accountRepository.GetAccountLowerPositionvalue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AccountManagement.Application.Contracts\AccountManagement.Application.Contracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AccountManagement.Domain\AccountManagement.Domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
97
AccountManagement.Application/CameraAccountApplication.cs
Normal file
97
AccountManagement.Application/CameraAccountApplication.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
using AccountManagement.Domain.CameraAccountAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application;
|
||||||
|
|
||||||
|
public class CameraAccountApplication : ICameraAccountApplication
|
||||||
|
{
|
||||||
|
private readonly ICameraAccountRepository _cameraAccountRepository;
|
||||||
|
private readonly IPasswordHasher _passwordHasher;
|
||||||
|
|
||||||
|
public CameraAccountApplication(ICameraAccountRepository cameraAccountRepository, IPasswordHasher passwordHasher)
|
||||||
|
{
|
||||||
|
_cameraAccountRepository = cameraAccountRepository;
|
||||||
|
_passwordHasher = passwordHasher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Create(CreateCameraAccount command)
|
||||||
|
{
|
||||||
|
var opreation = new OperationResult();
|
||||||
|
if (string.IsNullOrWhiteSpace(command.Username) || string.IsNullOrWhiteSpace(command.Password))
|
||||||
|
return opreation.Failed("وارد کردن نام کاربری و گذرواژه الزامیست");
|
||||||
|
if (_cameraAccountRepository.Exists(x => x.Username == command.Username))
|
||||||
|
return opreation.Failed("نام کاربری تکراری است");
|
||||||
|
if (command.Password.Length < 8)
|
||||||
|
return opreation.Failed("گذرواژه نباید کمتر از 8 کاراکتر باشد");
|
||||||
|
if (command.Username.Length < 8)
|
||||||
|
return opreation.Failed("نام کاربری نباید کمتر از 8 کاراکتر باشد");
|
||||||
|
var password = _passwordHasher.Hash(command.Password);
|
||||||
|
var create = new CameraAccount(command.Username, password, command.Mobile, command.WorkshopName,
|
||||||
|
command.WorkshopId, command.AccountId);
|
||||||
|
_cameraAccountRepository.Create(create);
|
||||||
|
_cameraAccountRepository.SaveChanges();
|
||||||
|
return opreation.Succcedded();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Edit(EditCameraAccount command)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditCameraAccount GetDetails(long id)
|
||||||
|
{
|
||||||
|
return _cameraAccountRepository.GetDetails(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Active(long id)
|
||||||
|
{
|
||||||
|
var opration = new OperationResult();
|
||||||
|
var acc = _cameraAccountRepository.Get(id);
|
||||||
|
if (acc == null)
|
||||||
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
||||||
|
|
||||||
|
acc.Active();
|
||||||
|
|
||||||
|
_cameraAccountRepository.SaveChanges();
|
||||||
|
return opration.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult DeActive(long id)
|
||||||
|
{
|
||||||
|
var opration = new OperationResult();
|
||||||
|
var acc = _cameraAccountRepository.Get(id);
|
||||||
|
if (acc == null)
|
||||||
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
||||||
|
|
||||||
|
acc.DeActive();
|
||||||
|
|
||||||
|
_cameraAccountRepository.SaveChanges();
|
||||||
|
return opration.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult ChangePass(ChangePassword command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var account = _cameraAccountRepository.Get(command.Id);
|
||||||
|
if (account == null)
|
||||||
|
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
|
||||||
|
if (command.Password != command.RePassword)
|
||||||
|
return operation.Failed(ApplicationMessages.PasswordsNotMatch);
|
||||||
|
if (command.Password.Length < 8)
|
||||||
|
return operation.Failed("تعداد کاراکترهای گذرواژه نباید کمتر از 8 باشد");
|
||||||
|
|
||||||
|
var password = _passwordHasher.Hash(command.Password);
|
||||||
|
account.ChangePassword(password);
|
||||||
|
_cameraAccountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
}
|
||||||
169
AccountManagement.Application/PositionApplication.cs
Normal file
169
AccountManagement.Application/PositionApplication.cs
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
|
||||||
|
using TaskManager.Application.Contract.Position;
|
||||||
|
using TaskManager.Domain.PositionAgg;
|
||||||
|
|
||||||
|
namespace TaskManager.Application;
|
||||||
|
|
||||||
|
public class PositionApplication:IPositionApplication
|
||||||
|
{
|
||||||
|
private readonly IPositionRepository _positionRepository;
|
||||||
|
private readonly IAccountRepository _accountRepository;
|
||||||
|
private readonly IAccountApplication _accountApplication;
|
||||||
|
|
||||||
|
public PositionApplication(IPositionRepository positionRepository, IAccountRepository accountRepository, IAccountApplication accountApplication)
|
||||||
|
{
|
||||||
|
_positionRepository = positionRepository;
|
||||||
|
_accountRepository = accountRepository;
|
||||||
|
_accountApplication = accountApplication;
|
||||||
|
}
|
||||||
|
//ساخت پوزیشن
|
||||||
|
public OperationResult Create(CreatePosition command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (string.IsNullOrWhiteSpace(command.Name))
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا نام سمت را وارد کنید");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.Value==0)
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا سطح سمت را وارد کنید");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.Value>5)
|
||||||
|
{
|
||||||
|
return operation.Failed(" سطح سمت وارد شده معتبر نمیباشد");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_positionRepository.Exists(x=>x.PositionValue==command.Value))
|
||||||
|
{
|
||||||
|
return operation.Failed("سطح انتخاب شده قبلا تعریف شده است");
|
||||||
|
}
|
||||||
|
|
||||||
|
var position = new Position(command.Name, command.Value);
|
||||||
|
_positionRepository.Create(position);
|
||||||
|
_positionRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(position.id);
|
||||||
|
}
|
||||||
|
//ذخیره لیست پرسنل برای سمت خود
|
||||||
|
public OperationResult SaveAccountPosition(List<AccountViewModel> command, long positionId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_positionRepository.Exists(x=>x.id==positionId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین سمتی وجود ندارد");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.Count<1)
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا شخصی برای ذخیره انتخاب کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var accountViewModel in command)
|
||||||
|
{
|
||||||
|
var account = _accountRepository.Get(accountViewModel.Id);
|
||||||
|
account.SetPosition(positionId);
|
||||||
|
}
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(positionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountViewModel> GetNoPositionAccounts()
|
||||||
|
{
|
||||||
|
return _positionRepository.GetNoPositionAccounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Remove(long id)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_positionRepository.Exists(x=>x.id==id))
|
||||||
|
{
|
||||||
|
return operation.Failed("سمت مورد نظر یافت نشد");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_accountApplication.GetAccountsByPositionId(id).Count>0)
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید سمتی که در آن شخصی وجود دارد را حذف کنید.");
|
||||||
|
}
|
||||||
|
|
||||||
|
_positionRepository.Remove(id);
|
||||||
|
_positionRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
//ویرایش پوزیشن
|
||||||
|
public OperationResult Edit(EditPosition command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (_positionRepository.Exists(x=>x.id!=command.Id&&x.PositionName==command.Name))
|
||||||
|
{
|
||||||
|
return operation.Failed("سمتی با این نام وجود دارد");
|
||||||
|
}
|
||||||
|
if (_positionRepository.Exists(x => x.id != command.Id && x.PositionValue == command.Value))
|
||||||
|
{
|
||||||
|
return operation.Failed("سمتی با این سطح وجود دارد");
|
||||||
|
}
|
||||||
|
|
||||||
|
var position = _positionRepository.Get(command.Id);
|
||||||
|
position.Edit(command.Name,command.Value);
|
||||||
|
_positionRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(command.Id);
|
||||||
|
|
||||||
|
}
|
||||||
|
//گرفتن تمامی پوزیشن ها برای نمایش
|
||||||
|
public List<PositionViewModel> GetPositions()=>
|
||||||
|
_positionRepository.GetPositions();
|
||||||
|
//ذخیره پوزیشن
|
||||||
|
public OperationResult Save()
|
||||||
|
{
|
||||||
|
_positionRepository.SaveChanges();
|
||||||
|
return new OperationResult().Succcedded();
|
||||||
|
}
|
||||||
|
//حذف یک شخص از یک گروه
|
||||||
|
public OperationResult RemoveAccountFromPosition(long positionId, long AccountId)
|
||||||
|
{
|
||||||
|
var operation=new OperationResult();
|
||||||
|
if (!_accountRepository.Exists(x => x.id == AccountId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین شخصی وجود ندارد");
|
||||||
|
}
|
||||||
|
var account = _accountRepository.GetIncludePositions(AccountId);
|
||||||
|
if (account.Position.id != positionId)
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین شخصی در این گروه وجود ندارد");
|
||||||
|
}
|
||||||
|
account.DeletePositionId();
|
||||||
|
_positionRepository.SaveChanges();
|
||||||
|
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
//حذف یک لیستی از اشخاص از یک گروه
|
||||||
|
public OperationResult RemoveAccountListFromPosition(List<long> accountIdList, long PositionId)
|
||||||
|
{
|
||||||
|
var operation= new OperationResult();
|
||||||
|
foreach (var account in accountIdList)
|
||||||
|
{
|
||||||
|
var acc = _accountRepository.GetIncludePositions(account);
|
||||||
|
acc.DeletePositionId();
|
||||||
|
}
|
||||||
|
_accountRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PositionViewModel> GetLowerPosition()
|
||||||
|
{
|
||||||
|
return _positionRepository.GetLowerPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
//گرفتن بالاترین سطح قابل ذخیره
|
||||||
|
public int GetLastPositionValue()
|
||||||
|
{
|
||||||
|
return _positionRepository.GetLastPositionValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
73
AccountManagement.Application/RoleApplication.cs
Normal file
73
AccountManagement.Application/RoleApplication.cs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Role;
|
||||||
|
using AccountManagement.Domain.RoleAgg;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application;
|
||||||
|
|
||||||
|
public class RoleApplication : IRoleApplication
|
||||||
|
{
|
||||||
|
private readonly IRoleRepository _roleRepository;
|
||||||
|
|
||||||
|
public RoleApplication(IRoleRepository roleRepository)
|
||||||
|
{
|
||||||
|
_roleRepository = roleRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Create(CreateRole command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (_roleRepository.Exists(x => x.Name == command.Name))
|
||||||
|
return operation.Failed(ApplicationMessages.DuplicatedRecord);
|
||||||
|
var permissions = new List<Permission>();
|
||||||
|
foreach (var code in command.Permissions)
|
||||||
|
{
|
||||||
|
if (code > 0)
|
||||||
|
{
|
||||||
|
permissions.Add(new Permission(code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//command.Permissions.ForEach(code => permissions.Add(new Permission(code)));
|
||||||
|
var role = new Role(command.Name, permissions);
|
||||||
|
_roleRepository.Create(role);
|
||||||
|
_roleRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Edit(EditRole command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var role = _roleRepository.Get(command.Id);
|
||||||
|
if (role == null)
|
||||||
|
return operation.Failed(ApplicationMessages.RecordNotFound);
|
||||||
|
|
||||||
|
if (_roleRepository.Exists(x => x.Name == command.Name && x.id != command.Id))
|
||||||
|
return operation.Failed(ApplicationMessages.DuplicatedRecord);
|
||||||
|
|
||||||
|
//var permissions = new List<Permission>();
|
||||||
|
//command.Permissions.ForEach(code => permissions.Add(new Permission(code)));
|
||||||
|
|
||||||
|
var permissions = new List<Permission>();
|
||||||
|
foreach (var code in command.Permissions)
|
||||||
|
{
|
||||||
|
if (code > 0)
|
||||||
|
{
|
||||||
|
permissions.Add(new Permission(code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
role.Edit(command.Name, permissions);
|
||||||
|
_roleRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditRole GetDetails(long id)
|
||||||
|
{
|
||||||
|
return _roleRepository.GetDetails(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RoleViewModel> List()
|
||||||
|
{
|
||||||
|
return _roleRepository.List();
|
||||||
|
}
|
||||||
|
}
|
||||||
998
AccountManagement.Application/TaskApplication.cs
Normal file
998
AccountManagement.Application/TaskApplication.cs
Normal file
@@ -0,0 +1,998 @@
|
|||||||
|
using _0_Framework.Application;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using AccountManagement.Application.Contracts.Assign;
|
||||||
|
using AccountManagement.Application.Contracts.Task;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
using AccountManagement.Domain.AssignAgg;
|
||||||
|
using AccountManagement.Domain.MediaAgg;
|
||||||
|
using AccountManagement.Domain.TaskAgg;
|
||||||
|
using IPE.SmsIrClient.Models.Results;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using TaskManager.Domain.PositionAgg;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AccountManagement.Application;
|
||||||
|
|
||||||
|
public class TaskApplication : ITaskApplication
|
||||||
|
{
|
||||||
|
private readonly ITaskRepository _taskRepository;
|
||||||
|
private readonly IAccountRepository _accountRepository;
|
||||||
|
private readonly IMediaRepository _mediaRepository;
|
||||||
|
private readonly IPositionRepository _positionRepository;
|
||||||
|
private readonly IAssignRepository _assignRepository;
|
||||||
|
private readonly IHttpContextAccessor _contextAccessor;
|
||||||
|
|
||||||
|
|
||||||
|
public TaskApplication(ITaskRepository taskRepository, IAccountRepository accountRepository, IMediaRepository mediaRepository, IAssignRepository assignRepository, IHttpContextAccessor contextAccessor, IPositionRepository positionRepository)
|
||||||
|
{
|
||||||
|
_taskRepository = taskRepository;
|
||||||
|
_accountRepository = accountRepository;
|
||||||
|
_mediaRepository = mediaRepository;
|
||||||
|
_assignRepository = assignRepository;
|
||||||
|
_contextAccessor = contextAccessor;
|
||||||
|
_positionRepository = positionRepository;
|
||||||
|
}
|
||||||
|
//غیرفعال سازی تسک
|
||||||
|
public OperationResult DeActiveTask(long TaskId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == TaskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای برای حذف وجود ندارد!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var task = _taskRepository.Get(TaskId);
|
||||||
|
task.DeActive();
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
|
||||||
|
}
|
||||||
|
//حذف کامل تسک
|
||||||
|
public OperationResult RemoveTask(long TaskId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == TaskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای برای حذف وجود ندارد!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var task = _taskRepository.Get(TaskId);
|
||||||
|
var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value);
|
||||||
|
var sender = _accountRepository.GetIncludePositions(task.SenderId);
|
||||||
|
if (sender.Position.PositionValue < positionValue)
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتواند وظیفه ای که سطحی از شما پایین تر دارد را حذف کنید");
|
||||||
|
}
|
||||||
|
var medias = _mediaRepository.GetMediaByTaskId(TaskId);
|
||||||
|
if (task.IsCanceledRequest || task.IsDone || task.IsCancel || task.TimeRequest || task.AcceptedTimeRequest > 0)
|
||||||
|
{
|
||||||
|
task.DeActive();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var item in medias)
|
||||||
|
{
|
||||||
|
RemoveFile(item.Id);
|
||||||
|
}
|
||||||
|
_taskRepository.Remove(task.id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
//حذف فایلی در تسک
|
||||||
|
public OperationResult RemoveFile(long MediaId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_mediaRepository.Exists(x => x.id == MediaId))
|
||||||
|
{
|
||||||
|
operation.Failed("چنین فایلی وجود ندارد");
|
||||||
|
}
|
||||||
|
var media = _mediaRepository.Get(MediaId);
|
||||||
|
File.Delete(media.Path);
|
||||||
|
_mediaRepository.Remove(media.id);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
//ویرایش تسک
|
||||||
|
public OperationResult Edit(EditTask command)
|
||||||
|
{
|
||||||
|
var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value);
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (string.IsNullOrEmpty(command.Title))
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(command.EndTaskDate))
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.ReceiverId.Count < 1)
|
||||||
|
{
|
||||||
|
return operation.Failed("طرف وظیفه خود را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.SenderId < 1)
|
||||||
|
{
|
||||||
|
return operation.Failed("خطای سیستمی!!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var sender = _accountRepository.GetIncludePositions(command.SenderId);
|
||||||
|
if (sender.Position.PositionValue < posValue)
|
||||||
|
{
|
||||||
|
return operation.Failed("شما حق ویرایش این وظیفه را ندارید");
|
||||||
|
}
|
||||||
|
var task = _taskRepository.Get(command.Id);
|
||||||
|
var endTask = command.EndTaskDate.ToGeorgianDateTime();
|
||||||
|
task.Edit(command.Title, endTask, command.Description, command.SenderId);
|
||||||
|
|
||||||
|
|
||||||
|
#region ChangeMedias
|
||||||
|
|
||||||
|
#region SaveDocuments
|
||||||
|
|
||||||
|
if ((command.Document1?.Length > 2000000) || (command.Document2?.Length > 2000000) || (command.Document3?.Length > 2000000))
|
||||||
|
return operation.Failed("حجم فایل نمیتواند از 2 مگابایت بیشتر باشد");
|
||||||
|
|
||||||
|
if (command.Document1?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document1.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (command.Document2?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document2.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (command.Document3?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document3.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (command.Document4?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document4.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (command.Document5?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document5.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (command.Document6?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document6.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document6.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (command.Voice?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Voice.FileName);
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Voice.CopyTo(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_mediaRepository.Exists(x => x.Path == filepath))
|
||||||
|
{
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "صوت");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
//ساخت یک ارجاع دهنده
|
||||||
|
public OperationResult CreateAssign(CreateAssign command)
|
||||||
|
{
|
||||||
|
var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value);
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == command.TaskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
if (!_accountRepository.Exists(x => x.id == command.AssignerId))
|
||||||
|
{
|
||||||
|
return operation.Failed("خطای سیستمی!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var assignedId in command.AssignedId)
|
||||||
|
{
|
||||||
|
if (!_accountRepository.Exists(x => x.id == assignedId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین شخصی برای ارجاع وجود ندارد.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var assigner = _accountRepository.GetIncludePositions(command.AssignerId);
|
||||||
|
foreach (var assignedId in command.AssignedId)
|
||||||
|
{
|
||||||
|
var assigned = _accountRepository.GetIncludePositions(assignedId);
|
||||||
|
|
||||||
|
var assign = new Assign(command.TaskId, command.AssignerId, assignedId, assigner.Position.PositionValue,
|
||||||
|
assigned.Fullname, assigned.Position.PositionValue);
|
||||||
|
_assignRepository.Create(assign);
|
||||||
|
}
|
||||||
|
_assignRepository.SaveChanges();
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
//ساخت تسک
|
||||||
|
public OperationResult CreateTask(CreateTask command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (string.IsNullOrEmpty(command.Title))
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(command.EndTaskDate))
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(command.ContractingPartyName))
|
||||||
|
{
|
||||||
|
return operation.Failed("لطفا طرف حساب خودرا وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (command.SenderId < 1)
|
||||||
|
{
|
||||||
|
return operation.Failed("خطای سیستمی!!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var sender = _accountRepository.GetIncludePositions(command.SenderId);
|
||||||
|
|
||||||
|
if (command.PositionId?.Count > 0 && command.ReceiverId?.Count > 0)
|
||||||
|
{
|
||||||
|
if (command.PositionId.Any(x => x > 0))
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید همرمان به صورت انفرادی و هم به صورت گروهی تسک دهید. ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command.PositionId?.Count > 0)
|
||||||
|
{
|
||||||
|
var res = CreateTaskByPosition(command);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (command.ReceiverId.Count < 1)
|
||||||
|
{
|
||||||
|
return operation.Failed("طرف وظیفه خود را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
var receivers = _accountRepository.GetAccountsByIds(command.ReceiverId);
|
||||||
|
|
||||||
|
if (sender.Position.PositionValue == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (receivers.Any(x => sender.Position.PositionValue > x.Position.PositionValue))
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید به سطح بالاتر خود وظیفه ای دهید");
|
||||||
|
}
|
||||||
|
else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (receivers.Any(x => sender.Position.PositionValue == x.Position.PositionValue))
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید به هم سطح خود وظیفه ای دهید");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DateTime endTask;
|
||||||
|
endTask = string.IsNullOrWhiteSpace(command.EndTaskTime) ? command.EndTaskDate.ToGeorgianDateTime2() : command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName);
|
||||||
|
_taskRepository.Create(task);
|
||||||
|
_assignRepository.SaveChanges();
|
||||||
|
foreach (var receiver in receivers)
|
||||||
|
{
|
||||||
|
var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname,
|
||||||
|
receiver.Position.PositionValue);
|
||||||
|
_assignRepository.Create(assign);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region SaveMedias
|
||||||
|
|
||||||
|
#region SaveDocuments
|
||||||
|
|
||||||
|
if ((command.Document1?.Length > 2000000) || (command.Document2?.Length > 2000000) || (command.Document3?.Length > 2000000))
|
||||||
|
return operation.Failed("حجم فایل نمیتواند از 2 مگابایت بیشتر باشد");
|
||||||
|
|
||||||
|
if (command.Document1?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document1.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document2?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document2.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document3?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document3.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document4?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document4.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document5?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document5.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document6?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document6.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document6.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (command.Voice?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Voice.FileName);
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Voice.CopyTo(stream);
|
||||||
|
}
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "صوت");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult CreateTaskByPosition(CreateTask command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var sender = _accountRepository.GetIncludePositions(command.SenderId);
|
||||||
|
|
||||||
|
var receivers = _positionRepository.GetAccountsByIds(command.PositionId);
|
||||||
|
|
||||||
|
|
||||||
|
if (sender.Position.PositionValue == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (receivers.Any(x => sender.Position.PositionValue > x.Position.PositionValue))
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید به سطح بالاتر خود وظیفه ای دهید");
|
||||||
|
}
|
||||||
|
else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (receivers.Any(x => sender.Position.PositionValue == x.Position.PositionValue))
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید به هم سطح خود وظیفه ای دهید");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DateTime endTask;
|
||||||
|
if (string.IsNullOrWhiteSpace(command.EndTaskTime))
|
||||||
|
{
|
||||||
|
endTask = command.EndTaskDate.ToGeorgianDateTime2();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
endTask = command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName);
|
||||||
|
_taskRepository.Create(task);
|
||||||
|
_assignRepository.SaveChanges();
|
||||||
|
foreach (var receiver in receivers)
|
||||||
|
{
|
||||||
|
var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname,
|
||||||
|
receiver.Position.PositionValue);
|
||||||
|
_assignRepository.Create(assign);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region SaveMedias
|
||||||
|
|
||||||
|
#region SaveDocuments
|
||||||
|
|
||||||
|
if ((command.Document1?.Length > 2000000) || (command.Document2?.Length > 2000000) || (command.Document3?.Length > 2000000))
|
||||||
|
return operation.Failed("حجم فایل نمیتواند از 2 مگابایت بیشتر باشد");
|
||||||
|
|
||||||
|
if (command.Document1?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document1.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document2?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document2.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document3?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document3.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document4?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document4.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document5?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document5.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
if (command.Document6?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Document6.FileName);
|
||||||
|
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Document6.CopyTo(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "فایل");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (command.Voice?.Length > 0)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
||||||
|
"Task", $"{task.id}");
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
string filepath = Path.Combine(path, command.Voice.FileName);
|
||||||
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
||||||
|
{
|
||||||
|
command.Voice.CopyTo(stream);
|
||||||
|
}
|
||||||
|
var type = Path.GetExtension(filepath);
|
||||||
|
var media = new Media(filepath, type, "صوت");
|
||||||
|
_mediaRepository.Create(media);
|
||||||
|
_mediaRepository.SaveChanges();
|
||||||
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ویرایش تسک
|
||||||
|
public EditTask GetDetails(long taskId)
|
||||||
|
{
|
||||||
|
return _taskRepository.GetDetails(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//لیست کامل تسک ها
|
||||||
|
public List<TaskViewModel> GetTasks(TaskSearchModel searchModel)
|
||||||
|
{
|
||||||
|
var test = _taskRepository.GetTasks(searchModel);
|
||||||
|
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
//ساخت درخواست مهلت
|
||||||
|
public OperationResult CreateRequestTime(CreateTaskTimeRequest command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (command.TaskId == 0)
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(command.Description))
|
||||||
|
{
|
||||||
|
return operation.Failed("توضیحات خود را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(command.RequestTime))
|
||||||
|
{
|
||||||
|
return operation.Failed("مهلت درخواستی خود را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
var task = _taskRepository.Get(command.TaskId);
|
||||||
|
var requestTime = command.RequestTime.ToGeorgianDateTime();
|
||||||
|
task.CreateTimeRequest(requestTime, command.Description);
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
//تایید درخواست مهلت
|
||||||
|
public OperationResult AcceptRequestDatetime(long taskId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == taskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
|
||||||
|
var task = _taskRepository.Get(taskId);
|
||||||
|
if (!task.TimeRequest)
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.RequestDate == null)
|
||||||
|
{
|
||||||
|
return operation.Failed("تاریخی برای درخواست وظیفه ثبت نشده است");
|
||||||
|
}
|
||||||
|
task.AcceptTimeRequest();
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
//ساخت درخواست کنسل
|
||||||
|
public OperationResult CreateCancelRequest(CreateTaskCancel command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (string.IsNullOrWhiteSpace(command.Description))
|
||||||
|
{
|
||||||
|
return operation.Failed("توضیحات خود را وارد کنید");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_taskRepository.Exists(x => x.id == command.TaskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
var task = _taskRepository.Get(command.TaskId);
|
||||||
|
task.CreateCancelRequest(command.Description);
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
//تایید درخواست کنسل
|
||||||
|
public OperationResult AcceptCancelRequest(long taskId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == taskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
var task = _taskRepository.Get(taskId);
|
||||||
|
if (!task.IsCanceledRequest)
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد");
|
||||||
|
}
|
||||||
|
task.AcceptCancelRequest();
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(taskId);
|
||||||
|
}
|
||||||
|
//انجام شدن تسک
|
||||||
|
public OperationResult CompleteTask(CompleteTaskViewModel command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == command.Id))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
var task = _taskRepository.Get(command.Id);
|
||||||
|
task.Completed(command.Description);
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
//لغو درخواست کنسل تسک
|
||||||
|
public OperationResult RejectCancelRequest(long taskId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == taskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
var task = _taskRepository.Get(taskId);
|
||||||
|
if (!task.IsCanceledRequest)
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد");
|
||||||
|
}
|
||||||
|
task.RejectCancel();
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(taskId);
|
||||||
|
}
|
||||||
|
//لغو درخواست مهلت تسک
|
||||||
|
public OperationResult RejectTimeRequest(long taskId)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
if (!_taskRepository.Exists(x => x.id == taskId))
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای وجود ندارد");
|
||||||
|
}
|
||||||
|
|
||||||
|
var task = _taskRepository.Get(taskId);
|
||||||
|
if (!task.TimeRequest)
|
||||||
|
{
|
||||||
|
return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد");
|
||||||
|
}
|
||||||
|
task.RejectTimeRequest();
|
||||||
|
_taskRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(task.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult CreateTaskByPosition(CreateTask command, List<long> positionIds)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value);
|
||||||
|
var positions = new List<Position>();
|
||||||
|
foreach (var positionId in positionIds)
|
||||||
|
{
|
||||||
|
var position = _positionRepository.Get(positionId);
|
||||||
|
positions.Add(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (positions.Any(x => x.PositionValue <= positionValue))
|
||||||
|
{
|
||||||
|
return operation.Failed("شما نمیتوانید به گروه هم سطح یا سطح بالاتر خود تسکی دهد");
|
||||||
|
}
|
||||||
|
|
||||||
|
var receiverIds = new List<long>();
|
||||||
|
foreach (var positionId in positionIds)
|
||||||
|
{
|
||||||
|
var acc = _accountRepository.GetAccountsByPositionId(positionId).Select(x => x.Id).ToList();
|
||||||
|
receiverIds.AddRange(acc);
|
||||||
|
}
|
||||||
|
|
||||||
|
command.ReceiverId = receiverIds;
|
||||||
|
operation = CreateTask(command);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskViewModel> GetAllRequestedTasks(TaskSearchModel searchModel)
|
||||||
|
{
|
||||||
|
return _taskRepository.GetAllRequestedTasks(searchModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetRequestedTasksCount()
|
||||||
|
{
|
||||||
|
return _taskRepository.GetRequestedTasksCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
80
AccountManagement.Application/TaskSubjectApplication.cs
Normal file
80
AccountManagement.Application/TaskSubjectApplication.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using AccountManagement.Application.Contracts.TaskSubject;
|
||||||
|
using AccountManagement.Domain.TaskSubjectAgg;
|
||||||
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||||||
|
|
||||||
|
namespace AccountManagement.Application;
|
||||||
|
|
||||||
|
public class TaskSubjectApplication : ITaskSubjectApplication
|
||||||
|
{
|
||||||
|
private readonly ITaskSubjectRepository _taskSubjectRepository;
|
||||||
|
|
||||||
|
public TaskSubjectApplication(ITaskSubjectRepository taskSubjectRepository)
|
||||||
|
{
|
||||||
|
_taskSubjectRepository = taskSubjectRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Create(string subject)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (subject.Length > 100)
|
||||||
|
{
|
||||||
|
return operation.Failed("عنوان نمیتواند بیشتر از 100 کاراکتر باشد");
|
||||||
|
}
|
||||||
|
|
||||||
|
var taskSubject = new TaskSubject(subject);
|
||||||
|
_taskSubjectRepository.Create(taskSubject);
|
||||||
|
_taskSubjectRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(taskSubject.id);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return operation.Failed("عملیات با خطا مواجه شد ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Edit(TaskSubjectViewModel command)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (command.Subject.Length > 100)
|
||||||
|
{
|
||||||
|
return operation.Failed("عنوان نمیتواند بیشتر از 100 کاراکتر باشد");
|
||||||
|
}
|
||||||
|
|
||||||
|
var taskSubject = _taskSubjectRepository.Get(command.Id);
|
||||||
|
taskSubject.Edit(command.Subject);
|
||||||
|
_taskSubjectRepository.SaveChanges();
|
||||||
|
return operation.Succcedded(taskSubject.id);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return operation.Failed("عملیات با خطا مواجه شد ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult Delete(long id)
|
||||||
|
{
|
||||||
|
var operation = new OperationResult();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_taskSubjectRepository.Remove(id);
|
||||||
|
return operation.Succcedded();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return operation.Failed("عملیات با خطا مواجه شد ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskSubjectViewModel> GetAll()
|
||||||
|
{
|
||||||
|
return _taskSubjectRepository.GetAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AccountManagement.Application.Contracts\AccountManagement.Application.Contracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AccountManagement.Application\AccountManagement.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\AccountMangement.Infrastructure.EFCore\AccountMangement.Infrastructure.EFCore.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using AccountManagement.Application;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
using AccountManagement.Application.Contracts.Role;
|
||||||
|
using AccountManagement.Application.Contracts.Task;
|
||||||
|
using AccountManagement.Application.Contracts.TaskSubject;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
using AccountManagement.Domain.AssignAgg;
|
||||||
|
using AccountManagement.Domain.CameraAccountAgg;
|
||||||
|
using AccountManagement.Domain.MediaAgg;
|
||||||
|
using AccountManagement.Domain.RoleAgg;
|
||||||
|
using AccountManagement.Domain.TaskAgg;
|
||||||
|
using AccountManagement.Domain.TaskSubjectAgg;
|
||||||
|
using AccountMangement.Infrastructure.EFCore;
|
||||||
|
using AccountMangement.Infrastructure.EFCore.Repository;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using TaskManager.Application.Contract.Position;
|
||||||
|
using TaskManager.Application;
|
||||||
|
using TaskManager.Domain.PositionAgg;
|
||||||
|
using TaskManager.Infrastructure.EFCore.Repository;
|
||||||
|
|
||||||
|
namespace AccountManagement.Configuration
|
||||||
|
{
|
||||||
|
public class AccountManagementBootstrapper
|
||||||
|
{
|
||||||
|
public static void Configure(IServiceCollection services, string connectionString)
|
||||||
|
{
|
||||||
|
services.AddTransient<IAccountApplication, AccountApplication>();
|
||||||
|
services.AddTransient<IAccountRepository, AccountRepository>();
|
||||||
|
|
||||||
|
services.AddTransient<IRoleApplication, RoleApplication>();
|
||||||
|
services.AddTransient<IRoleRepository, RoleRepository>();
|
||||||
|
|
||||||
|
services.AddTransient<ICameraAccountApplication, CameraAccountApplication>();
|
||||||
|
services.AddTransient<ICameraAccountRepository, CameraAccountRepository>();
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
services.AddTransient<IPositionRepository, PositionRepository>();
|
||||||
|
services.AddTransient<IPositionApplication, PositionApplication>();
|
||||||
|
|
||||||
|
services.AddTransient<ITaskApplication, TaskApplication>();
|
||||||
|
services.AddTransient<ITaskRepository, TaskRepository>();
|
||||||
|
|
||||||
|
services.AddTransient<ITaskSubjectRepository, TaskSubjectRepository>();
|
||||||
|
services.AddTransient<ITaskSubjectApplication, TaskSubjectApplication>();
|
||||||
|
|
||||||
|
services.AddTransient<IAssignRepository, AssignRepository>();
|
||||||
|
|
||||||
|
services.AddTransient<IMediaRepository, MediaRepository>();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
services.AddScoped<IWorker, Worker>();
|
||||||
|
services.AddDbContext<AccountContext>(x => x.UseSqlServer(connectionString));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
138
AccountManagement.Domain/AccountAgg/Account.cs
Normal file
138
AccountManagement.Domain/AccountAgg/Account.cs
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.CameraAccountAgg;
|
||||||
|
using AccountManagement.Domain.RoleAgg;
|
||||||
|
using TaskManager.Domain.PositionAgg;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.AccountAgg
|
||||||
|
{
|
||||||
|
public class Account : EntityBase
|
||||||
|
{
|
||||||
|
public string Fullname { get; private set; }
|
||||||
|
public string Username { get; private set; }
|
||||||
|
public string Password { get; private set; }
|
||||||
|
public string Mobile { get; private set; }
|
||||||
|
public long RoleId { get; private set; }
|
||||||
|
public string RoleName { get; private set; }
|
||||||
|
public Role Role { get; private set; }
|
||||||
|
public string ProfilePhoto { get; private set; }
|
||||||
|
public string AdminAreaPermission { get; private set; }
|
||||||
|
public string ClientAriaPermission { get; private set; }
|
||||||
|
public string NationalCode { get; private set; }
|
||||||
|
public string Email { get; private set; }
|
||||||
|
public string VerifyCode { get; set; }
|
||||||
|
public string IsActiveString { get; private set; }
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
public long? PositionId { get; private set; }
|
||||||
|
public Position Position { get; private set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public List<CameraAccount> CameraAccounts { get; private set; }
|
||||||
|
public Account(string fullname, string username, string password, string mobile,
|
||||||
|
long roleId, string profilePhoto, string roleName, string adminAreaPermission, string clientAriaPermission)
|
||||||
|
{
|
||||||
|
Fullname = fullname;
|
||||||
|
Username = username;
|
||||||
|
Password = password;
|
||||||
|
Mobile = mobile;
|
||||||
|
RoleId = roleId;
|
||||||
|
|
||||||
|
if (roleId == 0)
|
||||||
|
RoleId = 2;
|
||||||
|
|
||||||
|
ProfilePhoto = profilePhoto;
|
||||||
|
RoleName = roleName;
|
||||||
|
AdminAreaPermission = adminAreaPermission;
|
||||||
|
ClientAriaPermission = clientAriaPermission;
|
||||||
|
IsActiveString = "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Account(string fullname, string username, string password, string mobile, string nationalCode)
|
||||||
|
{
|
||||||
|
Fullname = fullname;
|
||||||
|
Username = username;
|
||||||
|
Password = password;
|
||||||
|
Mobile = mobile;
|
||||||
|
NationalCode = nationalCode;
|
||||||
|
RoleId = 15;
|
||||||
|
RoleName = "کارفرما";
|
||||||
|
AdminAreaPermission = "false";
|
||||||
|
ClientAriaPermission = "true";
|
||||||
|
ProfilePhoto = " ";
|
||||||
|
IsActiveString = "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Account()
|
||||||
|
{
|
||||||
|
ProfilePhoto = " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Edit(string fullname, string username, string mobile,
|
||||||
|
long roleId, string profilePhoto, string roleName)
|
||||||
|
{
|
||||||
|
Fullname = fullname;
|
||||||
|
Username = username;
|
||||||
|
Mobile = mobile;
|
||||||
|
RoleId = roleId;
|
||||||
|
RoleName = roleName;
|
||||||
|
if (!string.IsNullOrWhiteSpace(profilePhoto))
|
||||||
|
ProfilePhoto = profilePhoto;
|
||||||
|
}
|
||||||
|
public void EditClient(string fullname, string username, string mobile,
|
||||||
|
string profilePhoto, string email, string nationalCode)
|
||||||
|
{
|
||||||
|
Fullname = fullname;
|
||||||
|
Username = username;
|
||||||
|
Mobile = mobile;
|
||||||
|
Email = email;
|
||||||
|
NationalCode = nationalCode;
|
||||||
|
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(profilePhoto))
|
||||||
|
ProfilePhoto = profilePhoto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetVerifyCode(string verifyCode)
|
||||||
|
{
|
||||||
|
VerifyCode = verifyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveCode()
|
||||||
|
{
|
||||||
|
VerifyCode = "";
|
||||||
|
}
|
||||||
|
public void ChangePassword(string password)
|
||||||
|
{
|
||||||
|
Password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Active()
|
||||||
|
{
|
||||||
|
this.IsActiveString = "true";
|
||||||
|
}
|
||||||
|
public void DeActive()
|
||||||
|
{
|
||||||
|
this.IsActiveString = "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
public void SetPosition(long positionId)
|
||||||
|
{
|
||||||
|
PositionId = positionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeletePositionId()
|
||||||
|
{
|
||||||
|
PositionId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
32
AccountManagement.Domain/AccountAgg/IAccountRepository.cs
Normal file
32
AccountManagement.Domain/AccountAgg/IAccountRepository.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.AccountAgg
|
||||||
|
{
|
||||||
|
public interface IAccountRepository : IRepository<long, Account>
|
||||||
|
{
|
||||||
|
Account GetBy(string username);
|
||||||
|
Account GetById(long id);
|
||||||
|
EditAccount GetDetails(long id);
|
||||||
|
EditAccount GetByVerifyCode(string code, string phone);
|
||||||
|
EditAccount GetByUserNameAndId(long id, string username);
|
||||||
|
List<AccountViewModel> GetAccounts();
|
||||||
|
List<AccountViewModel> GetClientsAccount();
|
||||||
|
List<AccountViewModel> Search(AccountSearchModel searchModel);
|
||||||
|
Task RemoveCode(long id);
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
Account GetIncludePositions(long id);
|
||||||
|
List<AccountViewModel> GetAccountsByPositionId(long positionId);
|
||||||
|
List<AccountViewModel> AccountsForAssign(long taskId);
|
||||||
|
List<Account> GetAccountsByIds(List<long> ids);
|
||||||
|
List<AccountViewModel> GetAccountLowerPositionvalue();
|
||||||
|
AccountViewModel GetAccountViewModel(long id);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
AccountManagement.Domain/AccountAgg/IWorker.cs
Normal file
17
AccountManagement.Domain/AccountAgg/IWorker.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.AccountAgg
|
||||||
|
{
|
||||||
|
public interface IWorker : IRepository<long, Account>
|
||||||
|
{
|
||||||
|
Task RemoveVerfy(long id);
|
||||||
|
Task CreateVerifyCode(long id, string code);
|
||||||
|
Task RemoveVerifyCode(long id);
|
||||||
|
Task CreateCode(long id, string code);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
AccountManagement.Domain/AccountManagement.Domain.csproj
Normal file
12
AccountManagement.Domain/AccountManagement.Domain.csproj
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\0_Framework\0_Framework.csproj" />
|
||||||
|
<ProjectReference Include="..\AccountManagement.Application.Contracts\AccountManagement.Application.Contracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
33
AccountManagement.Domain/AssignAgg/Assign.cs
Normal file
33
AccountManagement.Domain/AssignAgg/Assign.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.TaskAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.AssignAgg;
|
||||||
|
|
||||||
|
public class Assign : EntityBase
|
||||||
|
{
|
||||||
|
public Assign(long taskId, long assignerId, long assignedId, int assignerPositionValue, string assignedName, int assignedPositionValue)
|
||||||
|
{
|
||||||
|
TaskId = taskId;
|
||||||
|
AssignerId = assignerId;
|
||||||
|
AssignedId = assignedId;
|
||||||
|
AssignerPositionValue = assignerPositionValue;
|
||||||
|
AssignedName = assignedName;
|
||||||
|
AssignedPositionValue = assignedPositionValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long TaskId { get; private set; }
|
||||||
|
//آیدی شخص ارسال کننده
|
||||||
|
public long AssignerId { get; private set; }
|
||||||
|
//نام دریافت کننده
|
||||||
|
public string AssignedName { get; private set; }
|
||||||
|
//آیدی شخص دریافت کننده
|
||||||
|
public long AssignedId { get; private set; }
|
||||||
|
//سطح شخص ارسال کننده
|
||||||
|
public int AssignerPositionValue { get; private set; }
|
||||||
|
public int AssignedPositionValue { get; private set; }
|
||||||
|
|
||||||
|
public Tasks Task { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
12
AccountManagement.Domain/AssignAgg/IAssignRepository.cs
Normal file
12
AccountManagement.Domain/AssignAgg/IAssignRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.Assign;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.AssignAgg;
|
||||||
|
|
||||||
|
public interface IAssignRepository:IRepository<long,Assign>
|
||||||
|
{
|
||||||
|
|
||||||
|
List<AssignViewModel> GetAssignsByTaskId(long id);
|
||||||
|
|
||||||
|
}
|
||||||
46
AccountManagement.Domain/CameraAccountAgg/CameraAccount.cs
Normal file
46
AccountManagement.Domain/CameraAccountAgg/CameraAccount.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.CameraAccountAgg;
|
||||||
|
|
||||||
|
public class CameraAccount : EntityBase
|
||||||
|
{
|
||||||
|
public CameraAccount(string username, string password, string mobile, string workshopName, long workshopId, long accountId)
|
||||||
|
{
|
||||||
|
Username = username;
|
||||||
|
Password = password;
|
||||||
|
Mobile = mobile;
|
||||||
|
WorkshopName = workshopName;
|
||||||
|
WorkshopId = workshopId;
|
||||||
|
AccountId = accountId;
|
||||||
|
IsActiveSting = "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Username { get; private set; }
|
||||||
|
public string Password { get; private set; }
|
||||||
|
public string Mobile { get; private set; }
|
||||||
|
public long WorkshopId { get; private set; }
|
||||||
|
public string WorkshopName { get; private set; }
|
||||||
|
public long AccountId { get; private set; }
|
||||||
|
public string IsActiveSting { get; private set; }
|
||||||
|
public Account Account { get; private set; }
|
||||||
|
public void Active()
|
||||||
|
{
|
||||||
|
this.IsActiveSting = "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeActive()
|
||||||
|
{
|
||||||
|
this.IsActiveSting = "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangePassword(string password)
|
||||||
|
{
|
||||||
|
Password = password;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using _0_Framework.Application;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.CameraAccount;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.CameraAccountAgg
|
||||||
|
{
|
||||||
|
public interface ICameraAccountRepository : IRepository<long,CameraAccount>
|
||||||
|
|
||||||
|
{
|
||||||
|
CameraAccount GetBy(string username);
|
||||||
|
CameraAccount GetById(long id);
|
||||||
|
EditCameraAccount GetDetails(long id);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
AccountManagement.Domain/MediaAgg/IMediaRepository.cs
Normal file
13
AccountManagement.Domain/MediaAgg/IMediaRepository.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.Media;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.MediaAgg;
|
||||||
|
|
||||||
|
public interface IMediaRepository:IRepository<long,Media>
|
||||||
|
{
|
||||||
|
void CreateMediaWithTaskMedia(long taskId, long mediaId);
|
||||||
|
List<MediaViewModel> GetMediaByTaskId(long taskId);
|
||||||
|
void Remove(long id);
|
||||||
|
}
|
||||||
27
AccountManagement.Domain/MediaAgg/Media.cs
Normal file
27
AccountManagement.Domain/MediaAgg/Media.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.TaskMediaAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.MediaAgg;
|
||||||
|
|
||||||
|
public class Media:EntityBase
|
||||||
|
{
|
||||||
|
public Media( string path, string type, string category)
|
||||||
|
{
|
||||||
|
|
||||||
|
Path = path;
|
||||||
|
Type = type;
|
||||||
|
Category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//مسیر ذخیره فایل
|
||||||
|
public string Path { get; private set; }
|
||||||
|
|
||||||
|
//نوع ذخیره فایل
|
||||||
|
public string Type { get; private set; }
|
||||||
|
|
||||||
|
//دسته بندی ذخیره فایل
|
||||||
|
public string Category { get; set; }
|
||||||
|
public List<TaskMedia> TaskMedias { get; set; }
|
||||||
|
}
|
||||||
22
AccountManagement.Domain/PositionAgg/IPositionRepository.cs
Normal file
22
AccountManagement.Domain/PositionAgg/IPositionRepository.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.Account;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
using TaskManager.Application.Contract.Position;
|
||||||
|
|
||||||
|
namespace TaskManager.Domain.PositionAgg;
|
||||||
|
|
||||||
|
public interface IPositionRepository : IRepository<long, Position>
|
||||||
|
{
|
||||||
|
|
||||||
|
List<PositionViewModel> GetPositions();
|
||||||
|
List<PositionViewModel> GetLowerPosition();
|
||||||
|
|
||||||
|
List<AccountViewModel> GetNoPositionAccounts();
|
||||||
|
List<Account> GetAccountsByIds(List<long> ids);
|
||||||
|
|
||||||
|
void Remove(long id);
|
||||||
|
|
||||||
|
int GetLastPositionValue();
|
||||||
|
|
||||||
|
}
|
||||||
25
AccountManagement.Domain/PositionAgg/Position.cs
Normal file
25
AccountManagement.Domain/PositionAgg/Position.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
|
||||||
|
namespace TaskManager.Domain.PositionAgg;
|
||||||
|
|
||||||
|
public class Position:EntityBase
|
||||||
|
{
|
||||||
|
// نام سمت
|
||||||
|
public string PositionName { get; private set; }
|
||||||
|
// سطح سمت
|
||||||
|
public int PositionValue { get; private set; }
|
||||||
|
public List<Account> Accounts { get; set; }
|
||||||
|
|
||||||
|
public Position(string positionName, int positionValue)
|
||||||
|
{
|
||||||
|
PositionName = positionName;
|
||||||
|
PositionValue = positionValue;
|
||||||
|
}
|
||||||
|
public void Edit(string positionName, int positionValue)
|
||||||
|
{
|
||||||
|
PositionName = positionName;
|
||||||
|
PositionValue = positionValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
AccountManagement.Domain/RoleAgg/IRoleRepository.cs
Normal file
12
AccountManagement.Domain/RoleAgg/IRoleRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.Role;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.RoleAgg
|
||||||
|
{
|
||||||
|
public interface IRoleRepository : IRepository<long, Role>
|
||||||
|
{
|
||||||
|
List<RoleViewModel> List();
|
||||||
|
EditRole GetDetails(long id);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
AccountManagement.Domain/RoleAgg/Permission.cs
Normal file
22
AccountManagement.Domain/RoleAgg/Permission.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace AccountManagement.Domain.RoleAgg
|
||||||
|
{
|
||||||
|
public class Permission
|
||||||
|
{
|
||||||
|
public long Id { get; private set; }
|
||||||
|
public int Code { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public long RoleId { get; private set; }
|
||||||
|
public Role Role { get; private set; }
|
||||||
|
|
||||||
|
public Permission(int code)
|
||||||
|
{
|
||||||
|
Code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Permission(int code, string name)
|
||||||
|
{
|
||||||
|
Code = code;
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
AccountManagement.Domain/RoleAgg/Role.cs
Normal file
30
AccountManagement.Domain/RoleAgg/Role.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.RoleAgg
|
||||||
|
{
|
||||||
|
public class Role : EntityBase
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public List<Permission> Permissions { get; private set; }
|
||||||
|
public List<Account> Accounts { get; private set; }
|
||||||
|
|
||||||
|
protected Role()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Role(string name, List<Permission> permissions)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Permissions = permissions;
|
||||||
|
Accounts = new List<Account>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Edit(string name, List<Permission> permissions)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Permissions = permissions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
AccountManagement.Domain/TaskAgg/ITaskRepository.cs
Normal file
20
AccountManagement.Domain/TaskAgg/ITaskRepository.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.Task;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.TaskAgg;
|
||||||
|
|
||||||
|
public interface ITaskRepository:IRepository<long,Tasks>
|
||||||
|
{
|
||||||
|
EditTask GetDetails(long TaskId);
|
||||||
|
|
||||||
|
void Remove(long id);
|
||||||
|
//گرفتن تمامی وظایف
|
||||||
|
List<TaskViewModel> GetTasks(TaskSearchModel searchModel);
|
||||||
|
List<TaskViewModel> GetAllRequestedTasks(TaskSearchModel searchModel);
|
||||||
|
string SetTasksColors(DateTime time);
|
||||||
|
int GetRequestedTasksCount();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
127
AccountManagement.Domain/TaskAgg/Tasks.cs
Normal file
127
AccountManagement.Domain/TaskAgg/Tasks.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.AccessControl;
|
||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Domain.AssignAgg;
|
||||||
|
using AccountManagement.Domain.TaskMediaAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.TaskAgg;
|
||||||
|
|
||||||
|
public class Tasks : EntityBase
|
||||||
|
{
|
||||||
|
public Tasks(string title, DateTime endTaskDate, string? description, long senderId, string contractingPartyName)
|
||||||
|
{
|
||||||
|
Title = title;
|
||||||
|
EndTaskDate = endTaskDate;
|
||||||
|
Description = description;
|
||||||
|
SenderId = senderId;
|
||||||
|
ContractingPartyName = contractingPartyName;
|
||||||
|
StartTaskDate = DateTime.Now;
|
||||||
|
IsActiveString = "true";
|
||||||
|
}
|
||||||
|
//عنوان وظیفه
|
||||||
|
public string Title { get; private set; }
|
||||||
|
//زمان پایان وظیفه
|
||||||
|
public DateTime EndTaskDate { get; private set; }
|
||||||
|
//زمان ارسال وظیفه
|
||||||
|
public DateTime StartTaskDate { get; private set; }
|
||||||
|
//توضیحات وظیفه
|
||||||
|
public string? Description { get; private set; }
|
||||||
|
//آیدی شخص ارسال کننده
|
||||||
|
public long SenderId { get; private set; }
|
||||||
|
//آیا درخواست مهلت کرده است؟
|
||||||
|
public bool TimeRequest { get; private set; }
|
||||||
|
//تعداد تایید درخواست مهلت
|
||||||
|
public int AcceptedTimeRequest { get; set; }
|
||||||
|
//مهلت زمان درخواست شده
|
||||||
|
public DateTime? RequestDate { get; private set; }
|
||||||
|
//توضیحات درخواست مهلت
|
||||||
|
public string? TimeRequestDescription { get; private set; }
|
||||||
|
//آیا درخواست انصراف داده شده
|
||||||
|
public bool IsCanceledRequest { get; private set; }
|
||||||
|
//نام طرف حساب
|
||||||
|
public string ContractingPartyName { get; set; }
|
||||||
|
|
||||||
|
//آیا کنسل شده است
|
||||||
|
public bool IsCancel { get; private set; }
|
||||||
|
//توضیحات درخواست انصراف
|
||||||
|
public string? CancelDescription { get; private set; }
|
||||||
|
public bool IsDone { get; private set; }
|
||||||
|
public string? DoneDescription { get; private set; }
|
||||||
|
public string IsActiveString { get; private set; }
|
||||||
|
public List<Assign> Assigns { get; set; }
|
||||||
|
public List<TaskMedia> TaskMedias { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public void Edit(string title, DateTime endTaskDate, string? description, long senderId)
|
||||||
|
{
|
||||||
|
Title = title;
|
||||||
|
EndTaskDate = endTaskDate;
|
||||||
|
Description = description;
|
||||||
|
SenderId = senderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//برای ایجاد یک درخواست مهلت
|
||||||
|
public void CreateTimeRequest(DateTime requestDate, string timeRequestDescription)
|
||||||
|
{
|
||||||
|
RequestDate = requestDate;
|
||||||
|
TimeRequestDescription = timeRequestDescription;
|
||||||
|
TimeRequest = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AcceptTimeRequest()
|
||||||
|
{
|
||||||
|
TimeRequest = false;
|
||||||
|
AcceptedTimeRequest++;
|
||||||
|
EndTaskDate = (DateTime)RequestDate;
|
||||||
|
|
||||||
|
}
|
||||||
|
public void RejectTimeRequest()
|
||||||
|
{
|
||||||
|
TimeRequest = false;
|
||||||
|
TimeRequestDescription = null;
|
||||||
|
RequestDate = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateCancelRequest(string cancelDescription)
|
||||||
|
{
|
||||||
|
CancelDescription = cancelDescription;
|
||||||
|
IsCanceledRequest=true;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public void AcceptCancelRequest()
|
||||||
|
{
|
||||||
|
IsCanceledRequest=false;
|
||||||
|
IsCancel = true;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public void RejectCancel()
|
||||||
|
{
|
||||||
|
CancelDescription = null;
|
||||||
|
IsCanceledRequest = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Completed(string? doneDescription)
|
||||||
|
{
|
||||||
|
DoneDescription = doneDescription;
|
||||||
|
IsDone=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeActive()
|
||||||
|
{
|
||||||
|
IsActiveString = "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Activator()
|
||||||
|
{
|
||||||
|
IsActiveString = "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
20
AccountManagement.Domain/TaskMediaAgg/TaskMedia.cs
Normal file
20
AccountManagement.Domain/TaskMediaAgg/TaskMedia.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using AccountManagement.Domain.MediaAgg;
|
||||||
|
using AccountManagement.Domain.TaskAgg;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.TaskMediaAgg;
|
||||||
|
|
||||||
|
public class TaskMedia
|
||||||
|
{
|
||||||
|
public TaskMedia(long taskId, long mediaId)
|
||||||
|
{
|
||||||
|
TaskId = taskId;
|
||||||
|
MediaId = mediaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long TaskId { get; private set; }
|
||||||
|
public long MediaId { get; private set; }
|
||||||
|
public Tasks Tasks { get; private set; }
|
||||||
|
public Media Media { get; private set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
using AccountManagement.Application.Contracts.TaskSubject;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.TaskSubjectAgg;
|
||||||
|
|
||||||
|
public interface ITaskSubjectRepository:IRepository<long, TaskSubject>
|
||||||
|
{
|
||||||
|
List<TaskSubjectViewModel> GetAll();
|
||||||
|
void Remove(long id);
|
||||||
|
}
|
||||||
18
AccountManagement.Domain/TaskSubjectAgg/TaskSubject.cs
Normal file
18
AccountManagement.Domain/TaskSubjectAgg/TaskSubject.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using _0_Framework.Domain;
|
||||||
|
|
||||||
|
namespace AccountManagement.Domain.TaskSubjectAgg;
|
||||||
|
|
||||||
|
public class TaskSubject:EntityBase
|
||||||
|
{
|
||||||
|
public TaskSubject(string subject)
|
||||||
|
{
|
||||||
|
Subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Subject { get; private set; }
|
||||||
|
|
||||||
|
public void Edit(string subject)
|
||||||
|
{
|
||||||
|
Subject = subject;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
AccountMangement.Infrastructure.EFCore/AccountContext.cs
Normal file
45
AccountMangement.Infrastructure.EFCore/AccountContext.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using AccountManagement.Domain.AccountAgg;
|
||||||
|
using AccountMangement.Infrastructure.EFCore.Mappings;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using AccountManagement.Domain.CameraAccountAgg;
|
||||||
|
using AccountManagement.Domain.RoleAgg;
|
||||||
|
using AccountManagement.Domain.AssignAgg;
|
||||||
|
using AccountManagement.Domain.MediaAgg;
|
||||||
|
using AccountManagement.Domain.TaskAgg;
|
||||||
|
using AccountManagement.Domain.TaskMediaAgg;
|
||||||
|
using AccountManagement.Domain.TaskSubjectAgg;
|
||||||
|
using TaskManager.Domain.PositionAgg;
|
||||||
|
|
||||||
|
namespace AccountMangement.Infrastructure.EFCore
|
||||||
|
{
|
||||||
|
public class AccountContext : DbContext
|
||||||
|
{
|
||||||
|
|
||||||
|
public DbSet<Account> Accounts { get; set; }
|
||||||
|
public DbSet<Role> Roles { get; set; }
|
||||||
|
public DbSet<CameraAccount> CameraAccounts { get; set; }
|
||||||
|
|
||||||
|
#region Mahan
|
||||||
|
|
||||||
|
public DbSet<Position> Positions { get; set; }
|
||||||
|
public DbSet<Assign> Assigns { get; set; }
|
||||||
|
public DbSet<Tasks> Tasks { get; set; }
|
||||||
|
public DbSet<Media> Medias { get; set; }
|
||||||
|
public DbSet<TaskMedia> TaskMedias { get; set; }
|
||||||
|
public DbSet<TaskSubject> TaskSubjects { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
public AccountContext(DbContextOptions<AccountContext> options) : base(options)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
var assembly = typeof(AccountMapping).Assembly;
|
||||||
|
modelBuilder.ApplyConfigurationsFromAssembly(assembly);
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AccountManagement.Domain\AccountManagement.Domain.csproj" />
|
||||||
|
<ProjectReference Include="..\Company.Domain\Company.Domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user