public List <ShoesViewModel> GetAll()
        {
            List <Shoes> lsShoes = _shoesRepository
                                   .GetAll()
                                   .Where(s => s.IsAvaiable == true)
                                   .Include(s => s.ShoesHasSize)
                                   .Include(a => a.Brand)
                                   .ToList();

            List <ShoesViewModel> lsShoesVM      = new List <ShoesViewModel>();
            ShoesViewModel        shoesVM        = null;
            ShoesHasSizeViewModel shoesHasSizeVM = null;

            foreach (var shoes in lsShoes)
            {
                shoesVM = new ShoesViewModel()
                {
                    Id          = shoes.Id,
                    BrandId     = shoes.BrandId,
                    BrandName   = shoes.Brand.Name,
                    Color       = shoes.Color,
                    IsAvaiable  = shoes.IsAvaiable,
                    Name        = shoes.Name,
                    Description = shoes.Description,
                    Price       = shoes.Price,
                    Sex         = shoes.Sex
                };

                foreach (var shs in shoes.ShoesHasSize)
                {
                    ShoesHasSize shoesHasSize = _shoesHasSizeRepository.GetAll()
                                                .Where(h => h.Id == shs.Id).Include(h => h.Size).FirstOrDefault();
                    shoesHasSizeVM = new ShoesHasSizeViewModel()
                    {
                        Id       = shoesHasSize.Id,
                        Quantity = shoesHasSize.Quantity,
                        Scale    = shoesHasSize.Size.Scale,
                        ShoesId  = shoesHasSize.ShoesId,
                        SizeId   = shoesHasSize.SizeId
                    };
                    shoesVM.ShoesHasSizes.Add(shoesHasSizeVM);
                }

                List <Image> images = _imageRepository.GetAll().Where(i => i.IsShoes == true && i.OwnId == shoes.Id).ToList();
                shoesVM.Images = images;
                lsShoesVM.Add(shoesVM);
            }
            return(lsShoesVM);
        }
        public ShoesHasSizeViewModel GetShoesHasSize(int id)
        {
            ShoesHasSize shs = _shoesHasSizeRepository.GetAll().Where(s => s.Id == id).Include(s => s.Shoes).Include(s => s.Size).FirstOrDefault();

            if (shs != null)
            {
                ShoesHasSizeViewModel shoesHasSizeVM = new ShoesHasSizeViewModel()
                {
                    Id        = shs.Id,
                    Quantity  = shs.Quantity,
                    Scale     = shs.Size.Scale,
                    ShoesId   = shs.ShoesId,
                    ShoesName = shs.Shoes.Name,
                    SizeId    = shs.SizeId
                };
                return(shoesHasSizeVM);
            }
            return(null);
        }
        public async Task <Order> CreateOrderAsync(OrderAddViewModel orderAddVM)
        {
            Order order = new Order()
            {
                ContactPhone = orderAddVM.ContactPhone,
                CreateDate   = DateTime.Now,
                CusName      = orderAddVM.CusName,
                Description  = orderAddVM.Description,
                ShipAddress  = orderAddVM.ShipAddress,
                ShipDate     = orderAddVM.ShipDate,
                State        = "pending",
                DiscountCode = orderAddVM.DiscountCode,
                Sum          = 0,
                Total        = 0
            };

            order = _orderRepository.Add(order);

            OrderDetail orderDetail = null;

            foreach (var odd in orderAddVM.OrderDetailAdds)
            {
                ShoesHasSize shoesHasSize = _shoesHasSizeRepository.GetAll()
                                            .Where(h => h.SizeId == odd.SizeId && h.ShoesId == odd.ShoesId).FirstOrDefault();
                if (shoesHasSize != null)
                {
                    if (shoesHasSize.Quantity >= odd.Quantity)
                    {
                        orderDetail = new OrderDetail()
                        {
                            OrderId  = order.Id,
                            Quantity = odd.Quantity,
                            ShoesId  = odd.ShoesId,
                            SizeId   = odd.SizeId
                        };

                        _orderDetailRepository.Add(orderDetail);

                        double price = _shoesRepository.GetById(odd.ShoesId.Value).Price.Value;
                        order.Sum             += price * odd.Quantity;
                        shoesHasSize.Quantity -= odd.Quantity.Value;
                        _shoesHasSizeRepository.Update(shoesHasSize);

                        if (shoesHasSize.Quantity == 0)
                        {
                            Shoes shoes = _shoesRepository.GetById(odd.ShoesId.Value);
                            shoes.IsAvaiable = false;
                            _shoesRepository.Update(shoes);
                        }
                    }
                }
            }

            order.Total = order.Sum;
            if (order.DiscountCode != "")
            {
                order.Discount = _promotionRepository.GetAll()
                                 .Where(p => p.DiscountCode == order.DiscountCode).FirstOrDefault().Discount;
                order.Total -= order.Sum * order.Discount / 100;
            }

            if (order.Total == 0)
            {
                _orderRepository.Delete(order);
                return(null);
            }
            else
            {
                order = _orderRepository.Update(order);
                OrderViewModel orderVM = _mapper.Map <OrderViewModel>(order);
                FirebaseSerivce <OrderViewModel> firebaseSerivce = new FirebaseSerivce <OrderViewModel>();
                await firebaseSerivce.SetDataAsync("orders", orderVM);
            }

            return(order);
        }