...
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Back.Services;
|
using Back.Services;
|
||||||
|
using Back.Validations;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Shared.DTOs;
|
using Shared.DTOs;
|
||||||
@@ -13,9 +14,11 @@ namespace Back.Controllers
|
|||||||
private readonly CheckPermission _checkPermission;
|
private readonly CheckPermission _checkPermission;
|
||||||
private readonly servUser _servUser;
|
private readonly servUser _servUser;
|
||||||
private readonly servCustomer _servCus;
|
private readonly servCustomer _servCus;
|
||||||
public CustomerController(CheckPermission checkPermission, servUser servUser, servCustomer servCus)
|
private readonly AddCustomerValidation _addCustomerValidation;
|
||||||
|
public CustomerController(CheckPermission checkPermission, servUser servUser
|
||||||
|
, servCustomer servCus, AddCustomerValidation addCustomerValidation)
|
||||||
{
|
{
|
||||||
|
_addCustomerValidation = addCustomerValidation;
|
||||||
_checkPermission = checkPermission;
|
_checkPermission = checkPermission;
|
||||||
_servUser = servUser;
|
_servUser = servUser;
|
||||||
_servCus = servCus;
|
_servCus = servCus;
|
||||||
@@ -33,5 +36,33 @@ namespace Back.Controllers
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
[HttpPost("Add")]
|
||||||
|
public async Task<ActionResult<bool>> Add(RCustomer item)
|
||||||
|
{
|
||||||
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||||
|
var UserID = claim.Value;
|
||||||
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||||
|
|
||||||
|
var resultValidationmodel = await _addCustomerValidation.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID,item));
|
||||||
|
if (!resultValidationmodel.IsValid)
|
||||||
|
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||||
|
|
||||||
|
return Ok(_servCus.AddCustomer(new Data.Models.Customer
|
||||||
|
{
|
||||||
|
Address = item.Address,
|
||||||
|
BranchID = item.BranchID,
|
||||||
|
CompanyID = user.RolUsers.First().CompanyID,
|
||||||
|
CustomerType = item.CustomerType,
|
||||||
|
EconomicCode = item.EconomicCode,
|
||||||
|
Email = item.Email,
|
||||||
|
FullName = item.FullName,
|
||||||
|
Info = item.Info,
|
||||||
|
MeliCode = item.MeliCode,
|
||||||
|
PassportNumber = item.PassportNumber,
|
||||||
|
Phone = item.Phone,
|
||||||
|
ZipCode = item.ZipCode,
|
||||||
|
IsDeleted = false
|
||||||
|
})) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ builder.Services.AddScoped<servUser>();
|
|||||||
builder.Services.AddScoped<servTaxPayer>();
|
builder.Services.AddScoped<servTaxPayer>();
|
||||||
builder.Services.AddScoped<servCustomer>();
|
builder.Services.AddScoped<servCustomer>();
|
||||||
builder.Services.AddScoped<CompanyRegistrationValidation>();
|
builder.Services.AddScoped<CompanyRegistrationValidation>();
|
||||||
|
builder.Services.AddScoped<AddCustomerValidation>();
|
||||||
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
||||||
|
|
||||||
string origins = "OriginTaxPayer";
|
string origins = "OriginTaxPayer";
|
||||||
|
|||||||
@@ -98,48 +98,48 @@ namespace Back.Services
|
|||||||
// })
|
// })
|
||||||
// .FirstOrDefaultAsync();
|
// .FirstOrDefaultAsync();
|
||||||
//}
|
//}
|
||||||
//public async Task<Customer?> AddORUpdateCustomer(Customer item)
|
public async Task<bool> AddCustomer(Customer item)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//SysLog log = new SysLog()
|
||||||
//{
|
//{
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// SysLog log = new SysLog()
|
|
||||||
// {
|
|
||||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer",
|
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer",
|
||||||
// Value ="*"+ JsonConvert.SerializeObject(item),
|
// Value = "*" + JsonConvert.SerializeObject(item),
|
||||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||||
// Type = "User"
|
// Type = "User"
|
||||||
// };
|
//};
|
||||||
// _contextMongodb.InsertItem(log);
|
//_contextMongodb.InsertItem(log);
|
||||||
|
|
||||||
// if (item.ID == null || item.ID == 0)
|
if (item.ID == null || item.ID == 0)
|
||||||
// {
|
{
|
||||||
// var ret = await _repositores.ADD(item);
|
var ret = await _repoCus.AddBoolResultAsync(item);
|
||||||
// _checkPermission.ExtensionofAccess(item.CompanyID, 5, "-1");
|
await _checkPermission.ExtensionofAccess(item.CompanyID, 5, "-1");
|
||||||
// return item;
|
return ret;
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// return await _repositores.UPDATE(item);
|
return await _repoCus.UpdateAsync(item);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// catch (Exception ex)
|
catch (Exception ex)
|
||||||
// {
|
{
|
||||||
// SysLog log = new SysLog()
|
//SysLog log = new SysLog()
|
||||||
// {
|
//{
|
||||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer",
|
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer",
|
||||||
// Value = ex.Message,
|
// Value = ex.Message,
|
||||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||||
// Type = "catch"
|
// Type = "catch"
|
||||||
// };
|
//};
|
||||||
// _contextMongodb.InsertItem(log);
|
//_contextMongodb.InsertItem(log);
|
||||||
// return null;
|
return false;
|
||||||
// }
|
}
|
||||||
|
|
||||||
//}
|
}
|
||||||
//public async Task<bool> DeleteCustomer(Customer item)
|
//public async Task<bool> DeleteCustomer(Customer item)
|
||||||
//{
|
//{
|
||||||
|
|
||||||
|
|||||||
61
Back/Validations/AddCustomerValidation.cs
Normal file
61
Back/Validations/AddCustomerValidation.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using Back.Services;
|
||||||
|
using FluentValidation;
|
||||||
|
using Shared.DTOs;
|
||||||
|
|
||||||
|
namespace Back.Validations
|
||||||
|
{
|
||||||
|
public class AddCustomerValidation : AbstractValidator<Tuple<int, RCustomer>>
|
||||||
|
{
|
||||||
|
public AddCustomerValidation(CheckPermission _checkPermission)
|
||||||
|
{
|
||||||
|
CascadeMode = CascadeMode.Stop;
|
||||||
|
RuleFor(r => r.Item1)
|
||||||
|
.Custom((CompanyID, context) => {
|
||||||
|
if (! _checkPermission.AllowAddCustomerInCompany(CompanyID).Result)
|
||||||
|
context.AddFailure("اضافه کردن مشتری محدود شده است");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
RuleFor(r => r.Item2.FullName)
|
||||||
|
.NotNull().WithMessage("نام نمی تواند خالی باشذ")
|
||||||
|
.NotEmpty().WithMessage("نام نمی تواند خالی باشذ")
|
||||||
|
.MinimumLength(5).WithMessage("حداقل کارکتر مجار نام 5 می باشد");
|
||||||
|
|
||||||
|
RuleFor(r => r.Item2.Phone)
|
||||||
|
.NotNull().WithMessage("تلفن نمی تواند خالی باشذ")
|
||||||
|
.NotEmpty().WithMessage("تلفن نمی تواند خالی باشذ")
|
||||||
|
.MinimumLength(8).WithMessage("حداقل کارکتر مجار تلفن 8 می باشد");
|
||||||
|
|
||||||
|
RuleFor(r => r.Item2.Email)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (!string.IsNullOrEmpty(model) && (!model.Contains("@") || !model.Contains(".")))
|
||||||
|
context.AddFailure("فرمت پست الکترونیک صحبح نمی باشد");
|
||||||
|
});
|
||||||
|
RuleFor(r => r.Item2.EconomicCode)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (!string.IsNullOrEmpty(model) && (model.Length<11 || model.Length > 14))
|
||||||
|
context.AddFailure("تعداد شماره اقتصادی صحبح نمی باشد");
|
||||||
|
});
|
||||||
|
RuleFor(r => r.Item2.BranchID)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (!string.IsNullOrEmpty(model) && (model.Length > 10 ))
|
||||||
|
context.AddFailure("تعداد کد شعبه صحبح نمی باشد");
|
||||||
|
});
|
||||||
|
RuleFor(r => r.Item2.ZipCode)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (!string.IsNullOrEmpty(model) && (model.Length !=10))
|
||||||
|
context.AddFailure("تعداد کد پستی صحبح نمی باشد");
|
||||||
|
});
|
||||||
|
RuleFor(r => r.Item2.MeliCode)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (!string.IsNullOrEmpty(model) && (model.Length < 10 || model.Length > 12))
|
||||||
|
context.AddFailure("تعداد شناسه ملی صحبح نمی باشد");
|
||||||
|
});
|
||||||
|
RuleFor(r => r.Item2.PassportNumber)
|
||||||
|
.Custom((model, context) => {
|
||||||
|
if (!string.IsNullOrEmpty(model) && (model.Length!=9))
|
||||||
|
context.AddFailure("تعداد شماره گذرنامه صحبح نمی باشد");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,11 +10,11 @@ namespace Shared.DTOs
|
|||||||
public class RCustomer
|
public class RCustomer
|
||||||
{
|
{
|
||||||
[Display(Name ="شناسه")]
|
[Display(Name ="شناسه")]
|
||||||
public int ID { get; set; }
|
public int? ID { get; set; }
|
||||||
[Display(Name = "نام کامل")]
|
[Display(Name = "نام کامل")]
|
||||||
public string FullName { get; set; }
|
public string FullName { get; set; }
|
||||||
[Display(Name = "نوع مشتری")]
|
[Display(Name = "نوع مشتری")]
|
||||||
public string CustomerTypeTitle { get; set; }
|
public string? CustomerTypeTitle { get; set; }
|
||||||
[Display(Name = "تلفن")]
|
[Display(Name = "تلفن")]
|
||||||
public string Phone { get; set; }
|
public string Phone { get; set; }
|
||||||
[Display(Name = "پست الکترونیک")]
|
[Display(Name = "پست الکترونیک")]
|
||||||
@@ -24,15 +24,15 @@ namespace Shared.DTOs
|
|||||||
[Display(Name = "کد اقتصادی")]
|
[Display(Name = "کد اقتصادی")]
|
||||||
public string? EconomicCode { get; set; }
|
public string? EconomicCode { get; set; }
|
||||||
[Display(Name = "کد شعبه")]
|
[Display(Name = "کد شعبه")]
|
||||||
public string? BranchID { get; set; }
|
public string? BranchID { get; set; }//
|
||||||
[Display(Name = "توضیحات")]
|
[Display(Name = "توضیحات")]
|
||||||
public string? Info { get; set; }
|
public string? Info { get; set; }//
|
||||||
|
|
||||||
//------------
|
//------------
|
||||||
public CustomerType CustomerType { get; set; }
|
public CustomerType CustomerType { get; set; }
|
||||||
public string? ZipCode { get; set; }
|
public string? ZipCode { get; set; }
|
||||||
public string? MeliCode { get; set; }
|
public string? MeliCode { get; set; }
|
||||||
public string? PassportNumber { get; set; }
|
public string? PassportNumber { get; set; }//
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,76 @@
|
|||||||
@using Shared.DTOs
|
@using Shared.DTOs
|
||||||
<p>سلام</p>
|
<form>
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label" style="color:red" for="inputFullName">نام کامل</label>
|
||||||
|
<InputText @bind-Value="Cus.FullName" type="text" class="form-control" id="inputFullName" placeholder="نام کامل"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label" style="color:red" for="inputcustomertype">نوع مشتری</label>
|
||||||
|
<select @bind="Cus.CustomerType" class="form-control" id="inputcustomertype">
|
||||||
|
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
|
||||||
|
<option value="1">حقیقی</option>
|
||||||
|
<option value="2">حقوقی</option>
|
||||||
|
<option value="3">مشارکت مدنی</option>
|
||||||
|
<option value="4">اتباع غیر ایرانی</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">تلفن</label>
|
||||||
|
<InputText @bind-Value="Cus.Phone" type="text" class="form-control" id="inputPhone" placeholder="تلفن"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">آدرس</label>
|
||||||
|
<InputText @bind-Value="Cus.Address" type="text" class="form-control" id="inputAddress" placeholder="آدرس"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">پست الکترونیک</label>
|
||||||
|
<InputText @bind-Value="Cus.Email" type="email" class="form-control" id="inputEmail" placeholder="پست الکترونیک"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">کد پستی</label>
|
||||||
|
<InputText @bind-Value="Cus.ZipCode" type="text" class="form-control" id="inputZipCode" placeholder="کد پستی"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">کد اقتصادی</label>
|
||||||
|
<InputText @bind-Value="Cus.EconomicCode" type="text" class="form-control" id="inputEconomicCode" placeholder="کد اقتصادی"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">کد ملی</label>
|
||||||
|
<InputText @bind-Value="Cus.MeliCode" type="text" class="form-control" id="inputMeliCode" placeholder="کدملی"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">کد شعبه</label>
|
||||||
|
<InputText @bind-Value="Cus.BranchID" type="text" class="form-control" id="inputBranchID" placeholder="کد شعبه"/>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label class="col-sm-4 col-form-label">شماره گذرنامه</label>
|
||||||
|
<InputText @bind-Value="Cus.PassportNumber" type="text" class="form-control" id="inputPassportNumber" placeholder="شماره گذرنامه"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<label class="col-sm-4 col-form-label">توضیحات</label>
|
||||||
|
<InputTextArea @bind-Value="Cus.Info" class="form-control" id="inputMeliInfo" placeholder="توضیحات" rows="3"></InputTextArea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
@if (Cus.ID==-1)
|
@if (Cus.ID==-1)
|
||||||
{
|
{
|
||||||
<Button class="mt-3" Color="ButtonColor.Success" @onclick="OnClickAdd" Type="ButtonType.Button">
|
<Button class="mt-3" Color="ButtonColor.Success" @onclick="OnClickAdd" Type="ButtonType.Button">
|
||||||
@@ -41,6 +112,7 @@ else
|
|||||||
}
|
}
|
||||||
public async Task OnClickAdd()
|
public async Task OnClickAdd()
|
||||||
{
|
{
|
||||||
|
var rssss = Cus;
|
||||||
result.Action = ComponentAction.add;
|
result.Action = ComponentAction.add;
|
||||||
await OnMultipleOfThree.InvokeAsync(result);
|
await OnMultipleOfThree.InvokeAsync(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user