97 lines
3.6 KiB
C#
97 lines
3.6 KiB
C#
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();
|
|
}
|
|
} |