order
This commit is contained in:
57
Back/Controllers/OrderssController.cs
Normal file
57
Back/Controllers/OrderssController.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Back.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs;
|
||||
using Shared.DTOs.Serch;
|
||||
|
||||
namespace Back.Controllers
|
||||
{
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class OrderssController : ControllerBase
|
||||
{
|
||||
private readonly ServOrders _servOrders;
|
||||
private readonly ServPromotion _servPromotion;
|
||||
private readonly ServPricing _servPricing;
|
||||
private readonly servUser _servUser;
|
||||
|
||||
public OrderssController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser)
|
||||
{
|
||||
_servOrders = servOrders;
|
||||
_servPricing = servPricing;
|
||||
_servPromotion = servPromotion;
|
||||
_servUser = servUser;
|
||||
|
||||
}
|
||||
[HttpGet("GetAllPromotion")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<List<PromotionDto>>> GetAllPromotion() =>Ok(await _servPromotion.GetAll());
|
||||
|
||||
[HttpGet("GetAllPricing")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<List<PricingDto>>> GetAllPricing() => Ok(await _servPricing.GetPricing());
|
||||
[HttpPost("GetAllOrder")]
|
||||
public async Task<ActionResult<List<OrderDto>>> GetAllOrder(ItemSerachOrder itemSerach)
|
||||
{
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
int CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
return Ok(await _servOrders.GetOrdersByCompanyID(CompanyID,itemSerach));
|
||||
}
|
||||
[HttpGet("GetOrderDetails/{OrderID}")]
|
||||
public async Task<ActionResult<List<OrderDto>>> GetOrderDetails(int OrderID)
|
||||
{
|
||||
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||
var UserID = claim.Value;
|
||||
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||
int CompanyID = user.RolUsers.First().CompanyID;
|
||||
|
||||
return Ok(await _servOrders.GetOrderItems(CompanyID, OrderID));
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,7 +13,10 @@ namespace Back.Data.Models
|
||||
public string ApprovalDate { get; set; }
|
||||
public decimal PreDiscount { get { return OrderItems.Sum(s => s.Total); } }
|
||||
public decimal TDiscount { get; set; } = 0;
|
||||
public decimal TPrice { get { return OrderItems.Sum(s => s.Total) - TDiscount; } }
|
||||
public decimal lstDiscount { get { return OrderItems.Sum(s => s.Total) - TDiscount; } }
|
||||
public decimal TTax { get { return OrderItems.Sum(s => s.Tax); } }
|
||||
public decimal TPrice { get { return lstDiscount - TTax; } }
|
||||
|
||||
|
||||
#region Navigation
|
||||
[ForeignKey("CompanyID")]
|
||||
|
@@ -6,8 +6,8 @@ namespace Back.Data.Models
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int OrderID { get; set; }
|
||||
public int PermissionID { get; set; }
|
||||
public int CalculationTypeID { get; set; }
|
||||
public int? PermissionID { get; set; }
|
||||
public int? PromotionID { get; set; }
|
||||
public int CreditAmount { get; set; }
|
||||
public decimal APrice { get; set; }
|
||||
public decimal Discount { get; set; }
|
||||
@@ -18,9 +18,9 @@ namespace Back.Data.Models
|
||||
[ForeignKey("OrderID")]
|
||||
public virtual Order Order { get; set; }
|
||||
[ForeignKey("PermissionID")]
|
||||
public virtual Permission Permission { get; set; }
|
||||
[ForeignKey("CalculationTypeID")]
|
||||
public virtual CalculationType CalculationType { get; set; }
|
||||
public virtual Permission? Permission { get; set; }
|
||||
[ForeignKey("PromotionID")]
|
||||
public virtual Promotion? Promotion { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -6,10 +6,9 @@ namespace Back.Data.Models
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool Satus { get; set; }
|
||||
public bool Status { get; set; }
|
||||
|
||||
|
||||
public IEnumerable<PromotionDetails> PromotionDetails { get; set; }
|
||||
public virtual IEnumerable<PromotionDetails> PromotionDetails { get; set; }
|
||||
}
|
||||
public class PromotionDetails
|
||||
{
|
||||
@@ -21,9 +20,9 @@ namespace Back.Data.Models
|
||||
public decimal TPrice { get { return APrice * CreditAmount; } }
|
||||
|
||||
[ForeignKey("PermissionID")]
|
||||
public Permission Permission { get; set; }
|
||||
public virtual Permission Permission { get; set; }
|
||||
[ForeignKey("PromotionID")]
|
||||
public Promotion Promotion { get; set; }
|
||||
public virtual Promotion Promotion { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -77,6 +77,9 @@ builder.Services.AddScoped<AUInvoiceItemValidation>();
|
||||
builder.Services.AddScoped<servInvoiceItem>();
|
||||
builder.Services.AddScoped<ActionTaxPayer>();
|
||||
builder.Services.AddScoped<Servstuff>();
|
||||
builder.Services.AddScoped<ServPromotion>();
|
||||
builder.Services.AddScoped<ServOrders>();
|
||||
builder.Services.AddScoped<ServPricing>();
|
||||
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
||||
|
||||
string origins = "OriginTaxPayer";
|
||||
|
62
Back/Services/ServOrders.cs
Normal file
62
Back/Services/ServOrders.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shared.DTOs;
|
||||
using Shared.DTOs.Serch;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
public class ServOrders
|
||||
{
|
||||
private readonly IAsyncRepository<Order> _repoOrder;
|
||||
private readonly IAsyncRepository<OrderItem> _repoOrderItem;
|
||||
|
||||
|
||||
public ServOrders(IAsyncRepository<Order> repoOrder, IAsyncRepository<OrderItem> repoOrderItem)
|
||||
{
|
||||
_repoOrder = repoOrder;
|
||||
_repoOrderItem = repoOrderItem;
|
||||
|
||||
}
|
||||
public async Task<List<OrderDto>> GetOrdersByCompanyID(int CompanyID, ItemSerachOrder itemSerach)
|
||||
{
|
||||
var request = _repoOrder.Get(w => w.CompanyID == CompanyID);
|
||||
|
||||
if (itemSerach.Status.HasValue)
|
||||
request = request.Where(w => w.Status == itemSerach.Status);
|
||||
|
||||
if (itemSerach.ID.HasValue)
|
||||
request = request.Where(w => w.ID == itemSerach.ID);
|
||||
|
||||
request = request.Include(inc => inc.OrderItems);
|
||||
return await request
|
||||
.Select(w => new OrderDto
|
||||
{
|
||||
ApprovalDate = w.ApprovalDate,
|
||||
DateCreate = w.DateCreate,
|
||||
ID = w.ID,
|
||||
PreDiscount = w.PreDiscount,
|
||||
Status = w.Status,
|
||||
TDiscount = w.TDiscount,
|
||||
TPrice = w.TPrice,
|
||||
TTax = w.TPrice,
|
||||
lstDiscount = w.lstDiscount,
|
||||
}).ToListAsync();
|
||||
}
|
||||
public async Task<List<OrderItemDto>> GetOrderItems(int OrderID,int CompanyID)
|
||||
{
|
||||
return await _repoOrderItem.Get(w => w.OrderID == OrderID && w.Order.CompanyID== CompanyID)
|
||||
.Select(s=>new OrderItemDto
|
||||
{
|
||||
OrderID = OrderID,
|
||||
APrice = s.APrice,
|
||||
CreditAmount = s.CreditAmount,
|
||||
Discount=s.Discount,
|
||||
ID = s.ID,
|
||||
Tax = s.Tax,
|
||||
Type= s.PermissionID.HasValue && !s.PromotionID.HasValue ? "" : !s.PermissionID.HasValue && s.PromotionID.HasValue ? "تعرفه" : "نامشخص",
|
||||
IDForType = s.PermissionID.HasValue && !s.PromotionID.HasValue ? s.PermissionID.Value : !s.PermissionID.HasValue && s.PromotionID.HasValue ? s.PromotionID.Value : 0
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
28
Back/Services/ServPricing.cs
Normal file
28
Back/Services/ServPricing.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
|
||||
public class ServPricing
|
||||
{
|
||||
private readonly IAsyncRepository<Pricing> _repoPricing;
|
||||
|
||||
public ServPricing(IAsyncRepository<Pricing> repoPricing)
|
||||
{
|
||||
_repoPricing = repoPricing;
|
||||
}
|
||||
public async Task<List<PricingDto>> GetPricing()
|
||||
{
|
||||
return await _repoPricing.GetAll()
|
||||
.Select(s=>new PricingDto
|
||||
{
|
||||
PermissionID = s.PermissionID,
|
||||
PermissionTitle=s.Permission.Title,
|
||||
Price = s.Price,
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
41
Back/Services/ServPromotion.cs
Normal file
41
Back/Services/ServPromotion.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
|
||||
|
||||
public class ServPromotion
|
||||
{
|
||||
private readonly IAsyncRepository<Promotion> _repoPromotion;
|
||||
private readonly IAsyncRepository<PromotionDetails> _repoPromotionDetails;
|
||||
|
||||
|
||||
public ServPromotion(IAsyncRepository<Promotion> repoPromotion, IAsyncRepository<PromotionDetails> repoPromotionDetails)
|
||||
{
|
||||
_repoPromotion = repoPromotion;
|
||||
_repoPromotionDetails = repoPromotionDetails;
|
||||
|
||||
}
|
||||
public async Task<List<PromotionDto>> GetAll()
|
||||
{
|
||||
return await _repoPromotion.Get(w => w.Status)
|
||||
.Include(inc => inc.PromotionDetails).ThenInclude(tinc => tinc.Permission)
|
||||
.Select(s => new PromotionDto
|
||||
{
|
||||
ID = s.ID,
|
||||
Name = s.Name,
|
||||
promotionDetails = s.PromotionDetails.Select(s => new PromotionDetailDto
|
||||
{
|
||||
ID = s.ID,
|
||||
APrice = s.APrice,
|
||||
CreditAmount = s.CreditAmount,
|
||||
PermissionID = s.PermissionID,
|
||||
PermissionTitle = s.Permission.Title
|
||||
}).ToList()
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
22
Shared/DTOs/OrderDto.cs
Normal file
22
Shared/DTOs/OrderDto.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTOs
|
||||
{
|
||||
public class OrderDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public StatusOrder Status { get; set; }
|
||||
public string StatusTitle { get { return Status.GetEnumDisplayName(); } }
|
||||
public string DateCreate { get; set; }
|
||||
public string ApprovalDate { get; set; }
|
||||
public decimal PreDiscount { get; set; }
|
||||
public decimal TDiscount { get; set; }
|
||||
public decimal lstDiscount { get; set; }
|
||||
public decimal TTax { get; set; }
|
||||
public decimal TPrice { get; set; }
|
||||
}
|
||||
}
|
21
Shared/DTOs/OrderItemDto.cs
Normal file
21
Shared/DTOs/OrderItemDto.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTOs
|
||||
{
|
||||
public class OrderItemDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int OrderID { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int IDForType { get; set; }
|
||||
public int CreditAmount { get; set; }
|
||||
public decimal APrice { get; set; }
|
||||
public decimal Discount { get; set; }
|
||||
public decimal Tax { get; set; }
|
||||
public decimal Total { get { return (CreditAmount * APrice) - Discount + Tax; } }
|
||||
}
|
||||
}
|
15
Shared/DTOs/PricingDto.cs
Normal file
15
Shared/DTOs/PricingDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTOs
|
||||
{
|
||||
public class PricingDto
|
||||
{
|
||||
public int PermissionID { get; set; }
|
||||
public string PermissionTitle { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
}
|
||||
}
|
18
Shared/DTOs/PromotionDetailDto.cs
Normal file
18
Shared/DTOs/PromotionDetailDto.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTOs
|
||||
{
|
||||
public class PromotionDetailDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int PermissionID { get; set; }
|
||||
public string PermissionTitle { get; set; }
|
||||
public int CreditAmount { get; set; }
|
||||
public decimal APrice { get; set; }
|
||||
public decimal TPrice { get { return APrice * CreditAmount; } }
|
||||
}
|
||||
}
|
15
Shared/DTOs/PromotionDto.cs
Normal file
15
Shared/DTOs/PromotionDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTOs
|
||||
{
|
||||
public class PromotionDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ICollection<PromotionDetailDto> promotionDetails { get; set; }
|
||||
}
|
||||
}
|
14
Shared/DTOs/Serch/ItemSerachOrder.cs
Normal file
14
Shared/DTOs/Serch/ItemSerachOrder.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.DTOs.Serch
|
||||
{
|
||||
public class ItemSerachOrder
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public StatusOrder? Status { get; set; }
|
||||
}
|
||||
}
|
@@ -5,10 +5,10 @@ namespace Shared.DTOs
|
||||
public enum StatusOrder
|
||||
{
|
||||
[Display(Name = "ساخته شده")]
|
||||
Create,
|
||||
Create=1,
|
||||
[Display(Name = "پرداخت شده")]
|
||||
Paid,
|
||||
Paid=2,
|
||||
[Display(Name = "انصراف داده شده")]
|
||||
Cancel
|
||||
Cancel=3
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user