Beispiel #1
0
 public Apparel getApparelForCart(string apparelID, string size)
 {
     Apparel data = new Apparel();
     string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
     SqlConnection conn = new SqlConnection(conStr);
     try
     {
         conn.Open();
         SqlCommand cmd = new SqlCommand("Select ap.ApparelID, ap.ApparelName, qt.ApparelSize, qt.ApparelDiscount, qt.ApparelCost from Apparel ap INNER JOIN Quantity qt ON ap.ApparelID=qt.ApparelID where ap.ApparelID=@apparelID AND qt.ApparelSize=@size", conn);
         cmd.Parameters.AddWithValue("apparelID", apparelID.Trim());
         cmd.Parameters.AddWithValue("size", size.Trim());
         var reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             while (reader.Read())
             {
                 data.ApparelName = reader.GetString(reader.GetOrdinal("ApparelName"));
                 data.ApparelID = reader.GetInt32(reader.GetOrdinal("ApparelID"));
                 data.ApparelCost = reader.GetDecimal(reader.GetOrdinal("ApparelCost"));
                 data.ApparelSize = reader.GetString(reader.GetOrdinal("ApparelSize")).Trim();
                 data.ApparelDiscount = reader.GetDecimal(reader.GetOrdinal("ApparelDiscount"));
             }
         }
     }
     catch (Exception ExcObj)
     {
         HttpContext.Current.Session["ErrorMessage"] = ExcObj.Message;
     }
     conn.Close();
     return data;
 }
Beispiel #2
0
 public List<Apparel> GetProductByCategory(string category)
 {
     List<Apparel> dataRows = new List<Apparel>();
     string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
     SqlConnection conn = new SqlConnection(conStr);
     try
     {
         conn.Open();
         SqlCommand cmd = new SqlCommand("Select * from Apparel ap INNER JOIN Quantity qt ON ap.ApparelID=qt.ApparelID where ApparelCategory=@category order by ap.ApparelAddTime desc", conn);
         cmd.Parameters.AddWithValue("category", category.Trim());
         var reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             while (reader.Read())
             {
                 Apparel prodObj = new Apparel();
                 prodObj.ApparelID = reader.GetInt32(reader.GetOrdinal("ApparelID"));
                 prodObj.ApparelName = reader.GetString(reader.GetOrdinal("ApparelName"));
                 prodObj.BrandName = reader.GetString(reader.GetOrdinal("BrandName"));
                 prodObj.ApparelCost = reader.GetDecimal(reader.GetOrdinal("ApparelCost"));
                 prodObj.Description = reader.GetString(reader.GetOrdinal("Description"));
                 prodObj.ApparelImage = reader.GetString(reader.GetOrdinal("ApparelImage"));
                 prodObj.ApparelCategory = reader.GetString(reader.GetOrdinal("ApparelCategory"));
                 prodObj.ApparelRating = reader.GetInt32(reader.GetOrdinal("ApparelRating"));
                 prodObj.ApparelSize = reader.GetString(reader.GetOrdinal("ApparelSize"));
                 prodObj.ApparelDiscount = reader.GetDecimal(reader.GetOrdinal("ApparelDiscount"));
                 dataRows.Add(prodObj);
             }
         }
     }
     catch (Exception ExcObj)
     {
         HttpContext.Current.Session["ErrorMessage"] = ExcObj.Message;
     }
     conn.Close();
     return dataRows;
 }
Beispiel #3
0
        public List<CartItem> getUserCart(string UserID)
        {
            bool status = false;
            HttpContext.Current.Session["status"] = "DefaultMessage";
            string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            List<CartItem> cartItems = new List<CartItem>();
            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand("SELECT * FROM SavedCart WHERE UserID=@UserID", conn);
                cmd.Parameters.AddWithValue("UserID", UserID.Trim());
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CartItem cartItem = new CartItem();

                        string apparelID = reader.GetString(reader.GetOrdinal("ApparelID"));
                        string apparelSize = reader.GetString(reader.GetOrdinal("ApparelSize"));
                        string offerID = reader.GetString(reader.GetOrdinal("OfferID"));
                        int quantity = reader.GetInt32(reader.GetOrdinal("Quantity"));
                        cartItem.OfferID = offerID;
                        cartItem.Apparel.ApparelSize = apparelSize;
                        cartItem.Apparel.ApparelID = Convert.ToInt32(apparelID);

                        CustomerDal custDal = new CustomerDal();
                        Quantity quantityDetails = custDal.GetQuantityDetailForApparel(Convert.ToInt32(apparelID), apparelSize);

                        int availableQuantity = (quantityDetails.ApparelQuantity >= quantity) ? quantity : quantityDetails.ApparelQuantity;
                        if(availableQuantity!=quantity)
                            HttpContext.Current.Session["cartUpdated"] = "true";

                        if(availableQuantity >0 )
                        {
                            cartItem.Quantity = availableQuantity;
                            Apparel apparel = new Apparel();
                            apparel = custDal.GetApparelByID(Convert.ToInt32(apparelID))[0];

                            cartItem.Apparel.ApparelName = apparel.ApparelName;
                            cartItem.Apparel.ApparelCost = quantityDetails.ApparelCost;
                            cartItem.Apparel.ApparelDiscount = quantityDetails.ApparelDiscount;
                            if(!(offerID.Trim().Equals("NOOFF")))
                            {
                                AdminDal adminDal = new AdminDal();
                                Offer offer = new Offer();
                                offer = adminDal.GetOfferDateAndDiscountByID(offerID);
                                if(System.DateTime.Equals(offer.OfferDate, DateTime.Now.Date))
                                    cartItem.Apparel.ApparelDiscount += offer.Discount;
                            }
                            cartItems.Add(cartItem);
                        }

                    }

                }
                conn.Close();
                conn.Open();
                SqlCommand cmd2 = new SqlCommand("DELETE FROM SavedCart WHERE UserID=@UserID", conn);
                cmd2.Parameters.AddWithValue("UserID", UserID.Trim());
                var reader2 = cmd2.ExecuteNonQuery();

            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return cartItems;
        }
Beispiel #4
0
 public CartItem(Apparel apparel, int quantity, string offerID)
 {
     this.apparel = apparel;
     this.quantity = quantity;
     this.OfferID = offerID;
 }
 public List<Apparel> GetApparelByID(int id)
 {
     List<Apparel> dataRows = new List<Apparel>();
     string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
     SqlConnection conn = new SqlConnection(conStr);
     try
     {
         conn.Open();
         SqlCommand cmd = new SqlCommand("Select * from Apparel where ApparelID=@id", conn);
         cmd.Parameters.AddWithValue("id", id);
         var reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             while (reader.Read())
             {
                 Apparel prodObj = new Apparel();
                 prodObj.ApparelID = reader.GetInt32(reader.GetOrdinal("ApparelID"));
                 prodObj.ApparelName = reader.GetString(reader.GetOrdinal("ApparelName"));
                 prodObj.BrandName = reader.GetString(reader.GetOrdinal("BrandName"));
                 prodObj.Description = reader.GetString(reader.GetOrdinal("Description"));
                 prodObj.ApparelImage = reader.GetString(reader.GetOrdinal("ApparelImage"));
                 prodObj.ApparelCategory = reader.GetString(reader.GetOrdinal("ApparelCategory"));
                 prodObj.ApparelRating = reader.GetInt32(reader.GetOrdinal("ApparelRating"));
                 dataRows.Add(prodObj);
             }
         }
     }
     catch (Exception ExcObj)
     {
         HttpContext.Current.Session["ErrorMessage"] = ExcObj.Message;
     }
     conn.Close();
     return dataRows;
 }
 public AddApparel()
 {
     apparel = new Apparel();
 }
        public ActionResult OfferOfDay()
        {
            ViewBag.Title = "Offer of The Day!!!";
            CustomerBLL obj = new CustomerBLL();
            List<Offer> model = new List<Offer>();
            model = obj.GetTodaysOffer();
            Apparel apparel = new Apparel();

            if (model.Count > 0)
            {
                apparel = obj.GetApparelByID(model[0].ApparelID)[0];
                ViewBag.OfferID = model[0].OfferID;
                ViewBag.OfferName = model[0].OfferName;
                ViewBag.OfferDescription = model[0].OfferDescription;
                ViewBag.OfferDiscount = model[0].Discount;
                ViewBag.OfferName = model[0].OfferName;
            }
            else
            {
                ViewBag.OfferTitle = "none";

            }

            return View(apparel);
        }
        public ActionResult OrderNowOffer(string id, string size, string offerDiscount, string offerID)
        {
            size = size.Trim();
            if (Session["UserID"] == null)
                return RedirectToAction("Login", "Account");
            if (Session["UserRole"].ToString() == "admin")
                return RedirectToAction("Index", "Admin");

            Apparel apparel = new Apparel();
            apparel = bllObj.getApparelForCart(id, size);
            apparel.ApparelDiscount += Convert.ToDecimal(offerDiscount);
            if (Session["cart"] == null)
            {
                List<CartItem> cart = new List<CartItem>();

                cart.Add(new CartItem(apparel, 1, offerID));
                Session["cart"] = cart;
            }
            else
            {
                List<CartItem> cart = (List<CartItem>)Session["cart"];
                int index = IsExisting(Convert.ToInt32(id), size);
                if (index == -1)
                    cart.Add(new CartItem(apparel, 1, offerID));
                else
                    cart[index].Quantity++;
                Session["cart"] = cart;
            }
            return RedirectToAction("Index");
        }