public virtual ActionResult Manage(TempOrderDetailSearchFilter filter)
 {
     if (!Request.IsAjaxRequest()) return View(_TempOrderDetailSrv.Get(filter));
     else return PartialView("Partials/_List", _TempOrderDetailSrv.Get(filter));
 }
Exemplo n.º 2
0
 public IActionResult Get(Guid basketId) => Json(_tempOrderDetailSrv.Get(basketId));
Exemplo n.º 3
0
        public async Task <IResponse <Order> > AddTempBasket(TempOrderDTO model)
        {
            var getItems = _tempOrderDetailSrv.Get(model.BasketId);

            if (!getItems.IsSuccessful)
            {
                return new Response <Order> {
                           Message = getItems.Message
                }
            }
            ;
            var productId = getItems.Result.Where(x => x.Count != 0).First().Id;
            var store     = await _appUow.ProductRepo.FirstOrDefaultAsync(x => new { x.StoreId, x.Store.AddressId }, x => x.ProductId == productId);

            if (store == null)
            {
                return new Response <Order> {
                           Message = ServiceMessage.RecordNotExist
                }
            }
            ;
            var address = await _appUow.AddressRepo.FindAsync(store.AddressId);

            if (address == null)
            {
                await _appUow.AddressRepo.FindAsync(store.AddressId);
            }
            var getDeliveryCost = await _deliverySrv.GetDeliveryCost(model.DeliveryId, store.StoreId, new LocationDTO { Lat = model.Address.Lat, Lng = model.Address.Lng });

            if (!getDeliveryCost.IsSuccessful)
            {
                return new Response <Order> {
                           Message = getDeliveryCost.Message
                }
            }
            ;
            var orderDetails = getItems.Result.Where(x => x.Count != 0).Select(i => new OrderDetail
            {
                ProductId       = i.Id,
                Count           = i.Count,
                Price           = i.Price,
                TotalPrice      = i.RealPrice * i.Count,
                DiscountPrice   = i.DiscountPrice,
                DiscountPercent = i.Discount
            }).ToList();
            var order = new Order
            {
                StoreId    = store.StoreId,
                TotalPrice = orderDetails.Sum(x => x.Price * x.Count),
                TotalPriceAfterDiscount = orderDetails.Sum(x => x.TotalPrice) + getDeliveryCost.Result,
                UserId             = model.UserToken,
                DiscountPrice      = orderDetails.Sum(x => x.DiscountPrice),
                OrderStatus        = OrderStatus.WaitForPayment,
                DeliveryProviderId = model.DeliveryId,
                OrderComment       = model.Description,
                UserComment        = new UserComment {
                    Reciever = model.Reciever, RecieverMobileNumber = model.RecieverMobileNumber
                }.SerializeToJson(),
                ToAddressId = model.Address.Id ?? 0,
                ToAddress   = model.Address.Id == null ? new Address
                {
                    UserId         = model.UserToken,
                    AddressType    = AddressType.Home,
                    Latitude       = model.Address.Lat,
                    Longitude      = model.Address.Lng,
                    AddressDetails = model.Address.Address
                } : null,
                FromAddressId = store.AddressId ?? 0,
                OrderDetails  = orderDetails
            };
            await _orderRepo.AddAsync(order);

            var addOrder = await _appUow.ElkSaveChangesAsync();

            if (!addOrder.IsSuccessful)
            {
                return new Response <Order> {
                           Message = addOrder.Message
                }
            }
            ;
            return(new Response <Order>
            {
                IsSuccessful = true,
                Result = order
            });
        }