70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
using System.Text.RegularExpressions;
|
|
using _0_Framework.Application;
|
|
using Company.Domain.ContactUsAgg;
|
|
using CompanyManagment.App.Contracts.ContactUs;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class ContactUsApplication : IContactUsApplication
|
|
{
|
|
private readonly IContactUsRepository _contactUsRepository;
|
|
|
|
public ContactUsApplication(IContactUsRepository contactUsRepository)
|
|
{
|
|
_contactUsRepository = contactUsRepository;
|
|
}
|
|
|
|
public OperationResult Create(CreateContactUs command)
|
|
{
|
|
var op = new OperationResult();
|
|
if (string.IsNullOrWhiteSpace(command.FirstName))
|
|
{
|
|
return op.Failed("لطفا نام خود را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.LastName))
|
|
{
|
|
return op.Failed("لطفا نام خانوادگی خود را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Email))
|
|
{
|
|
return op.Failed("لطفا ایمیل خود را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.PhoneNumber))
|
|
{
|
|
return op.Failed("لطفا شماره تماس خود را وارد کنید");
|
|
}
|
|
|
|
if (!Regex.IsMatch(command.PhoneNumber, @"^(\+98|0)?9\d{9}$"))
|
|
{
|
|
return op.Failed("شماره تماس وارد شده نامعتبر است");
|
|
}
|
|
|
|
if (!Regex.IsMatch(command.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
|
|
{
|
|
return op.Failed("ایمیل وارد شده نامعتبر است");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Title))
|
|
{
|
|
return op.Failed("لطفا عنوان پیغام خود را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Message))
|
|
{
|
|
return op.Failed("لطفا پیغام خود را وارد کنید");
|
|
}
|
|
|
|
var entity = new ContactUs(command.FirstName, command.LastName, command.Email, command.PhoneNumber,
|
|
command.Title, command.Message);
|
|
|
|
_contactUsRepository.Create(entity);
|
|
|
|
_contactUsRepository.SaveChanges();
|
|
|
|
return op.Succcedded();
|
|
|
|
}
|
|
} |