start cod

This commit is contained in:
mmrbnjd
2024-05-08 17:43:41 +03:30
parent 716f02baa1
commit c3c74635cb
5 changed files with 123 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
using Back.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs.Serch;
using Shared.DTOs;
namespace Back.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CODController : ControllerBase
{
private readonly ServCOD _servCOD;
private readonly servUser _servUser;
public CODController(ServCOD servCOD, servUser servUser)
{
_servCOD = servCOD;
_servUser = servUser;
}
[HttpPost("GetAll")]
public async Task<ActionResult<PagingDto<RCOD>?>> GetAll([FromBody] ItemSerchGetCOD itemSerch)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
// if (!await _checkPermission.AllowSYSGetCOD(Convert.ToInt32(UserID), user.RolUsers.First().CompanyID)) return Forbid("شما دسترسی به خواندن اطلاعات کالا را نداربد");
return Ok(await _servCOD.GetCODs(user.RolUsers.First().CompanyID, itemSerch));
}
}
}

View File

@@ -15,15 +15,12 @@ namespace Back.Controllers
[ApiController]
public class CustomerController : ControllerBase
{
private readonly CheckPermission _checkPermission;
private readonly servUser _servUser;
private readonly servCustomer _servCus;
private readonly AddOrCustomerValidation _addorupdateCustomerValidation;
public CustomerController(CheckPermission checkPermission, servUser servUser
, servCustomer servCus, AddOrCustomerValidation addorupdateCustomerValidation)
public CustomerController( servUser servUser, servCustomer servCus, AddOrCustomerValidation addorupdateCustomerValidation)
{
_addorupdateCustomerValidation = addorupdateCustomerValidation;
_checkPermission = checkPermission;
_servUser = servUser;
_servCus = servCus;
}
@@ -34,7 +31,7 @@ namespace Back.Controllers
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
if (!await _checkPermission.AllowSYSGetCustomer(Convert.ToInt32(UserID), user.RolUsers.First().CompanyID)) return Forbid("شما دسترسی به خواندن اطلاعات مشتری را نداربد");
// if (!await _checkPermission.AllowSYSGetCustomer(Convert.ToInt32(UserID), user.RolUsers.First().CompanyID)) return Forbid("شما دسترسی به خواندن اطلاعات مشتری را نداربد");
return Ok(await _servCus.GetCustomers(user.RolUsers.First().CompanyID, itemSerch));

51
Back/Services/ServCOD.cs Normal file
View File

@@ -0,0 +1,51 @@
using Back.Common;
using Back.Data.Contracts;
using Back.Data.Models;
using Shared.DTOs;
using Shared.DTOs.Serch;
namespace Back.Services
{
public class ServCOD
{
private readonly IAsyncRepository<CODItem> _CODRepo;
public ServCOD(IAsyncRepository<CODItem> CODRepo)
{
_CODRepo = CODRepo;
}
public async Task<PagingDto<RCOD>?> GetCODs(int CompanyID, ItemSerchGetCOD itemSerch)
{
#region AdvancedSearch
var invok = _CODRepo
.Get(w => w.CompanyID == CompanyID && !w.IsDeleted);
//foreach (InputObj item in inputObjs)
// invok = invok.Where(ExMethod.GetFunc<CODItem>(item.Param, item.Value));
if (!string.IsNullOrEmpty(itemSerch.Title))
invok = invok.Where(w => w.Title.Contains(itemSerch.Title));
if (!string.IsNullOrEmpty(itemSerch.ItemTaxID))
invok = invok.Where(w => w.ItemTaxID == itemSerch.ItemTaxID);
if (itemSerch.CODID.HasValue)
invok = invok.Where(w => w.ID == itemSerch.CODID);
if (itemSerch.UnitID.HasValue)
invok = invok.Where(w => w.UnitID == itemSerch.UnitID);
#endregion
//-----------------------
return await invok.Select(s => new RCOD()
{
ID = s.ID,
TaxID = s.ItemTaxID,
Title = s.Title,
Unit = s.CODUnit.Title,
TaxRate = s.TaxRate
})
.Paging(itemSerch.PageIndex, itemSerch.PageSize);
}
}
}

20
Shared/DTOs/RCOD.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs
{
public class RCOD
{
public int? ID { get; set; }
public string? TaxID { get; set; }
public string Title { get; set; }
public int UnitID { get; set; }
public string? Unit { get; set; }
public int TaxRate { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs.Serch
{
public class ItemSerchGetCOD : IFildGlobalItemSerch
{
public int? CODID { get; set; }
public string? ItemTaxID { get; set; }
public string? Title { get; set; }
public int? UnitID { get; set; }
public int PageIndex { get; set; } = 1;
public int PageSize { get; set; } = 5;
}
}