...
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Back.Data.Models;
|
||||
using Back.Common;
|
||||
using Back.Data.Models;
|
||||
using Back.Services;
|
||||
using Back.Services.Warehouse;
|
||||
using Back.Validations.Warehouse.Receipt;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -17,6 +19,19 @@ namespace Back.Controllers.Warehouse
|
||||
{
|
||||
private readonly ReceiptService _receiptService;
|
||||
private readonly servUser _servUser;
|
||||
private readonly ADDValidation _addvalidation;
|
||||
private readonly UpdateValidation _updatevalidation;
|
||||
private readonly DeleteValidation _deletevalidation;
|
||||
|
||||
public ReceiptController(ReceiptService receiptService, servUser servUser, ADDValidation addvalidation, UpdateValidation updatevalidation, DeleteValidation deletevalidation)
|
||||
{
|
||||
_receiptService = receiptService;
|
||||
_servUser = servUser;
|
||||
_addvalidation = addvalidation;
|
||||
_updatevalidation = updatevalidation;
|
||||
_deletevalidation = deletevalidation;
|
||||
}
|
||||
|
||||
[HttpGet("{ItemID}")]
|
||||
public async Task<IActionResult> Get(int ItemID)
|
||||
{
|
||||
@@ -38,8 +53,19 @@ namespace Back.Controllers.Warehouse
|
||||
[HttpPost("ADD")]
|
||||
public async Task<IActionResult> AddReceipt(ReceiptDto item)
|
||||
{
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _addvalidation.ValidateAsync(Tuple.Create(item,CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
|
||||
// validate ADD
|
||||
var newmodel = await _receiptService.ADD(item);
|
||||
var newmodel = await _receiptService.ADD(item, CompanyID);
|
||||
if (newmodel != null) return Ok(newmodel);
|
||||
else return BadRequest(new List<string> { "خطا در صدور" });
|
||||
}
|
||||
@@ -47,7 +73,16 @@ namespace Back.Controllers.Warehouse
|
||||
[HttpPut("Update")]
|
||||
public async Task<IActionResult> UpdateReceipt(ReceiptDto item)
|
||||
{
|
||||
// validate Update
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _updatevalidation.ValidateAsync(Tuple.Create(item, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var Updatemodel = await _receiptService.Update(item);
|
||||
if (Updatemodel != null) return Ok(Updatemodel);
|
||||
else return BadRequest(new List<string> { "خطا در ویرایش" });
|
||||
@@ -61,6 +96,11 @@ namespace Back.Controllers.Warehouse
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
var CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
//-----Validaton
|
||||
var resultValidationmodel = await _deletevalidation.ValidateAsync(Tuple.Create(ItemID, CompanyID));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
var Deletemodel = await _receiptService.Delete(ItemID, CompanyID);
|
||||
if (Deletemodel) return Ok();
|
||||
else return BadRequest(new List<string> { "خطا در حذف" });
|
||||
|
Reference in New Issue
Block a user