Ejemplo n.º 1
0
        private void AddCartItem(Cart cart, CartProdModel s)
        {
            CartProd cartProd = new CartProd();

            cartProd.Quantity = s.Quantity;
            cartProd.CartId   = s.CartId;
            cartProd.Price    = s.Price;
            cartProd.Title    = s.Title;
            if (s.ProdId != null)
            {
                if (s.ProdDetailId == null)
                {
                    cartProd.ProdId = s.ProdId;
                }
                else if (s.ProdDetailId != null)
                {
                    cartProd.ProdId       = s.ProdId;
                    cartProd.ProdDetailId = s.ProdDetailId;
                }
            }
            else if (s.PackId != null)
            {
                cartProd.PackId = s.PackId;
            }
            else if (s.SaleProdId != null)
            {
                cartProd.SaleProdId = s.SaleProdId;
            }
            _context.CartProd.Add(cartProd);
        }
Ejemplo n.º 2
0
        public void Checkout(string email)
        {
            DateTime created = System.DateTime.Now;

            _orderSer.CreateOrder(email, created);

            OrderDetails ord;
            CartProd     cartProd;
            Guid         orderId = _orderRepo.GetOrder(email, created).Id;
            var          list    = _cartProdSer.GetCartProds(email).ToList();

            foreach (var prod in list)
            {
                ord           = new OrderDetails();
                ord.OrderFk   = orderId;
                ord.ProductFk = prod.Product.Id;
                ord.Quantity  = prod.Quantity;
                _orderDetailsRepo.AddToOrderDetails(ord);

                _prodSer.UpdateProduct(ord.ProductFk, ord.Quantity);

                cartProd           = new CartProd();
                cartProd.ProductFk = prod.Product.Id;
                _cartProdSer.RemoveCartProduct(cartProd.ProductFk, email);
            }
        }
        public void AddToCart(Guid prodID, string email)
        {
            CartProd scp = new CartProd();

            scp.ShoppingCartFk = _cartRepo.GetCart(email).Id;
            scp.Quantity      += 1;
            scp.DateCreated    = System.DateTime.Now;
            scp.ProductFk      = _productRepo.GetProduct(prodID).Id;
            _cartProdRepo.AddToCart(scp);
        }
        public void UpdateToCart(Guid id, string email)
        {
            CartProd scp = _cartProdRepo.GetCartProduct(id);

            scp.ShoppingCartFk = _cartRepo.GetCart(email).Id;
            int currentQuantity = scp.Quantity;

            currentQuantity++;
            scp.Quantity    = currentQuantity;
            scp.DateCreated = System.DateTime.Now;
            scp.ProductFk   = _productRepo.GetProduct(id).Id;
            _cartProdRepo.UpdateCart(scp);
        }
Ejemplo n.º 5
0
        public IHttpActionResult Post([FromBody] CartProdModel cartProdModel)
        {
            var result = new Result <String>();

            using (var db = new jupiterEntities())
            {
                CartProd cartProd = new CartProd();
                Mapper.Map(cartProdModel, cartProd);
                try
                {
                    db.CartProds.Add(cartProd);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    result.ErrorMessage = e.Message;
                    result.IsSuccess    = false;
                    return(Json(result));
                }
                return(Json(result));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Mycart()
        {
            //var Lcart = new List<User_cart>();
            //var Lprod= new List<Product>();
            HttpCookie c        = Request.Cookies["Username"];
            string     Username = "";

            if (c != null)
            {
                Username = c.Value;
            }
            int           UserId = 0;
            SqlConnection con2   = new SqlConnection(Settings.ConStr);
            SqlCommand    cmd1   = new SqlCommand("select UserId from UserDetail where Username=@Username", con2);

            cmd1.Parameters.Add(new SqlParameter("Username", Username));
            con2.Open();

            SqlDataReader r = cmd1.ExecuteReader();

            while (r.Read())
            {
                UserId = (int)r["UserId"];
            }
            con2.Close();

            if (Request["Add"] != null)
            {
                int           Product_ID = int.Parse(Request["Add"]);
                SqlConnection conn       = new SqlConnection(Settings.ConStr);
                SqlCommand    cmdd       = new SqlCommand("select Product.*,Usercart.Quantity from Product,Usercart,UserDetail where Usercart.UserId=@UserId AND Usercart.UserId=UserDetail.UserId AND Usercart.Product_ID=Product.Product_ID AND Usercart.Product_ID=@Product_ID", conn);

                cmdd.Parameters.Add(new SqlParameter("UserId", UserId));
                cmdd.Parameters.Add(new SqlParameter("Product_ID", Product_ID));
                conn.Open();

                SqlDataReader rr       = cmdd.ExecuteReader();
                int           Quantity = 0;
                while (rr.Read())
                {
                    Quantity = (int)rr["Quantity"];
                }
                Quantity++;
                conn.Close();
                //SqlConnection conn = new SqlConnection(Settings.ConStr);
                SqlConnection conn1 = new SqlConnection(Settings.ConStr);
                SqlCommand    cmd2  = new SqlCommand("Update Usercart set Quantity=@Quantity where UserId=@UserId AND Product_ID=@Product_ID", conn1);
                cmd2.Parameters.Add(new SqlParameter("Quantity", Quantity));
                cmd2.Parameters.Add(new SqlParameter("UserId", UserId));
                cmd2.Parameters.Add(new SqlParameter("Product_ID", Product_ID));

                conn1.Open();
                cmd2.ExecuteNonQuery();
                conn1.Close();
            }
            if (Request["Minus"] != null)
            {
                int           Product_ID = int.Parse(Request["Minus"]);
                SqlConnection conn       = new SqlConnection(Settings.ConStr);
                SqlCommand    cmdd       = new SqlCommand("select Product.*,Usercart.Quantity from Product,Usercart,UserDetail where Usercart.UserId=@UserId AND Usercart.UserId=UserDetail.UserId AND Usercart.Product_ID=Product.Product_ID AND Usercart.Product_ID=@Product_ID", conn);

                cmdd.Parameters.Add(new SqlParameter("UserId", UserId));
                cmdd.Parameters.Add(new SqlParameter("Product_ID", Product_ID));
                conn.Open();

                SqlDataReader rr       = cmdd.ExecuteReader();
                int           Quantity = 1;
                while (rr.Read())
                {
                    Quantity = (int)rr["Quantity"];
                }
                if (Quantity == 0)
                {
                    Quantity = 0;
                }
                else
                {
                    Quantity--;
                }
                conn.Close();
                //SqlConnection conn = new SqlConnection(Settings.ConStr);
                SqlConnection conn1 = new SqlConnection(Settings.ConStr);
                SqlCommand    cmd2  = new SqlCommand("Update Usercart set Quantity=@Quantity where UserId=@UserId AND Product_ID=@Product_ID", conn1);
                cmd2.Parameters.Add(new SqlParameter("Quantity", Quantity));
                cmd2.Parameters.Add(new SqlParameter("UserId", UserId));
                cmd2.Parameters.Add(new SqlParameter("Product_ID", Product_ID));

                conn1.Open();
                cmd2.ExecuteNonQuery();
                conn1.Close();
            }
            if (Request["Remove"] != null)
            {
                //
                int           Product_ID = int.Parse(Request["Remove"]);
                SqlConnection conn       = new SqlConnection(Settings.ConStr);
                SqlCommand    cmd2       = new SqlCommand("DELETE FROM Usercart where UserId=@UserId AND Product_ID=@Product_ID", conn);

                cmd2.Parameters.Add(new SqlParameter("UserId", UserId));
                cmd2.Parameters.Add(new SqlParameter("Product_ID", Product_ID));

                conn.Open();
                cmd2.ExecuteNonQuery();
                conn.Close();
                //   break;
            }



            string cheke = Request["checkout"];

            //  HttpCookie c = Request.Cookies["Username"];

            var           Lmycart = new List <CartProd>();
            SqlConnection con     = new SqlConnection(Settings.ConStr);
            SqlCommand    cmd     = new SqlCommand("select Product.*,Usercart.Quantity from Product,Usercart,UserDetail where Usercart.UserId=@UserId AND Usercart.UserId=UserDetail.UserId AND Usercart.Product_ID=Product.Product_ID;", con);

            cmd.Parameters.Add(new SqlParameter("UserId", UserId));
            con.Open();

            SqlDataReader r2 = cmd.ExecuteReader();

            ViewBag.sum            = 0;
            ViewBag.TotalItems     = 0;
            ViewBag.DeliveryCharge = 0;

            while (r2.Read())
            {
                //var Pro = new Product();
                //var cart = new User_cart();
                var mycart = new CartProd();
                mycart.Product_ID  = (int)r2["Product_ID"];
                mycart.ProductName = r2["ProductName"].ToString();
                mycart.Description = (string)r2["Description"];
                mycart.Price       = (double)r2["Price"];
                mycart.Picture     = (string)r2["Picture"];

                mycart.qty = (int)r2["Quantity"];

                //Lprod.Add(Pro);
                //Lcart.Add(cart);
                //mycart.Usercart = cart;
                //mycart.Product = Pro;
                ViewBag.TotalItems    += mycart.qty;
                ViewBag.sum           += (mycart.Price * mycart.qty);
                ViewBag.DeliveryCharge = 100;
                ViewBag.AmtPayable     = ViewBag.sum + ViewBag.DeliveryCharge;
                Lmycart.Add(mycart);
            }



            Session["email_data"] = Lmycart;

            Session["OrderTotal"] = ViewBag.AmtPayable;
            if (Request["checkout"] != null)
            {
                if (ViewBag.AmtPayable == null)
                {
                    ViewBag.CheckoutMsg = "Add atleast one Item to your cart!";
                }
                else
                {
                    return(RedirectToAction("checkout"));
                }
            }
            return(View(Lmycart));
        }
 public void UpdateCart(CartProd prod)
 {
     _context.CartProd.Update(prod);
     _context.SaveChanges();
 }
 public void AddToCart(CartProd p)
 {
     _context.CartProd.Add(p);
     _context.SaveChanges();
 }