Ejemplo n.º 1
0
        public async Task <IDataResult <List <Order> > > GetListByUserId(int userId)
        {
            List <Order> orders = await _orderDAL.GetListAsync(x => x.UserId == userId, x => x.Address);

            orders = orders.OrderBy(o => o.OrderStatus).OrderByDescending(o => o.OrderDate).ToList();
            return(ResultHelper <List <Order> > .DataResultReturn(orders));
        }
Ejemplo n.º 2
0
        public async Task <IDataResult <List <Order> > > GetListAsync()
        {
            DateTime     oneMonthAgo = DateTime.Now.AddMonths(-1);
            List <Order> orders      = await _orderDAL.GetListAsync(x => x.OrderDate >= oneMonthAgo, x => x.User);

            return(ResultHelper <List <Order> > .DataResultReturn(orders));
        }
Ejemplo n.º 3
0
        public async Task <IDataResult <CartDTO> > GetCart()
        {
            string key       = _httpContextAccessor.HttpContext.Request.Cookies["key"]?.ToString() ?? "";
            string existCart = await _redisManager.GetDb().StringGetAsync(key);

            CartDTO cart = string.IsNullOrEmpty(existCart) ? null : JsonSerializer.Deserialize <CartDTO>(existCart);

            return(ResultHelper <CartDTO> .DataResultReturn(cart));
        }
Ejemplo n.º 4
0
        public async Task <IDataResult <CartDTO> > AddToCart(AddToCartDTO model)
        {
            var key = _httpContextAccessor.HttpContext.Request.Cookies["key"]?.ToString() ?? Guid.NewGuid().ToString();

            string existCart = await _redisManager.GetDb().StringGetAsync(key);

            CartDTO cart;

            if (!string.IsNullOrEmpty(existCart))
            {
                cart = JsonSerializer.Deserialize <CartDTO>(existCart);
            }
            else
            {
                cart = new CartDTO();
            }

            //! Sepette indirim etkinliğini bu satırda kontrol et ve cart'ta ki indirime apply et

            var existCartItem = cart.CartItems.FirstOrDefault(x => x.ProductId == model.ProductId && x.DemandTypes.SequenceEqual(model.DemandTypes));

            if (existCartItem != null)
            {
                cart.CartItems.Remove(existCartItem);
                existCartItem.Quantity += model.Quantity;
                cart.CartItems.Add(existCartItem);
            }
            else
            {
                var product = (await _productService.GetByIdAsync(model.ProductId)).Data;
                product.ProductDemands = null;
                CartItemDTO cartModel = CartHelper.NewCartItem(product, model);
                cart.CartItems.Add(cartModel);
            }

            TimeSpan expireCart = TimeSpan.FromMinutes(1);
            var      status     = await _redisManager.GetDb().StringSetAsync(key, JsonSerializer.Serialize(cart), expireCart);

            if (!status)
            {
                cart = null;
            }
            else
            {
                _httpContextAccessor.HttpContext.Response.Cookies.Append("key", key, new CookieOptions
                {
                    Expires  = DateTime.Now + expireCart,
                    HttpOnly = true,
                    SameSite = SameSiteMode.Lax,
                    Secure   = true
                });
            }
            return(ResultHelper <CartDTO> .DataResultReturn(cart));
        }
Ejemplo n.º 5
0
        public async Task <IDataResult <List <Event> > > GetActiveEventsAsync()
        {
            List <Event> events = await _eventDAL.GetListAsync(x => x.EndDate >= DateTime.Now);

            return(ResultHelper <List <Event> > .DataResultReturn(events));
        }
Ejemplo n.º 6
0
        public async Task <IDataResult <Product> > GetProductWithDemandAsync(int productId)
        {
            Product product = await _productDAL.GetProductWithDemands(productId);

            return(ResultHelper <Product> .DataResultReturn(product));
        }
Ejemplo n.º 7
0
        public async Task <IDataResult <List <OrderDetail> > > GetOrderDetail(int orderId)
        {
            List <OrderDetail> orderDetails = await _orderDetailDAL.GetOrderDetailWithDemands(orderId);

            return(ResultHelper <List <OrderDetail> > .DataResultReturn(orderDetails));
        }
Ejemplo n.º 8
0
        public async Task <IDataResult <List <DemandType> > > GetListAsync()
        {
            var demandTypes = await _demandTypeDAL.GetListAsync(null, x => x.Demands);

            return(ResultHelper <List <DemandType> > .DataResultReturn(demandTypes));
        }