...
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Back.Services;
|
||||
using Back.Validations;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs;
|
||||
@@ -13,9 +14,11 @@ namespace Back.Controllers
|
||||
private readonly CheckPermission _checkPermission;
|
||||
private readonly servUser _servUser;
|
||||
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;
|
||||
_servUser = servUser;
|
||||
_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
|
||||
})) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user