Esempio n. 1
0
        public static bool DoesUserExists(UserLoginDetails userLoginDetails)
        {
            bool found;

            using (marketContext = new MarketContext())
            {
                var user = marketContext.Users.Where(u => (u.Email == userLoginDetails.UserEmail) && (u.Password == userLoginDetails.UserPassword)).FirstOrDefault();
                found = user != null ? true : false;
            }
            return(found);
        }
Esempio n. 2
0
        public ProductDetails  AddProduct(ProductDetails productDetails)
        {
            ProductDetails productAdded;

            using (marketContext = new MarketContext())
            {
                productAdded = marketContext.Products.Add(productDetails);
                marketContext.SaveChanges();
            }
            return(productAdded);
        }
Esempio n. 3
0
        public static UserDetails AddUser(UserDetails userDetails)
        {
            UserDetails user;

            using (marketContext = new MarketContext())
            {
                user = marketContext.Users.Add(userDetails);
                marketContext.SaveChanges();
            }
            return(user);
        }
Esempio n. 4
0
        public static ProductDetails GetProduct(int id)
        {
            ProductDetails product = null;

            using (var context = new MarketContext())
            {
                product = context.Products
                          .Where(x => x.ProductId == id)
                          .FirstOrDefault();
            }
            return(product);
        }
Esempio n. 5
0
        public static List <ProductCategory> GetProductCategories()
        {
            List <ProductCategory> productCategories = null;

            using (var context = new MarketContext())
            {
                productCategories = context.ProductCategories.ToList <ProductCategory>();
            }
            if (productCategories == null || productCategories.Count == 0)
            {
                return(null);
            }
            return(productCategories);
        }
Esempio n. 6
0
        public static List <ProductDTO> GetAllProducts()
        {
            List <ProductDTO> allProducts;

            using (marketContext = new MarketContext())
            {
                allProducts = marketContext.Products.Where(product => product.ProductId != null).Select(product => new ProductDTO()
                {
                    ProductId          = product.ProductId,
                    ProductCategory    = product.ProductCategory,
                    ProductModelName   = product.ProductModelName,
                    ProductDescription = product.ProductDescription
                }).ToList();
            }
            return(allProducts);
        }
Esempio n. 7
0
        public static void AddProduct(MultipartFormDataStreamProvider provider)
        {
            var    model = provider.FormData["product"];
            var    jsonObj = JObject.Parse(model);
            var    product = JsonConvert.DeserializeObject <ProductDetails>(jsonObj.ToString());
            string filename = String.Empty, filepath = String.Empty;

            foreach (MultipartFileData file in provider.FileData)
            {
                filename = file.Headers.ContentDisposition.FileName;
                filepath = file.LocalFileName;
            }
            product.ProductImageFile = File.ReadAllBytes(filepath);
            product.ProductFileName  = filename;
            using (marketContext = new MarketContext())
            {
                var stud = product;
                marketContext.Products.Add(product);
                marketContext.SaveChanges();
            }
            File.Delete(filepath);
        }