Пример #1
0
 public CartDTO UpdateCart(CartItemDTO cart)
 {
     using (var dbContext = new OMHRDModel())
     {
         var cartItem = dbContext.Cart_T.FirstOrDefault(x => x.ProductId == cart.ProductId && x.UserId == cart.UserId && x.SizeId == cart.SizeId && (!x.ColorId.HasValue || x.ColorId.Value == cart.ColorId.Value));
         if (cartItem != null)
         {
             cartItem.Quantity = cart.IsQuantityForAddition ? cartItem.Quantity + cart.Quantity : cart.Quantity;
             dbContext.SaveChanges();
         }
         else
         {
             cartItem = new Cart_T()
             {
                 ProductId = cart.ProductId,
                 ColorId   = cart.ColorId,
                 SizeId    = cart.SizeId,
                 Quantity  = cart.Quantity,
                 UserId    = cart.UserId
             };
             dbContext.Cart_T.Add(cartItem);
             dbContext.SaveChanges();
         }
         return(GetCartTotal(cart.UserId));
     }
 }
Пример #2
0
        public List <CartItemDTO> GetCartItems(int userId)
        {
            using (var dbContext = new OMHRDModel())
            {
                var cartItems = (from cart in dbContext.Cart_T
                                 join price in dbContext.ProductPrice_T on new { ProductId = cart.ProductId, SizeId = cart.SizeId, ColorId = cart.ColorId } equals new { price.ProductId, SizeId = price.ProductSizeId, ColorId = price.ProductColorId }
                                 join prodcut in dbContext.Product_T on cart.ProductId equals prodcut.Id
                                 where cart.UserId == userId
                                 select new CartItemDTO
                {
                    Id = cart.Id,
                    ColorId = cart.ColorId,
                    ColorName = cart.ColorId.HasValue ? cart.ProductColor_T.Name : "",
                    ColorCode = cart.ColorId.HasValue ? cart.ProductColor_T.Code : "",
                    Price = price.Price - price.Discount,
                    Discount = price.Discount,
                    ProductId = prodcut.Id,
                    ProductName = prodcut.Name,
                    Quantity = cart.Quantity,
                    SizeId = cart.SizeId,
                    SizeName = cart.ProductSize_T.Name,
                    SizeCode = cart.ProductSize_T.Code,
                    UserId = userId
                }).ToList();

                return(cartItems);
            }
        }
Пример #3
0
 public UserProfile_T Login(string username, string password)
 {
     using (var dbContext = new OMHRDModel())
     {
         return(dbContext.UserProfile_T.FirstOrDefault(x => x.Username.ToLower() == username.ToLower() && x.Password == password));
     }
 }
Пример #4
0
        public ProductDTO GetProductById(int productId)
        {
            using (dbContext = new OMHRDModel())
            {
                using (dbContext = new OMHRDModel())
                {
                    var product = dbContext.Product_T.Where(x => (x.Id == productId))
                                  .Select(x => new ProductDTO
                    {
                        Id               = x.Id,
                        Code             = x.Code,
                        Name             = x.Name,
                        HSN              = x.HSN,
                        ShortDescription = x.Description,
                        Description      = x.Description,
                        PriceList        = x.ProductPrice_T.Select(y => new ProductPriceDTO
                        {
                            Id        = y.Id,
                            Price     = y.Price,
                            Discount  = y.Discount,
                            Quantity  = y.Quantity,
                            SizeId    = y.ProductSizeId,
                            SizeCode  = y.ProductSize_T.Code,
                            SizeName  = y.ProductSize_T.Name,
                            ColorId   = y.ProductColorId,
                            ColorCode = y.ProductColorId != null ? y.ProductColor_T.Code : string.Empty,
                            ColorName = y.ProductColorId != null ? y.ProductColor_T.Name : string.Empty
                        }).ToList()
                    }).FirstOrDefault();

                    return(product);
                }
            }
        }
Пример #5
0
        public List <ProductDTO> GetProducts(ProductSearchDTO searchDto)
        {
            using (dbContext = new OMHRDModel())
            {
                var products = dbContext.Product_T.Where(x => (searchDto.SubCategoryId == 0 || x.SubCategoryId == searchDto.SubCategoryId) && (searchDto.CategoryId == 0 || x.ProductSubCategory_T.CategoryId == searchDto.CategoryId))
                               .Select(x => new ProductDTO
                {
                    Id               = x.Id,
                    Code             = x.Code,
                    Name             = x.Name,
                    HSN              = x.HSN,
                    ShortDescription = x.Description,
                    Description      = x.Description,
                    PriceList        = x.ProductPrice_T.Select(y => new ProductPriceDTO
                    {
                        Price     = y.Price,
                        Discount  = y.Discount,
                        Quantity  = y.Quantity,
                        SizeId    = y.ProductSizeId,
                        SizeCode  = y.ProductSize_T.Code,
                        ColorId   = y.ProductColorId,
                        ColorCode = y.ProductColorId == null ? y.ProductColor_T.Code : string.Empty
                    }).ToList()
                }).ToList();

                return(products);
            }
        }
Пример #6
0
 public int InsertCart(Cart_T cart)
 {
     using (var dbContext = new OMHRDModel())
     {
         dbContext.Cart_T.Add(cart);
         return(dbContext.SaveChanges());
     }
 }
Пример #7
0
 public int Register(UserProfile_T user)
 {
     using (var dbContext = new OMHRDModel())
     {
         dbContext.UserProfile_T.Add(user);
         return(dbContext.SaveChanges());
     }
 }
Пример #8
0
        public CartDTO GetCartTotal(int userId)
        {
            using (var dbContext = new OMHRDModel())
            {
                var cartItems = (from cartDB in dbContext.Cart_T
                                 join price in dbContext.ProductPrice_T on new { ProductId = cartDB.ProductId, SizeId = cartDB.SizeId, ColorId = cartDB.ColorId } equals new { price.ProductId, SizeId = price.ProductSizeId, ColorId = price.ProductColorId }
                                 join prodcut in dbContext.Product_T on cartDB.ProductId equals prodcut.Id
                                 where cartDB.UserId == cartDB.UserId
                                 select new
                {
                    Price = (price.Price - price.Discount) * cartDB.Quantity,
                    Quantity = cartDB.Quantity
                });

                return(new CartDTO {
                    TotalPrice = cartItems.Sum(x => x.Price), Quantity = cartItems.Sum(x => x.Quantity)
                });
            }
        }