83 lines
3.2 KiB
C#
83 lines
3.2 KiB
C#
![]() |
using Back.Common;
|
|||
|
using Back.Data.Models;
|
|||
|
using Back.Services;
|
|||
|
using Back.Validations;
|
|||
|
using Microsoft.AspNetCore.Http;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using Shared.DTOs;
|
|||
|
using Shared.DTOs.Serch;
|
|||
|
|
|||
|
namespace Back.Controllers
|
|||
|
{
|
|||
|
[Route("api/[controller]")]
|
|||
|
[ApiController]
|
|||
|
public class InvoiceController : ControllerBase
|
|||
|
{
|
|||
|
private readonly servInvoice _servInvoice;
|
|||
|
private readonly servUser _servUser;
|
|||
|
private readonly AddOrUpdateInvoiceValidation _validationInvoice;
|
|||
|
public InvoiceController(servInvoice servInvoice, servUser servUser, AddOrUpdateInvoiceValidation validationInvoice)
|
|||
|
{
|
|||
|
_servInvoice = servInvoice;
|
|||
|
_servUser = servUser;
|
|||
|
_validationInvoice = validationInvoice;
|
|||
|
|
|||
|
}
|
|||
|
[HttpPost("GetAll")]
|
|||
|
public async Task<ActionResult<PagingDto<InvoiceDTO>?>> GetAll([FromBody] ItemSerchGetInvoices itemSerch)
|
|||
|
{
|
|||
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|||
|
var UserID = claim.Value;
|
|||
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
|||
|
|
|||
|
return Ok(await _servInvoice.GetInvoices(user.RolUsers.First().CompanyID, itemSerch));
|
|||
|
|
|||
|
}
|
|||
|
[HttpPost("AddORUpdateInvoice/{CompanyID}")]//ok
|
|||
|
public async Task<ActionResult<int>> AddORUpdateInvoice(int CompanyID, [FromBody] NUInvoiceDTO item)
|
|||
|
{
|
|||
|
if (!ModelState.IsValid)
|
|||
|
return BadRequest(item);
|
|||
|
|
|||
|
//-----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 _validationInvoice.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, item, eActionValidation.add));
|
|||
|
if (!resultValidationmodel.IsValid)
|
|||
|
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
|||
|
|
|||
|
|
|||
|
//if (item.BillReference.HasValue)
|
|||
|
//{
|
|||
|
// Invoice ReferenceInvoice = await _servInvoice.GetInvoiceByInvoiceID(item.BillReference.Value);
|
|||
|
// if (ReferenceInvoice == null) return NotFound("صورتحساب مرجع یافت نشد");
|
|||
|
|
|||
|
// if (await _servCompany.ExsistCompanyByComoanyIDandUserID(UserID, ReferenceInvoice.CompanyID.Value)) return Forbid("صورتحساب مرجع برای شما در دسترس نمی باشد");
|
|||
|
//}
|
|||
|
|
|||
|
|
|||
|
return Ok(_servInvoice.AddInvoice(new Invoice()
|
|||
|
{
|
|||
|
|
|||
|
Title = item.Title,
|
|||
|
Des = item.Des,
|
|||
|
invoiceType = InvoiceType.Bidding,
|
|||
|
CustomerID = item.CustomerID,
|
|||
|
CompanyID = CompanyID,
|
|||
|
InvoicIssueDate = item.InvoicIssueDate.Replace("/", ""),
|
|||
|
InvoiceDate = item.InvoicIssueDate.Replace("/", ""),
|
|||
|
LastChangeUserID = Convert.ToInt32(UserID),
|
|||
|
BillReference = null,
|
|||
|
IsDeleted = false,
|
|||
|
PatternID = item.PatternID
|
|||
|
}));
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|