Exemple #1
0
 public void BindGrid()
 {
     var _db = new ProductContext();
     IQueryable<Product> query = _db.Products;
     GridView1.DataSource = query;
     GridView1.DataBind();
 }
Exemple #2
0
        public bool AddProduct(string productName, string description, string imagePath, string unitPrice, int labelID, string status, string unitInStock, string categoryID, string userID)
        {
            var newProduct = new Product();
            newProduct.ProductName = productName;
            newProduct.Description = description;
            newProduct.ImagePath = imagePath;
            newProduct.UnitPrice = Convert.ToDouble(unitPrice);
            newProduct.LabelID = labelID;
            newProduct.Status = Convert.ToBoolean(status);
            newProduct.UnitInStock = Convert.ToInt16(unitInStock);
            newProduct.CategoryID = Convert.ToInt16(categoryID);
            newProduct.CreatedDate = DateTime.Now.Date;
            newProduct.CreatedBy = userID;
            newProduct.UnitsAvailable = Convert.ToInt16(unitInStock);
            newProduct.UnitsLock = 0;
            newProduct.Discount = 0;

            using (ProductContext _db = new ProductContext())
            {
                // Add product to DB.
                _db.Products.Add(newProduct);
                _db.SaveChanges();
            }
            return true;
        }
Exemple #3
0
        public IQueryable<Product> GetProducts()
        {
            var _db = new ProductContext();
            IQueryable<Product> query = _db.Products;

            UserRoleActions user = new UserRoleActions();
            return query;
        }
        // The return type can be changed to IEnumerable, however to support
        // paging and sorting, the following parameters must be added:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable<MenStore.Models.OrderDetail> OrderHistory_GetData()
        {
            ProductContext _db = new ProductContext();
            string userName = User.Identity.GetUserName();

            IQueryable<OrderDetail> query = _db.OrderDetails.Where(p => p.Username == userName );

            return query;
        }
Exemple #5
0
 public void GetNewProducts()
 {
     var _db = new ProductContext();
     List<Product> query = new List<Product>();
     query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 1).ToList();
     query = query.OrderBy(i => i.CreatedDate).Take(4).ToList();
     productList.DataSource = query;
     productList.DataBind();
 }
Exemple #6
0
 public void GetSpecialProducts()
 {
     var _db = new ProductContext();
     List<Product> query = new List<Product>();
     query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.Discount != 0).ToList();
     query = query.OrderByDescending(i => i.Discount).Take(4).ToList();
     ProductListSpecial.DataSource = query;
     ProductListSpecial.DataBind();
 }
Exemple #7
0
 public void GetBestSellerProducts()
 {
     var _db = new ProductContext();
     ProductActions productAction = new ProductActions();
     List<Product> query = new List<Product>();
     query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 4).ToList();
     query = query.OrderByDescending(i => productAction.GetUnitSold(i.ProductID)).Take(4).ToList();
     productListBstSlr.DataSource = query;
     productListBstSlr.DataBind();
 }
Exemple #8
0
 public bool DeleteProduct(int productID)
 {
     using (ProductContext _db = new ProductContext())
     {
         var product = (from c in _db.Products where c.ProductID == productID select c).FirstOrDefault();
         if (product != null)
         {
             _db.Products.Remove(product);
             _db.SaveChanges();
         }
         return true;
     }
 }
Exemple #9
0
 internal bool UpdateCategory(int ID, string Name)
 {
     using (ProductContext _db = new ProductContext())
     {
         var cat = _db.Categories.Where(c => c.CategoryID == ID).FirstOrDefault();
         if (cat != null)
         {
             cat.CategoryName = Name;
             _db.SaveChanges();
             return true;
         }
     }
     return false;
 }
        protected void OrderHistory_DataBound(object sender, EventArgs e)
        {
            ProductContext _db = new ProductContext();
            Order order = new Order();

            for (int i = 0; i < OrderHistory.Rows.Count; i++)
            {
                int id = int.Parse(OrderHistory.Rows[i].Cells[0].Text);
                order = _db.Orders.Find(id);
                if (order.PaymentTransactionId == null)
                {
                    OrderHistory.Rows[i].Visible = false;
                }
            }
        }
Exemple #11
0
 public void GetProducts(string search)
 {
     var _db = new ProductContext();
     List<Product> query = new List<Product>();
     if (!string.IsNullOrEmpty(search))
     {
         query = _db.Products.Where(p => p.ProductName.Contains(search) && p.Status == true && p.UnitInStock > 0).ToList();
     }
     else
     {
         query = null;
     }
     productList.DataSource = query;
     productList.DataBind();
 }
Exemple #12
0
        internal bool AddCategory(string Name)
        {
            var newCategory = new Category();

            newCategory.CategoryName = Name;

            using (ProductContext _db = new ProductContext())
            {
                // Add product to DB.
                _db.Categories.Add(newCategory);
                _db.SaveChanges();
            }

            return true;
        }
Exemple #13
0
        internal bool DeleteCategory(int ID)
        {
            using (ProductContext _db = new ProductContext())
            {
                var myItem = (from c in _db.Categories where c.CategoryID == ID select c).FirstOrDefault();

                if (myItem.Products.Count() > 0)
                {
                    return false;
                }
                _db.Categories.Remove(myItem);
                _db.SaveChanges();

            }
            return true;
        }
Exemple #14
0
        public int GetUnitSold(int Id)
        {
            ProductContext _db = new ProductContext();
            Order order = new Order();
            int quantity = 0;
            List<OrderDetail> lst = _db.OrderDetails.Where(p => p.ProductId == Id).ToList();
            foreach (var item in lst)
            {
                order = _db.Orders.Where(p => p.OrderId == item.OrderId).FirstOrDefault();
                if (order.PaymentTransactionId != null)
                {
                    quantity += item.Quantity;
                }

            }
            return quantity;
        }
Exemple #15
0
 private static void CheckCart()
 {
     ProductContext _db = new ProductContext();
     ShoppingCartActions cartActions = new ShoppingCartActions();
     while (true)
     {
         foreach (var item in _db.ShoppingCartItems.ToList())
         {
             if ((DateTime.Now - (DateTime)item.DateCreated  ).TotalMinutes >= 20)
             {
                 cartActions.RemoveItem(item.CartId, item.ProductId);
             }
         }
         _db.SaveChanges();
         Thread.Sleep(5000);
     }
 }
Exemple #16
0
 public void GetProducts(string id)
 {
     var _db = new ProductContext();
     ProductActions productAction = new ProductActions();
     List<Product> query = new List<Product>();
     int catID = 0;
     bool r = Int32.TryParse(id, out catID);
     if (r && catID > 0)
     {
         query = _db.Products.Where(p => p.CategoryID == catID && p.Status == true && p.UnitInStock > 0).ToList();
         Title = _db.Categories.Where(c => c.CategoryID == catID).FirstOrDefault().CategoryName;
     }
     else if (id=="new")
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 1).ToList();
         query = query.OrderBy(i => i.CreatedDate).ToList();
         Title = "Special Offer";
     }
     else if (id == "bestseller")
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 4).ToList();
         query = query.OrderByDescending(i => productAction.GetUnitSold(i.ProductID)).ToList();
         Title = "Best Sellers";
     }
     else if (id == "special")
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.Discount != 0).ToList();
         query = query.OrderByDescending(i => i.Discount).ToList();
         Title = "Special Offer";
     }
     else
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0).ToList();
         Title = "Browse Products";
     }
     productList.DataSource = query;
     productList.DataBind();
 }
Exemple #17
0
 public bool UpdateProduct(int ID, string productName, string description, string imagePath, double unitPrice, bool status, double discount, int unitInStock, int categoryID, string userId)
 {
     using (ProductContext _db = new ProductContext())
     {
         var product = _db.Products.Where(p => p.ProductID == ID).FirstOrDefault();
         if (product != null)
         {
             product.ProductName = productName;
             product.Description = description;
             product.ImagePath = imagePath;
             product.UnitPrice = unitPrice;
             product.Status = status;
             product.UnitInStock = unitInStock;
             product.CategoryID = categoryID;
             product.ModifiedDate = DateTime.Now.Date;
             product.ModifiedBy = userId;
             product.UnitsAvailable = unitInStock - product.UnitsLock;
             product.Discount = discount;
             _db.SaveChanges();
         }
     }
     return true;
 }
Exemple #18
0
        private static void CheckLabel()
        {
            ProductContext _db = new ProductContext();
            ProductActions productAction = new ProductActions();
            while (true)
            {
                foreach (var item in _db.Products.ToList())
                {
                    DateTime date = (DateTime)item.CreatedDate;
                    DateTime newDate = DateTime.Now;
                    // Difference in days, hours, and minutes.
                    TimeSpan ts = newDate - date;
                    // Difference in days.
                    int differenceInDays = ts.Days;
                    if (differenceInDays >= 365)
                    {
                        if (item.Discount<0.50)
                        {
                            item.Discount = 0.50;
                        }
                        item.LabelID = 3;
                    }
                    else if (productAction.GetUnitSold(item.ProductID) >= 1000)
                    {
                        item.LabelID = 4;
                    }

                    else if (differenceInDays >= 7)
                    {
                        item.LabelID = 2;
                    }

                }
                _db.SaveChanges();
                Thread.Sleep(5000);
            }
        }
Exemple #19
0
        public IQueryable<Product> GetProduct([QueryString("productID")] int? productId)
        {
            var _db = new ProductContext();
            IQueryable<Product> query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0);
            query = query.Where(p => p.ProductID == productId);
            if (query.Count() > 0)
            {
                UserRoleActions user = new UserRoleActions();
                lblCreatedBy.Text = user.GetUserNameById(query.ToList()[0].CreatedBy);
                lblCreatedDate.Text = ((DateTime)query.ToList()[0].CreatedDate).ToShortDateString();
                if (query.ToList()[0].ModifiedBy != null)
                {
                    lblModifyBy.Text = user.GetUserNameById(query.ToList()[0].ModifiedBy);
                    lblModifyDate.Text = ((DateTime)query.ToList()[0].ModifiedDate).ToShortDateString();
                    proModifyby.Visible = true;
                }
            }
            else
            {
                query = null;
            }

            return query;
        }
Exemple #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NVPAPICaller payPalCaller = new NVPAPICaller();

                string retMsg = "";
                string token = "";
                string PayerID = "";
                NVPCodec decoder = new NVPCodec();
                token = Session["token"].ToString();

                bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg);
                if (ret)
                {
                    Session["payerId"] = PayerID;

                    var myOrder = new Order();
                    myOrder.OrderDate = Convert.ToDateTime(decoder["TIMESTAMP"].ToString());
                    myOrder.Username = User.Identity.Name;
                    myOrder.FirstName = decoder["FIRSTNAME"].ToString();
                    myOrder.LastName = decoder["LASTNAME"].ToString();
                    myOrder.Address = decoder["SHIPTOSTREET"].ToString();
                    myOrder.City = decoder["SHIPTOCITY"].ToString();
                    myOrder.State = decoder["SHIPTOSTATE"].ToString();
                    myOrder.PostalCode = decoder["SHIPTOZIP"].ToString();
                    myOrder.Country = decoder["SHIPTOCOUNTRYCODE"].ToString();
                    myOrder.Email = decoder["EMAIL"].ToString();
                    myOrder.Total = Convert.ToDecimal(decoder["AMT"].ToString());

                    // Verify total payment amount as set on CheckoutStart.aspx.
                    try
                    {
                        decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString());
                        decimal paymentAmoutFromPayPal = Convert.ToDecimal(decoder["AMT"].ToString());
                        if (paymentAmountOnCheckout != paymentAmoutFromPayPal)
                        {
                            Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }

                    // Get DB context.
                    ProductContext _db = new ProductContext();

                    // Add order to DB.
                    _db.Orders.Add(myOrder);
                    _db.SaveChanges();

                    // Get the shopping cart items and process them.
                    using (MenStore.Logic.ShoppingCartActions usersShoppingCart = new MenStore.Logic.ShoppingCartActions())
                    {
                        List<CartItem> myOrderList = usersShoppingCart.GetCartItems();

                        // Add OrderDetail information to the DB for each product purchased.
                        for (int i = 0; i < myOrderList.Count; i++)
                        {
                            // Create a new OrderDetail object.
                            var myOrderDetail = new OrderDetail();
                            myOrderDetail.OrderId = myOrder.OrderId;
                            myOrderDetail.Username = User.Identity.Name;
                            myOrderDetail.ProductId = myOrderList[i].ProductId;
                            myOrderDetail.Quantity = myOrderList[i].Quantity;
                            myOrderDetail.UnitPrice = Math.Round((double)(myOrderList[i].Product.UnitPrice - (myOrderList[i].Product.UnitPrice * myOrderList[i].Product.Discount)), 2);

                            // Add OrderDetail to DB.
                            //Product p = _db.Products.Find(myOrderList[i].ProductId);
                            ////set units in stock and unlock units
                            //p.UnitsLock -= myOrderList[i].Quantity;
                            //p.UnitInStock -= myOrderList[i].Quantity;
                            _db.OrderDetails.Add(myOrderDetail);
                            _db.SaveChanges();
                        }

                        // Set OrderId.
                        Session["currentOrderId"] = myOrder.OrderId;

                        // Display Order information.
                        List<Order> orderList = new List<Order>();
                        orderList.Add(myOrder);
                        ShipInfo.DataSource = orderList;
                        ShipInfo.DataBind();

                        // Display OrderDetails.
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
Exemple #21
0
 internal Product GetProduct(int id)
 {
     ProductContext _db = new ProductContext();
     return _db.Products.Find(id);
 }
Exemple #22
0
 public void Dispose()
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
 }
Exemple #23
0
 internal void UnlockUnits(int quantity, int id)
 {
     using (ProductContext _db = new ProductContext())
     {
         Product p = _db.Products.Find(id);
         p.UnitsLock -= quantity;
         _db.SaveChanges();
     }
 }
Exemple #24
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new ProductContext())
     {
         try
         {
             int CartItemCount = CartItemUpdates.Count();
             List<CartItem> myCart = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 // Iterate through all rows within shopping cart list
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.Product.ProductID == CartItemUpdates[i].ProductId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.ProductId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.ProductId, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemple #25
0
        public void UpdateItem(string updateCartID, int updateProductID, int quantity)
        {
            using (var _db = new ProductContext())
            {
                try
                {
                    var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Product.ProductID == updateProductID select c).FirstOrDefault();
                    if (myItem != null)
                    {

                        int count = quantity;
                        count -= myItem.Quantity;
                        //if (count < 0)
                        //{
                        //    count *= (-1);
                        //}
                        LockUnits(count, updateProductID);
                        myItem.Quantity = quantity;
                        _db.SaveChanges();

                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
                }
            }
        }
Exemple #26
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ProductID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.ShoppingCartItems.Remove(myItem);
                 UnlockUnits(myItem.Quantity, myItem.ProductId);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemple #27
0
 internal Category GetCategory(int id)
 {
     ProductContext _db = new ProductContext();
     return _db.Categories.Find(id);
 }
Exemple #28
0
        internal double GetCashCollected(int id)
        {
            ProductContext _db = new ProductContext();
            Order order = new Order();
            double cash = 0.00;
            List<OrderDetail> lst = _db.OrderDetails.Where(p => p.ProductId == id).ToList();
            foreach (var item in lst)
            {
                order = _db.Orders.Where(p => p.OrderId == item.OrderId).FirstOrDefault();
                if (order.PaymentTransactionId != null)
                {
                    cash += (double)(item.UnitPrice * item.Quantity);
                }

            }
            return cash;
        }
 protected string GetOrderDate(int id)
 {
     ProductContext _db = new ProductContext();
     return _db.Orders.Where(o => o.OrderId == id).FirstOrDefault().OrderDate.ToShortDateString(); ;
 }
Exemple #30
0
 public IQueryable<Category> GetCategories()
 {
     var _db = new ProductContext();
     IQueryable<Category> query = _db.Categories;
     return query;
 }