Skip to content

Commit

Permalink
add-order
Browse files Browse the repository at this point in the history
  • Loading branch information
mzahidberber committed Sep 28, 2023
1 parent 023ff6d commit ab41d4c
Show file tree
Hide file tree
Showing 86 changed files with 12,873 additions and 235 deletions.
Binary file modified .vs/ProjectEvaluation/shopapp.metadata.v6.1
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/shopapp.projects.v6.1
Binary file not shown.
Binary file modified .vs/shopapp/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/shopapp/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/shopapp/v17/fileList.bin
Binary file not shown.
1 change: 1 addition & 0 deletions shopapp.business/Concrete/Mapper/DTOMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal class DTOMapper : Profile
public DTOMapper()
{
CreateMap<ProductDTO, Product>().ReverseMap();
CreateMap<OrderItemDTO, OrderItem>().ReverseMap();
CreateMap<OrderDTO, Order>().ReverseMap();
CreateMap<UserDTO, User>().ReverseMap();
CreateMap<CartDTO, Cart>().ReverseMap();
Expand Down
65 changes: 65 additions & 0 deletions shopapp.business/Concrete/OrderService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Microsoft.EntityFrameworkCore;
using shopapp.business.Concrete.Mapper;
using shopapp.core.Business.Abstract;
using shopapp.core.DataAccess.Abstract;
using shopapp.core.DTOs.Abstract;
using shopapp.core.DTOs.Concrete;
using shopapp.core.Entity.Concrete;
using shopapp.dataaccess.Concrete.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace shopapp.business.Concrete;

public class OrderService : GenericService<Order, OrderDTO>, IOrderService
{
public IOrderRepository _genericRepository { get; set; }
public OrderService(IOrderRepository genericRepository) : base(genericRepository)
{
_genericRepository = genericRepository;
}

public async Task<Response<OrderDTO>> ChangeOrderState(int id,EnumOrderState state)
{
var product = await _genericRepository.GetByIdAsync(id);
if (product == null)
{
return Response<OrderDTO>.Fail("Id Not Found", 404, true);
}
if ((int)product.State<6)
product.State=state;
_genericRepository.Update(product);
await _genericRepository.CommitAsync();

return Response<OrderDTO>.Success(ObjectMapper.Mapper.Map<OrderDTO>(product), 200);
}

public async Task<Response<OrderDTO>> GetByIdWithUserAsync(int id)
{
var product = await _genericRepository.GetByIdWithUserAsync(id);
await _genericRepository.CommitAsync();
if (product == null)
{
return Response<OrderDTO>.Fail("Id Not Found", 404, true);
}
return Response<OrderDTO>.Success(ObjectMapper.Mapper.Map<OrderDTO>(product), 200);
}

public async Task<Response<IEnumerable<OrderDTO>>> GetAllWithUserAsync()
{
var products = ObjectMapper.Mapper.Map<List<OrderDTO>>(await _genericRepository.GetAllWithUser().ToListAsync());
await _genericRepository.CommitAsync();
return Response<IEnumerable<OrderDTO>>.Success(products, 200);
}

public async Task<Response<IEnumerable<OrderDTO>>> WhereWithProducts(Expression<Func<Order, bool>> predicate)
{
var list = await _genericRepository.GetWhereWithProduct(predicate).ToListAsync();
await _genericRepository.CommitAsync();
return Response<IEnumerable<OrderDTO>>.Success(ObjectMapper.Mapper.Map<IEnumerable<OrderDTO>>(list), 200);
}
}
40 changes: 38 additions & 2 deletions shopapp.business/Concrete/ProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using shopapp.core.DTOs.Abstract;
using shopapp.core.DTOs.Concrete;
using shopapp.core.Entity.Concrete;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Security.Policy;

namespace shopapp.business.Concrete;

[LogAspect(Priority = 1)]
//[LogAspect(Priority = 1)]
public class ProductService : GenericService<Product, ProductDTO>, IProductService
{
private readonly IProductRepository _genericRepository;
Expand All @@ -20,7 +22,41 @@ public ProductService(IProductRepository genericRepository) : base(genericReposi
_genericRepository = genericRepository;
}

public async Task<Response<IEnumerable<ProductDTO>>> WhereWithAtt(Expression<Func<Product, bool>> predicate)
public async Task<Response<NoDataDTO>> ReductionStock(int productId,int quantity)
{
var product= await _genericRepository.GetByIdAsync(productId);
if (product == null)
return Response<NoDataDTO>.Fail("product not found", 404, false);
if (product.Stock-quantity < 0)
return Response<NoDataDTO>.Fail("stock must more than 0",404,false);


product.Stock=product.Stock-quantity;
_genericRepository.Update(product);
await _genericRepository.CommitAsync();
return Response<NoDataDTO>.Success(200);
}
public async Task<Response<NoDataDTO>> ReductionManyProductStock(List<ProductStockChange> productsInfo)
{
foreach (var p in productsInfo)
{
var product = await _genericRepository.GetByIdAsync(p.productId);
if (product == null)
return Response<NoDataDTO>.Fail("product not found", 404, false);
if (product.Stock-p.quantity < 0)
return Response<NoDataDTO>.Fail("stock must more than 0", 404, false);


product.Stock = product.Stock - p.quantity;
_genericRepository.Update(product);
}

await _genericRepository.CommitAsync();
return Response<NoDataDTO>.Success(200);
}


public async Task<Response<IEnumerable<ProductDTO>>> WhereWithAtt(Expression<Func<Product, bool>> predicate)
{
var list = await _genericRepository.GetWhereWithAtt(predicate).ToListAsync();
await _genericRepository.CommitAsync();
Expand Down
3 changes: 2 additions & 1 deletion shopapp.core/Aspects/Logging/LogAspect.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Castle.DynamicProxy;
using NLog;
using System.Collections;

namespace shopapp.core.Aspects.Logging
{
Expand Down Expand Up @@ -42,7 +43,7 @@ private string GetParams(IInvocation IInvocation)

if (argument.GetType().GetProperties().Length > 0 && argument.GetType().Name != "String")
{
if (argument.GetType() != typeof(List<int>))
if (argument.GetType() != typeof(IList))
{
foreach (var prop in argument.GetType().GetProperties())
{
Expand Down
14 changes: 14 additions & 0 deletions shopapp.core/Business/Abstract/IOrderService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using shopapp.core.DTOs.Concrete;
using shopapp.core.Entity.Concrete;
using System.Linq.Expressions;

namespace shopapp.core.Business.Abstract;


public interface IOrderService : IGenericService<Order, OrderDTO>
{
Task<Response<IEnumerable<OrderDTO>>> WhereWithProducts(Expression<Func<Order, bool>> predicate);
Task<Response<IEnumerable<OrderDTO>>> GetAllWithUserAsync();
Task<Response<OrderDTO>> GetByIdWithUserAsync(int id);
Task<Response<OrderDTO>> ChangeOrderState(int id, EnumOrderState state);
}
5 changes: 4 additions & 1 deletion shopapp.core/Business/Abstract/IProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public interface IProductService : IGenericService<Product, ProductDTO>
Task<Response<NoDataDTO>> ChangeHome(int id, bool isHome);
Task<Response<ProductDTO>> AddCheckUrlAsync(ProductDTO entity);
Task<Response<IEnumerable<ProductDTO>>> GetAllWithCategoriesAndBrandAsync();
Task<Response<NoDataDTO>> ReductionStock(int productId, int stock);
Task<Response<NoDataDTO>> ReductionManyProductStock(List<ProductStockChange> productsInfo);


}

}
}
32 changes: 27 additions & 5 deletions shopapp.core/DTOs/Concrete/OrderDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@

namespace shopapp.core.DTOs.Concrete
{
public class OrderDTO : IDTO
public class OrderDTO : IDTO
{
public int Id { get; set; }
public string UserId { get; set; } = null!;
public User User { get; set; }
}
public OrderDTO()
{
this.OrderItems = new List<OrderItemDTO>();
}
public int Id { get; set; }
public string OrderNumber { get; set; }
public EnumOrderState State { get; set; }
public DateTime OrderTime { get; set; }
public double TotalPrice { get; set; }
public UserDTO User { get; set; }
public string UserId { get; set; } = null!;
public List<OrderItemDTO> OrderItems { get; set; }

public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string CityState { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Note { get; set; }

public string PaymentId { get; set; }
public string ConversationId { get; set; }
public EnumPaymentType PaymentType { get; set; }
}
}
16 changes: 16 additions & 0 deletions shopapp.core/DTOs/Concrete/OrderItemDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using shopapp.core.DTOs.Abstract;
using shopapp.core.Entity.Concrete;

namespace shopapp.core.DTOs.Concrete;

public class OrderItemDTO:IDTO
{
public int Id { get; set; }
public int OrderId { get; set; }
public OrderDTO Order { get; set; }
public int ProductId { get; set; }
public ProductDTO Product { get; set; }

public double Price { get; set; }
public int Quantity { get; set; }
}
10 changes: 10 additions & 0 deletions shopapp.core/DTOs/Concrete/OrderProductDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace shopapp.core.DTOs.Concrete;

public class OrderProductDTO
{
public int OrderId { get; set; }
public OrderDTO Order { get; set; }
public int ProductId { get; set; }
public ProductDTO Product { get; set; }
public int Quantity { get; set; }
}
5 changes: 3 additions & 2 deletions shopapp.core/DTOs/Concrete/ProductDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public ProductDTO()
{
this.Images = new List<ImageDTO>();
this.SubCategoryFeatureValues = new List<SubCategoryFeatureValueDTO>();
//this.Stocks = new List<StockDTO>();
this.OrderItems=new List<OrderItemDTO>();
}
public int Id { get; set; }
public string Name { get; set; }
Expand All @@ -34,7 +34,8 @@ public ProductDTO()

public List<ImageDTO> Images { get; set; }

//public List<StockDTO> Stocks { get; set; }
public List<OrderItemDTO> OrderItems { get; set; }


public List<SubCategoryFeatureValueDTO> SubCategoryFeatureValues { get; set; }
}
Expand Down
16 changes: 16 additions & 0 deletions shopapp.core/DTOs/Concrete/ProductStockChange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace shopapp.core.DTOs.Concrete;

public class ProductStockChange
{
[JsonIgnore]
public int productId { get; set; }
[JsonIgnore]
public int quantity { get; set; }
}
14 changes: 8 additions & 6 deletions shopapp.core/DTOs/Concrete/UserDTO.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using shopapp.core.DTOs.Abstract;
using shopapp.core.Entity.Concrete;
using Microsoft.AspNetCore.Identity;

namespace shopapp.core.DTOs.Concrete
{
public class UserDTO : IDTO
public class UserDTO
{
public UserDTO()
{
this.Orders = new List<Order>();
this.Orders = new List<OrderDTO>();
}
public int Id { get; set; }
public List<Order> Orders { get; set; }
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserName { get; set; }
public List<OrderDTO> Orders { get; set; }
}
}
11 changes: 11 additions & 0 deletions shopapp.core/DataAccess/Abstract/IOrderRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using shopapp.core.Entity.Concrete;
using System.Linq.Expressions;

namespace shopapp.core.DataAccess.Abstract;

public interface IOrderRepository : IGenericRepository<Order>
{
IQueryable<Order> GetWhereWithProduct(Expression<Func<Order, bool>> filter);
IQueryable<Order> GetAllWithUser(Expression<Func<Order, bool>>? filter = null);
Task<Order> GetByIdWithUserAsync(int id);
}
36 changes: 31 additions & 5 deletions shopapp.core/Entity/Concrete/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,38 @@ public class Order : IEntity
{
public Order()
{
this.Products = new List<Product>();

}
this.OrderItems = new List<OrderItem>();
}
public int Id { get; set; }
public string UserId { get; set; } = null!;
public string OrderNumber { get; set; }
public EnumOrderState State { get; set; }
public DateTime OrderTime { get; set; }
public double TotalPrice { get; set; }
public User User { get; set; }
public List<Product> Products { get; set; }
public string UserId { get; set; } = null!;
public List<OrderItem> OrderItems { get; set; }

public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string CityState { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string? Note { get; set; }

public string PaymentId { get; set; }
public string ConversationId { get; set; }
public EnumPaymentType PaymentType { get; set; }
}

public enum EnumPaymentType
{
CreditCard=0,Eft=1
}

public enum EnumOrderState
{
HasbeenTaken=0,Waiting=1,Unpaid=2,GettingReady=3,InCargo=4,HasDelivered=5
}
}
15 changes: 15 additions & 0 deletions shopapp.core/Entity/Concrete/OrderItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using shopapp.core.Entity.Abstract;

namespace shopapp.core.Entity.Concrete;

public class OrderItem:IEntity
{
public int Id { get; set; }
public int OrderId { get; set; }
public Order Order { get; set; }
public int ProductId { get; set; }
public Product Product { get; set; }

public double Price { get; set; }
public int Quantity { get; set; }
}
16 changes: 16 additions & 0 deletions shopapp.core/Entity/Concrete/OrderProduct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shopapp.core.Entity.Concrete;

public class OrderProduct
{
public int OrderId { get; set; }
public Order Order { get; set; }
public int ProductId { get; set; }
public Product Product { get; set; }
public int Quantity { get; set; }
}
Loading

0 comments on commit ab41d4c

Please sign in to comment.