Example #1
0
        public async Task <IActionResult> clearCart()
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var cartVm = await _cartApiClient.GetCartByUser(userId);

            var orderVm = await _orderApiClient.GetOrderByUser(userId);

            var     lstProduct  = new List <OrderDetailVm>();
            OrderVm od          = new();
            int     y           = orderVm.Count();
            var     lstCartItem = cartVm.cartItemVms.ToList();

            if (lstCartItem.Count > 0)
            {
                foreach (var x in lstCartItem)
                {
                    var pVm = new OrderDetailVm()
                    {
                    };
                    pVm.ProductId = x.productVm.Id;
                    pVm.Quantity  = x.Quantity;
                    pVm.UnitPrice = x.productVm.Price;
                    pVm.OrderId   = y + 1;

                    lstProduct.Add(pVm);
                }
                ;
            }
            await _cartApiClient.clearCart(userId);

            await _orderApiClient.CreateOrder(userId, lstProduct);

            return(RedirectToAction("Index", "Order"));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("OrderId,ProductId,Quantity,Price,Vat,Notes")] OrderDetailVm orderDetail)
        {
            if (id != orderDetail.OrderId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _orderDetailMapper.BlUpdateAsync(orderDetail);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderDetailExists(orderDetail.OrderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            //var ord = _orderMapper.BlGetAllOrder();
            //ViewData["OrderId"] = new SelectList(ord, "OrderId", "Article", orderDetail.OrderId);
            var prod = _productMapper.BlGetAllProduct();

            ViewData["ProductId"] = new SelectList(prod, "ProductId", "Article", orderDetail.ProductId);
            return(View(orderDetail));
        }
Example #3
0
        public async Task <ActionResult <OrderVm> > GetOrderById(int id)
        {
            var order = await _context.Orders.Include(x => x.OrderDetails).FirstOrDefaultAsync(x => x.Id == id);

            if (order == null)
            {
                return(NotFound());
            }
            List <OrderDetailVm> listOrderDetail = new();

            foreach (var oddt in order.OrderDetails)
            {
                var oddtVm = new OrderDetailVm
                {
                    ProductId = oddt.ProductId,
                    Quantity  = oddt.Quantity,
                    UnitPrice = oddt.UnitPrice,
                };
                listOrderDetail.Add(oddtVm);
            }
            var orderVm = new OrderVm
            {
                Status         = order.Status,
                Id             = order.Id,
                CraeteDate     = order.CraeteDate,
                UserId         = order.UserId,
                TotalPrice     = order.TotalPrice,
                orderDetailVms = listOrderDetail
            };

            return(orderVm);
        }
        public async Task <IActionResult> Get(long id)
        {
            var order = _orderRepository
                        .Query()
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.District)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.Country)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option)
                        .Include(x => x.CreatedBy)
                        .FirstOrDefault(x => x.Id == id);

            if (order == null)
            {
                return(new NotFoundResult());
            }

            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId)
            {
                return(new BadRequestObjectResult(new { error = "You don't have permission to manage this order" }));
            }

            var model = new OrderDetailVm
            {
                Id                   = order.Id,
                CreatedOn            = order.CreatedOn,
                OrderStatus          = (int)order.OrderStatus,
                OrderStatusString    = order.OrderStatus.ToString(),
                CustomerName         = order.CreatedBy.FullName,
                Subtotal             = order.SubTotal,
                Discount             = order.Discount,
                SubTotalWithDiscount = order.SubTotalWithDiscount,
                ShippingAddress      = new ShippingAddressVm
                {
                    AddressLine1        = order.ShippingAddress.AddressLine1,
                    AddressLine2        = order.ShippingAddress.AddressLine2,
                    ContactName         = order.ShippingAddress.ContactName,
                    DistrictName        = order.ShippingAddress.District?.Name,
                    StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name,
                    Phone = order.ShippingAddress.Phone
                },
                OrderItems = order.OrderItems.Select(x => new OrderItemVm
                {
                    Id               = x.Id,
                    ProductName      = x.Product.Name,
                    ProductPrice     = x.ProductPrice,
                    ProductImage     = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage),
                    Quantity         = x.Quantity,
                    VariationOptions = OrderItemVm.GetVariationOption(x.Product)
                }).ToList()
            };

            return(Json(model));
        }
        public async Task <IActionResult> UpdateOrderdetail(int id, OrderDetailVm orderDetailVm)
        {
            var orderDetail = await _context.OrderDetails.FindAsync(id);

            if (orderDetail == null)
            {
                return(NotFound());
            }

            orderDetail.Quantity  = orderDetailVm.Quantity;
            orderDetail.UnitPrice = orderDetailVm.UnitPrice;

            await _context.SaveChangesAsync();

            return(Accepted());
        }
Example #6
0
        public IActionResult Get(long id)
        {
            var order = _orderRepository
                        .Query()
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.Address).ThenInclude(x => x.District).ThenInclude(x => x.StateOrProvince)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option)
                        .Include(x => x.CreatedBy)
                        .FirstOrDefault(x => x.Id == id);

            if (order == null)
            {
                return(new NotFoundResult());
            }

            var model = new OrderDetailVm
            {
                Id                = order.Id,
                CreatedOn         = order.CreatedOn,
                OrderStatus       = (int)order.OrderStatus,
                OrderStatusString = order.OrderStatus.ToString(),
                CustomerName      = order.CreatedBy.FullName,
                SubTotal          = order.SubTotal,
                ShippingAddress   = new ShippingAddressVm
                {
                    AddressLine1        = order.ShippingAddress.Address.AddressLine1,
                    AddressLine2        = order.ShippingAddress.Address.AddressLine2,
                    ContactName         = order.ShippingAddress.Address.ContactName,
                    DistrictName        = order.ShippingAddress.Address.District.Name,
                    StateOrProvinceName = order.ShippingAddress.Address.StateOrProvince.Name,
                    Phone = order.ShippingAddress.Address.Phone
                },

                OrderItems = order.OrderItems.Select(x => new OrderItemVm
                {
                    Id               = x.Id,
                    ProductName      = x.Product.Name,
                    ProductPrice     = x.ProductPrice,
                    ProductImage     = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage),
                    Quantity         = x.Quantity,
                    VariationOptions = OrderItemVm.GetVariationOption(x.Product)
                }).ToList()
            };

            return(Json(model));
        }
        public async Task <IActionResult> Create([Bind("ProductId,Quantity,Price,Vat,Notes,OrdersVm")] OrderDetailVm orderDetail)
        {
            if (ModelState.IsValid)
            {
                await _OrderMapper.BlInser(orderDetail.OrdersVm);

                await _orderDetailMapper.BlInser(orderDetail);

                return(RedirectToAction(nameof(Index)));
            }
            var cust = _customerMapper.BlGetAllCustomer();

            ViewData["CustomerId"] = new SelectList(cust, "CustomerId", "FullName");
            var prod = _productMapper.BlGetAllProduct();

            ViewData["ProductId"] = new SelectList(prod, "ProductId", "Article");
            return(View(orderDetail));
        }
        public async Task <ActionResult <OrderDetailVm> > GetOrderdetailById(int id)
        {
            var order = await _context.OrderDetails.FindAsync(id);

            if (order == null)
            {
                return(NotFound());
            }

            var orderDetailVm = new OrderDetailVm
            {
                Id        = order.Id,
                OrderId   = order.OrderId,
                Quantity  = order.Quantity,
                UnitPrice = order.UnitPrice
            };

            return(orderDetailVm);
        }
Example #9
0
        public async Task <IEnumerable <OrderVm> > GetOrderByUser(string userId)
        {
            //var order = await _context.Orders.Include(o => o.OrderDetails).Where(x => x.UserId == userId)
            //   .FirstOrDefaultAsync();
            var order1 = await _context.Orders.Include(o => o.OrderDetails).Where(x => x.UserId == userId)
                         .ToListAsync();

            //List<OrderVm> orderVms = new();

            List <OrderDetailVm> orderDetailVms = new();
            List <OrderVm>       lstOrder       = new ();

            foreach (var order in order1)
            {
                foreach (var od in order.OrderDetails.ToList())
                {
                    var orderDetailVm = new OrderDetailVm
                    {
                        Id        = od.Id,
                        OrderId   = od.OrderId,
                        ProductId = od.ProductId,
                        Quantity  = od.Quantity,
                        UnitPrice = od.UnitPrice
                    };
                    orderDetailVms.Add(orderDetailVm);
                }
                var orderVm = new OrderVm
                {
                    Status         = order.Status,
                    Id             = order.Id,
                    CraeteDate     = order.CraeteDate,
                    UserId         = order.UserId,
                    TotalPrice     = order.TotalPrice,
                    orderDetailVms = orderDetailVms
                };
                lstOrder.Add(orderVm);
            }
            //    orderVms.Add(orderVm);


            return(lstOrder);
        }
        public async Task <ActionResult <OrderDetailVm> > GetOrderdetailByOrder(int orderId)
        {
            var orderdetail = await _context.OrderDetails.FirstOrDefaultAsync(x => x.OrderId == orderId);

            if (orderdetail == null)
            {
                return(NotFound());
            }
            var p        = orderdetail.Product;
            var products = await _context.Products.Include(p => p.Images).ToListAsync();

            var pVm = new ProductVm
            {
                Price = p.Price,

                CategoryId = p.CategoryId,

                Description   = p.Description,
                Id            = p.Id,
                ImageLocation = new List <string>(),
                Inventory     = p.Inventory,
                Name          = p.Name,
            };

            for (int i = 0; i < p.Images.Count; i++)
            {
                pVm.ImageLocation.Add(p.Images.ElementAt(i).ImagePath);
            }


            var orderDetailVm = new OrderDetailVm
            {
                Id        = orderdetail.Id,
                OrderId   = orderdetail.OrderId,
                Quantity  = orderdetail.Quantity,
                UnitPrice = orderdetail.UnitPrice,
            };

            return(orderDetailVm);
        }
Example #11
0
        public async Task <IActionResult> Print(long id)
        {
            var order = await _orderRepository
                        .Query()
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.District)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.Country)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option)
                        .Include(x => x.CreatedBy)
                        .FirstOrDefaultAsync(x => x.Id == id);

            if (order == null)
            {
                return(NotFound());
            }

            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId)
            {
                return(BadRequest(new { error = "You don't have permission to manage this order" }));
            }

            var model = new OrderDetailVm
            {
                Id                   = order.Id,
                CreatedOn            = order.CreatedOn,
                OrderStatus          = (int)order.OrderStatus,
                OrderStatusString    = order.OrderStatus.ToString(),
                CustomerId           = order.CreatedById,
                CustomerName         = order.CreatedBy.FullName,
                CustomerEmail        = order.CreatedBy.Email,
                ShippingMethod       = order.ShippingMethod,
                PaymentMethod        = order.PaymentMethod,
                PaymentFeeAmount     = order.PaymentFeeAmount,
                Subtotal             = order.SubTotal,
                DiscountAmount       = order.DiscountAmount,
                SubTotalWithDiscount = order.SubTotalWithDiscount,
                TaxAmount            = order.TaxAmount,
                ShippingAmount       = order.ShippingFeeAmount,
                OrderTotal           = order.OrderTotal,
                ShippingAddress      = new ShippingAddressVm
                {
                    AddressLine1        = order.ShippingAddress.AddressLine1,
                    AddressLine2        = order.ShippingAddress.AddressLine2,
                    ContactName         = order.ShippingAddress.ContactName,
                    DistrictName        = order.ShippingAddress.District?.Name,
                    StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name,
                    Phone = order.ShippingAddress.Phone
                },
                OrderItems = order.OrderItems.Select(x => new OrderItemVm
                {
                    Id               = x.Id,
                    ProductId        = x.Product.Id,
                    ProductName      = x.Product.Name,
                    ProductPrice     = x.ProductPrice,
                    Quantity         = x.Quantity,
                    DiscountAmount   = x.DiscountAmount,
                    TaxAmount        = x.TaxAmount,
                    TaxPercent       = x.TaxPercent,
                    VariationOptions = OrderItemVm.GetVariationOption(x.Product)
                }).ToList()
            };

            var invoiceHtml = await _viewRender.RenderViewToStringAsync("/Modules/SimplCommerce.Module.Orders/Views/Shared/InvoicePdf.cshtml", model);

            byte[] pdf = _pdfConverter.Convert(invoiceHtml);
            return(new FileContentResult(pdf, "application/pdf"));
        }
Example #12
0
        public async Task <IActionResult> Get(long id)
        {
            var order = _orderRepository
                        .Query()
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.District)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.Country)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option)
                        .Include(x => x.CreatedBy)
                        .FirstOrDefault(x => x.Id == id);

            if (order == null)
            {
                return(NotFound());
            }

            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin") && order.VendorId != currentUser.VendorId)
            {
                return(BadRequest(new { error = "You don't have permission to manage this order" }));
            }

            var model = new OrderDetailVm
            {
                Id                   = order.Id,
                IsMasterOrder        = order.IsMasterOrder,
                CreatedOn            = order.CreatedOn,
                OrderStatus          = (int)order.OrderStatus,
                OrderStatusString    = order.OrderStatus.ToString(),
                CustomerId           = order.CreatedById,
                CustomerName         = order.CreatedBy.FullName,
                CustomerEmail        = order.CreatedBy.Email,
                ShippingMethod       = order.ShippingMethod,
                PaymentMethod        = order.PaymentMethod,
                PaymentFeeAmount     = order.PaymentFeeAmount,
                Subtotal             = order.SubTotal,
                DiscountAmount       = order.DiscountAmount,
                SubTotalWithDiscount = order.SubTotalWithDiscount,
                TaxAmount            = order.TaxAmount,
                ShippingAmount       = order.ShippingFeeAmount,
                OrderTotal           = order.OrderTotal,
                ShippingAddress      = new ShippingAddressVm
                {
                    AddressLine1        = order.ShippingAddress.AddressLine1,
                    AddressLine2        = order.ShippingAddress.AddressLine2,
                    ContactName         = order.ShippingAddress.ContactName,
                    DistrictName        = order.ShippingAddress.District?.Name,
                    StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name,
                    Phone = order.ShippingAddress.Phone
                },
                OrderItems = order.OrderItems.Select(x => new OrderItemVm
                {
                    Id               = x.Id,
                    ProductId        = x.Product.Id,
                    ProductName      = x.Product.Name,
                    ProductPrice     = x.ProductPrice,
                    Quantity         = x.Quantity,
                    DiscountAmount   = x.DiscountAmount,
                    TaxAmount        = x.TaxAmount,
                    TaxPercent       = x.TaxPercent,
                    VariationOptions = OrderItemVm.GetVariationOption(x.Product)
                }).ToList()
            };

            if (order.IsMasterOrder)
            {
                model.SubOrderIds = _orderRepository.Query().Where(x => x.ParentId == order.Id).Select(x => x.Id).ToList();
            }

            await _mediator.Publish(new OrderDetailGot { OrderDetailVm = model });

            return(Json(model));
        }
Example #13
0
 public void Setup()
 {
     _mockOrdersRepository = new Mock <IOrdersRepository>();
     _mockOrdersFactory    = new Mock <IOrdersFactory>();
     _mockLogger           = new Mock <ILogger <OrdersController> >();
     _mockOrdersService    = new Mock <IOrdersService>();
     _mockStockService     = new Mock <IStockService>();
     _ordersController     = new OrdersController(_mockOrdersRepository.Object, _mockOrdersFactory.Object, _mockLogger.Object, _mockStockService.Object);
     _stubPurchaseOrderDto = new PurchaseOrderDto
     {
         Address            = "MockAddress",
         ExternalID         = 1,
         ID                 = Guid.NewGuid(),
         IsDeleted          = false,
         PaymentInformation = new PaymentInformationDto
         {
             ID         = Guid.NewGuid(),
             CardCVC    = "121",
             CardExpiry = new DateTime(),
             CardName   = "MockOli",
             CardNumber = "1234567890123456"
         },
         Postcode       = "T35T TST",
         ProductID      = Guid.NewGuid(),
         ProductName    = "Testy Producty",
         ProductPrice   = 50.55,
         PurchasedBy    = Guid.NewGuid(),
         PurchasedOn    = new DateTime(),
         PurchaseStatus = new PurchaseStatusDto
         {
             Id   = Guid.NewGuid(),
             Name = "Ordered"
         },
         Quantity = 2,
         Source   = "Undercutters",
     };
     _stubOrderCreatedDto = new OrderCreatedDto
     {
         Success = true,
     };
     _stubOrderFailedToCreateDto = new OrderCreatedDto
     {
         Success = false
     };
     _stubOrderListItem = new OrderListItemVm
     {
         Id          = Guid.NewGuid(),
         OrderStatus = "Ordered",
         Price       = 10.100,
         ProductName = "Test Product",
         Quantity    = 5
     };
     _stubOrderListList = new List <OrderListItemVm>();
     _stubOrderListList.Add(_stubOrderListItem);
     _stubOrderList = new OrderListVm
     {
         Orders = _stubOrderListList
     };
     _stubOrderDetailVm = new OrderDetailVm
     {
         OrderPrice     = 10,
         Address        = "Test",
         CardholderName = "Oli",
         Id             = Guid.NewGuid(),
         Last4Digits    = "123",
         Postcode       = "TSE3 231",
         ProductId      = Guid.NewGuid(),
         ProductName    = "Test",
         ProductPrice   = 5.99,
         PurchasedOn    = new DateTime(),
         PurchaseStatus = "Purchased",
         Quantity       = 5,
         Source         = "Undercutters"
     };
 }
Example #14
0
        public async Task <IActionResult> OrderDetails(long orderId)
        {
            var user = await _workContext.GetCurrentUser();

            var order = _orderRepository
                        .Query()
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.District)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.StateOrProvince)
                        .Include(x => x.ShippingAddress).ThenInclude(x => x.Country)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage)
                        .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option)
                        .Include(x => x.Customer)
                        .FirstOrDefault(x => x.Id == orderId);

            if (order == null)
            {
                return(NotFound());
            }

            if (order.CustomerId != user.Id)
            {
                return(BadRequest(new { error = "You don't have permission to view this order" }));
            }

            var model = new OrderDetailVm(_currencyService)
            {
                Id                   = order.Id,
                IsMasterOrder        = order.IsMasterOrder,
                CreatedOn            = order.CreatedOn,
                OrderStatus          = (int)order.OrderStatus,
                OrderStatusString    = order.OrderStatus.ToString(),
                CustomerId           = order.CustomerId,
                CustomerName         = order.Customer.FullName,
                CustomerEmail        = order.Customer.Email,
                ShippingMethod       = order.ShippingMethod,
                PaymentMethod        = order.PaymentMethod,
                PaymentFeeAmount     = order.PaymentFeeAmount,
                Subtotal             = order.SubTotal,
                DiscountAmount       = order.DiscountAmount,
                SubTotalWithDiscount = order.SubTotalWithDiscount,
                TaxAmount            = order.TaxAmount,
                ShippingAmount       = order.ShippingFeeAmount,
                OrderTotal           = order.OrderTotal,
                OrderNote            = order.OrderNote,
                ShippingAddress      = new ShippingAddressVm
                {
                    AddressLine1        = order.ShippingAddress.AddressLine1,
                    CityName            = order.ShippingAddress.City,
                    ZipCode             = order.ShippingAddress.ZipCode,
                    ContactName         = order.ShippingAddress.ContactName,
                    DistrictName        = order.ShippingAddress.District?.Name,
                    StateOrProvinceName = order.ShippingAddress.StateOrProvince.Name,
                    Phone = order.ShippingAddress.Phone
                },
                OrderItems = order.OrderItems.Select(x => new OrderItemVm(_currencyService)
                {
                    Id               = x.Id,
                    ProductId        = x.Product.Id,
                    ProductName      = x.Product.Name,
                    ProductPrice     = x.ProductPrice,
                    Quantity         = x.Quantity,
                    DiscountAmount   = x.DiscountAmount,
                    ProductImage     = x.Product.ThumbnailImage.FileName,
                    TaxAmount        = x.TaxAmount,
                    TaxPercent       = x.TaxPercent,
                    VariationOptions = OrderItemVm.GetVariationOption(x.Product)
                }).ToList()
            };

            foreach (var item in model.OrderItems)
            {
                item.ProductImage = _mediaService.GetMediaUrl(item.ProductImage);
            }

            return(View(model));
        }
Example #15
0
 public async Task BlUpdateAsync(OrderDetailVm OrderDetail)
 {
     var editMap = Mapper.Map <OrderDetailVm, OrderDetail>(OrderDetail);
     await _OrderDetailRepository.UpdateAsync(editMap);
 }
Example #16
0
 public async Task BlInser(OrderDetailVm OrderDetail)
 {
     var addMap = Mapper.Map <OrderDetailVm, OrderDetail>(OrderDetail);
     await _OrderDetailRepository.InsertAsync(addMap);
 }