...
This commit is contained in:
@@ -5,6 +5,7 @@ using Shared.DTOs.Serch;
|
||||
using Shared.DTOs;
|
||||
using System.Xml.Linq;
|
||||
using Back.Common;
|
||||
using Back.Validations;
|
||||
|
||||
namespace Back.Controllers
|
||||
{
|
||||
@@ -14,10 +15,12 @@ namespace Back.Controllers
|
||||
{
|
||||
private readonly ServCOD _servCOD;
|
||||
private readonly servUser _servUser;
|
||||
public CODController(ServCOD servCOD, servUser servUser)
|
||||
private readonly AddOrCodValidation _addorupdateCodValidation;
|
||||
public CODController(ServCOD servCOD, servUser servUser, AddOrCodValidation addorupdateCodValidation)
|
||||
{
|
||||
_servCOD = servCOD;
|
||||
_servUser = servUser;
|
||||
_servUser = servUser;
|
||||
_addorupdateCodValidation = addorupdateCodValidation;
|
||||
}
|
||||
[HttpPost("GetAll")]
|
||||
public async Task<ActionResult<PagingDto<RCOD>?>> GetAll([FromBody] ItemSerchGetCOD itemSerch)
|
||||
@@ -36,85 +39,69 @@ namespace Back.Controllers
|
||||
[HttpPost("Add")]
|
||||
public async Task<ActionResult<bool>> Add(RCOD item)
|
||||
{
|
||||
return Ok();
|
||||
//var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
//var UserID = claim.Value;
|
||||
//var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
|
||||
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 _addorupdateCustomerValidation.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, item, eActionValidation.add));
|
||||
//if (!resultValidationmodel.IsValid)
|
||||
// return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
var resultValidationmodel = await _addorupdateCodValidation.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, item, eActionValidation.add));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
//return Ok(await _servCus.AddOrUpdateCustomer(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
|
||||
//}));
|
||||
return Ok(await _servCOD.AddOrUpdateCod(new Data.Models.CODItem
|
||||
{
|
||||
|
||||
CompanyID = user.RolUsers.First().CompanyID,
|
||||
TaxRate = item.TaxRate,
|
||||
Title = item.Title,
|
||||
UnitID=item.UnitID,
|
||||
ItemTaxID=item.TaxID,
|
||||
IsDeleted = false
|
||||
}));
|
||||
}
|
||||
[HttpPut("Update")]
|
||||
public async Task<ActionResult<bool>> Update(RCOD item)
|
||||
{
|
||||
return Ok();
|
||||
////-----GetUserAndCompany
|
||||
//var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
//var UserID = claim.Value;
|
||||
//var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
//-----GetUserAndCompany
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
|
||||
////-----Validaton
|
||||
//var resultValidationmodel = await _addorupdateCustomerValidation.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, item, eActionValidation.update));
|
||||
//if (!resultValidationmodel.IsValid)
|
||||
// return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _addorupdateCodValidation.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, item, eActionValidation.update));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
////-----Get Cus
|
||||
//var cus = await _servCus.GetCustomerByCustomerID(item.ID.Value, user.RolUsers.First().CompanyID);
|
||||
//if (cus == null)
|
||||
// return BadRequest(new List<string> { "Cus notFound..." });
|
||||
//-----Get Cod
|
||||
var Cod = await _servCOD.GetCodByCodID(item.ID.Value, user.RolUsers.First().CompanyID);
|
||||
if (Cod == null)
|
||||
return BadRequest(new List<string> { "Cod notFound..." });
|
||||
|
||||
////-----change Cus
|
||||
//cus.Address = item.Address;
|
||||
//cus.BranchID = item.BranchID;
|
||||
//cus.CompanyID = user.RolUsers.First().CompanyID;
|
||||
//cus.CustomerType = item.CustomerType;
|
||||
//cus.EconomicCode = item.EconomicCode;
|
||||
//cus.Email = item.Email;
|
||||
//cus.FullName = item.FullName;
|
||||
//cus.Info = item.Info;
|
||||
//cus.MeliCode = item.MeliCode;
|
||||
//cus.PassportNumber = item.PassportNumber;
|
||||
//cus.Phone = item.Phone;
|
||||
//cus.ZipCode = item.ZipCode;
|
||||
//cus.IsDeleted = false;
|
||||
////-----change Cod
|
||||
Cod.TaxRate = item.TaxRate;
|
||||
Cod.Title = item.Title;
|
||||
Cod.UnitID = item.UnitID;
|
||||
Cod.ItemTaxID = item.TaxID;
|
||||
Cod.IsDeleted = false;
|
||||
|
||||
////----Update and sendResult
|
||||
//return Ok(await _servCus.AddOrUpdateCustomer(cus));
|
||||
//----Update and sendResult
|
||||
return Ok(await _servCOD.AddOrUpdateCod(Cod));
|
||||
}
|
||||
[HttpDelete("Delete/{ID}")]
|
||||
public async Task<ActionResult<bool>> Delete(int ID)
|
||||
{
|
||||
return Ok();
|
||||
////-----GetUserAndCompany
|
||||
//var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
//var UserID = claim.Value;
|
||||
//var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
//-----GetUserAndCompany
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
|
||||
////-----Get Cus
|
||||
//var cus = await _servCus.GetCustomerByCustomerID(ID, user.RolUsers.First().CompanyID);
|
||||
//if (cus == null)
|
||||
// return NotFound();
|
||||
//-----Get Cus
|
||||
var cod = await _servCOD.GetCodByCodID(ID, user.RolUsers.First().CompanyID);
|
||||
if (cod == null)
|
||||
return NotFound();
|
||||
|
||||
////----Update and sendResult
|
||||
//return Ok(await _servCus.DeleteCustomer(cus));
|
||||
//----Update and sendResult
|
||||
return Ok(await _servCOD.DeleteCod(cod));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ builder.Services.AddScoped<servTaxPayer>();
|
||||
builder.Services.AddScoped<servCustomer>();
|
||||
builder.Services.AddScoped<CompanyRegistrationValidation>();
|
||||
builder.Services.AddScoped<AddOrCustomerValidation>();
|
||||
builder.Services.AddScoped<AddOrCodValidation>();
|
||||
builder.Services.AddScoped<ServCOD>();
|
||||
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
||||
|
||||
|
@@ -11,11 +11,13 @@ namespace Back.Services
|
||||
{
|
||||
private readonly IAsyncRepository<CODItem> _CODRepo;
|
||||
private readonly IAsyncRepository<CODUnit> _UnitRepo;
|
||||
public ServCOD(IAsyncRepository<CODItem> CODRepo, IAsyncRepository<CODUnit> unitRepo)
|
||||
private readonly CheckPermission _checkPermission;
|
||||
public ServCOD(IAsyncRepository<CODItem> CODRepo, IAsyncRepository<CODUnit> unitRepo
|
||||
, CheckPermission checkPermission)
|
||||
{
|
||||
_CODRepo = CODRepo;
|
||||
_UnitRepo = unitRepo;
|
||||
|
||||
_checkPermission = checkPermission;
|
||||
}
|
||||
public async Task<PagingDto<RCOD>?> GetCODs(int CompanyID, ItemSerchGetCOD itemSerch)
|
||||
{
|
||||
@@ -47,6 +49,7 @@ namespace Back.Services
|
||||
TaxID = s.ItemTaxID,
|
||||
Title = s.Title,
|
||||
Unit = s.CODUnit.Title,
|
||||
UnitID=s.UnitID,
|
||||
TaxRate = s.TaxRate
|
||||
})
|
||||
.Paging(itemSerch.PageIndex, itemSerch.PageSize);
|
||||
@@ -55,5 +58,96 @@ namespace Back.Services
|
||||
{
|
||||
return await _UnitRepo.GetAll().Select(s => new IdName<int> { ID = s.ID, Title = s.Title }).ToListAsync();
|
||||
}
|
||||
public async Task<CODItem?> GetCodByCodID(int CodID, int CompanyID)
|
||||
{
|
||||
return await _CODRepo
|
||||
.Get(w => w.ID == CodID && w.CompanyID == CompanyID && !w.IsDeleted).FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<bool> ExistCodByCustomerID(int CodID, int CompanyID)
|
||||
{
|
||||
return await _CODRepo
|
||||
.Get(w => w.ID == CodID && w.CompanyID == CompanyID && !w.IsDeleted).AnyAsync();
|
||||
}
|
||||
public async Task<bool> ExistUnit(int UnitID)
|
||||
{
|
||||
return await _UnitRepo
|
||||
.Get(w => w.ID == UnitID ).AnyAsync();
|
||||
}
|
||||
public async Task<bool> AddOrUpdateCod(CODItem item)
|
||||
{
|
||||
try
|
||||
{
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer",
|
||||
// Value = "*" + JsonConvert.SerializeObject(item),
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "User"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
|
||||
if (item.ID == null || item.ID <= 0)
|
||||
{
|
||||
var ret = await _CODRepo.AddBoolResultAsync(item);
|
||||
await _checkPermission.ExtensionofAccess(item.CompanyID, 5, "-1");
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return await _CODRepo.UpdateAsync(item);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer",
|
||||
// Value = ex.Message,
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "catch"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<bool> DeleteCod(CODItem item)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
item.IsDeleted = true;
|
||||
return await _CODRepo.UpdateAsync(item);
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/DeleteCustomer",
|
||||
// Value = JsonConvert.SerializeObject(item.ID),
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "User"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//SysLog log = new SysLog()
|
||||
//{
|
||||
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
||||
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
||||
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/DeleteCustomer",
|
||||
// Value = ex.Message,
|
||||
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
||||
// Type = "catch"
|
||||
//};
|
||||
//_contextMongodb.InsertItem(log);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
Back/Validations/AddOrCodValidation.cs
Normal file
65
Back/Validations/AddOrCodValidation.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Back.Common;
|
||||
using Back.Services;
|
||||
using FluentValidation;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Validations
|
||||
{
|
||||
public class AddOrCodValidation : AbstractValidator<Tuple<int, RCOD, eActionValidation>>
|
||||
{
|
||||
public AddOrCodValidation(CheckPermission _checkPermission, ServCOD servCod)
|
||||
{
|
||||
CascadeMode = CascadeMode.Stop;
|
||||
When(r => r.Item3 == eActionValidation.add, () =>
|
||||
{
|
||||
RuleFor(r => r.Item1)
|
||||
.Custom((CompanyID, context) =>
|
||||
{
|
||||
|
||||
if (!_checkPermission.AllowAddCODInCompany(CompanyID).Result)
|
||||
context.AddFailure("اضافه کردن کالا محدود شده است");
|
||||
});
|
||||
});
|
||||
|
||||
When(r => r.Item3 == eActionValidation.update, () =>
|
||||
{
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
var companyid = model.Item1;
|
||||
if (!model.Item2.ID.HasValue || model.Item2.ID <= 0)
|
||||
context.AddFailure("شناسه کالا نمی تواند خالی باشذ");
|
||||
else
|
||||
{
|
||||
var customerid = model.Item2.ID.Value;
|
||||
if (!servCod.ExistCodByCustomerID(customerid, companyid).Result)
|
||||
context.AddFailure("کالا با این شناسه یافت نشد");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
RuleFor(r => r.Item2.Title)
|
||||
.NotNull().WithMessage("نام نمی تواند خالی باشد")
|
||||
.NotEmpty().WithMessage("نام نمی تواند خالی باشد")
|
||||
.MinimumLength(3).WithMessage("حداقل کارکتر مجار نام 3 می باشد");
|
||||
//
|
||||
RuleFor(r => r.Item2.UnitID)
|
||||
.NotNull().WithMessage("واحد اندازه گیزی نمی تواند خالی باشد")
|
||||
.NotEmpty().WithMessage("واحد اندازه گیزی نمی تواند خالی باشد")
|
||||
;
|
||||
RuleFor(r => r.Item2.TaxRate)
|
||||
.NotNull().WithMessage("نرخ مالیات نمی تواند خالی باشد")
|
||||
.NotEmpty().WithMessage("نرخ مالیات نمی تواند خالی باشد")
|
||||
.Custom((TaxRate, context) =>
|
||||
{
|
||||
if (TaxRate > 100)
|
||||
context.AddFailure("نرخ مالیات نمی تواند بیشتر از 100 باشد");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,12 +18,27 @@
|
||||
<div class="form-group col-md-6">
|
||||
<label class="col-sm-5 col-form-label" style="color:red" for="inputUnitID">واحد اندازه گیزی</label>
|
||||
<select @bind="Cod.UnitID" class="form-control" aria-label="Default select example" id="inputUnitID">
|
||||
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
|
||||
@if (Cod.UnitID > 0)
|
||||
{
|
||||
<option value="0" style="color: #b5b5b5" selected>انتخاب کنید...</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="0" style="color: #b5b5b5">انتخاب کنید...</option>
|
||||
}
|
||||
|
||||
@if (Unitrequest != null)
|
||||
{
|
||||
foreach (var item in Unitrequest)
|
||||
{
|
||||
<option value="@item.ID">@item.Title</option>
|
||||
if (Cod.UnitID == item.ID)
|
||||
{
|
||||
<option value="@item.ID" selected>@item.Title</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
<option value="@item.ID">@item.Title</option>
|
||||
}
|
||||
}
|
||||
}
|
||||
</select>
|
||||
|
@@ -6,15 +6,15 @@
|
||||
</div>
|
||||
<div class="rc__post-content">
|
||||
<h3 class="rc__post-title">
|
||||
<a href="blog-details.html">
|
||||
<a href="@Navigation.ToAbsoluteUri($"/BlogDetails/{@Item?.ID}")">
|
||||
@Item?.Title.Split(':')[1]
|
||||
</a>
|
||||
</h3><a href="blog-details.html">
|
||||
</h3><a>
|
||||
<div class="rc__meta">
|
||||
<span>@Item?.Date</span>
|
||||
</div>
|
||||
</a>
|
||||
</div><a href="blog-details.html">
|
||||
</div><a>
|
||||
</a>
|
||||
</div><a href="@Navigation.ToAbsoluteUri($"/BlogDetails/{@Item?.ID}")"></a>
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="tp-blog-title-box">
|
||||
<a class="tp-blog-title-sm" href="blog-details.html">@Item?.Title.Split(':')[1]</a>
|
||||
<a class="tp-blog-title-sm" href="@Navigation.ToAbsoluteUri($"/BlogDetails/{@Item?.ID}")">@Item?.Title.Split(':')[1]</a>
|
||||
</div>
|
||||
<div class="tp-blog-author-info-box d-flex align-items-center">
|
||||
<div class="tp-blog-avata">
|
||||
|
Reference in New Issue
Block a user