Example #1
0
 public ProductDB GetProductByModelNumber(string modelNumber)
 {
     using (var context = new ECommerceDB())
     {
         return(context.productDB.FirstOrDefault(x => x.ModelNumber == modelNumber));
     }
 }
Example #2
0
 public void CreateNewUser(RegisterDB register)
 {
     using (var context = new ECommerceDB())
     {
         context.registerDB.Add(register);
         context.SaveChanges();
     }
 }
Example #3
0
 public List <RegisterDB> GetRegisteredUsersList()
 {
     using (var context = new ECommerceDB())
     {
         var listOfUsers = context.registerDB.ToList();
         return(listOfUsers);
     }
 }
Example #4
0
        public bool CheckUserProductListDb(string email)
        {
            using (var context = new ECommerceDB())
            {
                if (context.userProductDBModels.Any(x => x.Email == email))
                {
                    return(true);
                }

                return(false);
            }
        }
Example #5
0
        public ActionResult Index(int?id)
        {
            int       currentPage  = (id.HasValue) ? id.Value : 1; // shorter version of if/else - turnary operator, ?:
            const int ProdsPerPage = 2;

            ECommerceDB    db    = new ECommerceDB();
            List <Product> prods = db.Products.OrderBy(p => p.Name).Skip((currentPage - 1) * ProdsPerPage).Take(ProdsPerPage).ToList();

            //cast to avoid integer division, & round up to nearest whole number
            ViewBag.MaxPage     = Math.Ceiling(db.Products.Count() / (double)ProdsPerPage);
            ViewBag.CurrentPage = currentPage;
            return(View(prods));
        }
Example #6
0
 public ActionResult Edit(int id)
 {
     using (var db = new ECommerceDB())
     {
         var category = db.ProductCategories.FirstOrDefault(x => x.Id == id);
         var model    = new ViewModels.ProductCategoryEditViewModel
         {
             CategoryId = category.Id,
             Name       = category.Name
         };
         return(View(model));
     }
 }
        // GET: Category

        public ActionResult Index()
        {
            var model = new ProductCategoryViewModel();

            using (var db = new ECommerceDB())
            {
                model.CategoriesList.AddRange(db.ProductCategories.Select(x => new ProductCategoryViewModel.CategoryListViewModel
                {
                    CategoryId = x.Id,
                    Name       = x.Name
                }));

                return(View(model));
            }
        }
Example #8
0
        public AddressDB GetBillingAddress(AddressDTO addressDTO)
        {
            var addressDB = new AddressDB();

            using (var context = new ECommerceDB())
            {
                if (context.addressDB.Any(x => x.Email == addressDTO.Email))
                {
                    return(context.addressDB.FirstOrDefault(x => x.Email == addressDTO.Email));
                }
                else
                {
                    return(null);
                }
            }
        }
Example #9
0
        public List <UserProductDBModel> GetUserProductsDB(string email)
        {
            using (var context = new ECommerceDB())
            {
                List <UserProductDBModel> userProductList = context.userProductDBModels.Where(x => x.Email == email).ToList();


                if (userProductList != null)
                {
                    return(userProductList);
                }

                else
                {
                    return(null);
                }
            }
        }
Example #10
0
        public ProductDTO PurchaseProduct(ProductDTO productDTO)
        {
            ProductDB product = new ProductDB();

            UserProductDBModel userProductDBModel = new UserProductDBModel();

            ProductDTO productDTOObj = new ProductDTO();

            using (var context = new ECommerceDB())
            {
                if (context.productDB.Any(x => x.ModelNumber == productDTO.ModelNumber))
                {
                    product = context.productDB.FirstOrDefault(x => x.ModelNumber == productDTO.ModelNumber);

                    if ((product.AvailableQuantity > productDTO.RequiredQuantity) && productDTO.RequiredQuantity != 0)
                    {
                        product.AvailableQuantity -= productDTO.RequiredQuantity;
                        context.SaveChanges();

                        productDTOObj.ModelNumber       = productDTO.ModelNumber;
                        productDTOObj.Price             = productDTO.Price;
                        productDTOObj.Description       = productDTO.Description;
                        productDTOObj.AvailableQuantity = productDTO.AvailableQuantity;
                        productDTOObj.RequiredQuantity  = productDTO.RequiredQuantity;
                        productDTOObj.DeliveryTime      = productDTO.DeliveryTime;

                        userProductDBModel.Email            = productDTO.Email;
                        userProductDBModel.ModelNumber      = productDTO.ModelNumber;
                        userProductDBModel.RequiredQuantity = productDTO.RequiredQuantity;
                        userProductDBModel.Price            = productDTO.Price;
                        userProductDBModel.Description      = productDTO.Description;
                        userProductDBModel.DeliveryTime     = productDTO.DeliveryTime;
                        context.userProductDBModels.Add(userProductDBModel);
                        context.SaveChanges();

                        return(productDTOObj);
                    }

                    return(null);
                }
                return(null);
            }
        }