Example #1
0
        public ActionResult getshopsbylocation(string select1, int select2)
        {
            ViewData["location"] = select1;
            ViewData["category"] = select2;
            SqlConnection con = new SqlConnection();

            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection  = con;
            cmd.CommandText = "getShopsIn";
            cmd.Parameters.AddWithValue("@city", select1);
            cmd.Parameters.AddWithValue("@categoryID", select2);
            SqlDataReader    r = cmd.ExecuteReader();
            List <shopOwner> l = new List <shopOwner>();

            if (!r.HasRows)
            {
                ViewBag.Message = "no shops found";
            }
            while (r.Read())
            {
                shopOwner s = new shopOwner();
                s.shopName    = r["shopName"].ToString();
                s.shopImg     = r["shopImg"].ToString();
                s.shopOwnerID = int.Parse(r["shopOwnerID"].ToString());

                l.Add(s);
            }
            con.Close();

            return(View(l));
        }
Example #2
0
        public ActionResult getshopsdiscount()
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection  = con;
            cmd.CommandText = "getShopsOffers";
            cmd.Parameters.AddWithValue("@id", ViewBag.consumer.consumerID);
            SqlDataReader    r  = cmd.ExecuteReader();
            List <shopOwner> l2 = new List <shopOwner>();

            while (r.Read())
            {
                shopOwner s = new shopOwner();
                s.shopName = r["shopName"].ToString();
                s.shopImg  = r["shopImg"].ToString();
                s.discount = double.Parse(r["discount"].ToString());
                l2.Add(s);
            }
            con.Close();

            return(View(l));
        }
Example #3
0
 public ActionResult xxx(shopOwner s)
 {
     if (s.shopImg == null)
     {
         s.shopImg = "user-image.jpg";
     }
     if (s.shopName == null)
     {
         s.shopName = "User";
     }
     Session["shopOwner"]   = s.personalInfoID;
     Session["shopOwnerID"] = s.shopOwnerID;
     Session["email"]       = s.email;
     return(RedirectToAction("Index2", new { shopOnwerId = s.shopOwnerID }));
 }
Example #4
0
        public ActionResult SignUp(uiSignConsumer u)
        {
            SqlConnection con = new SqlConnection();

            //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";

            con.Open();
            if (u.role == 1 && u.password == u.repassword)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Connection  = con;//بربط ال command على الداتابيز
                cmd.CommandText = "addConsumer";
                cmd.Parameters.AddWithValue("@consumerName", u.firstName);
                cmd.Parameters.AddWithValue("@email", u.email);
                cmd.Parameters.AddWithValue("@password", u.password);
                cmd.Parameters.AddWithValue("@country", u.country);
                cmd.Parameters.AddWithValue("@city", u.city);
                cmd.Parameters.AddWithValue("@role", u.role);


                int x = cmd.ExecuteNonQuery();
                if (x == 2)
                {
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd2.Connection  = con;//بربط ال command على الداتابيز
                    cmd2.CommandText = "getConsumerAll";
                    cmd2.Parameters.AddWithValue("@email", u.email);


                    SqlDataReader r = cmd2.ExecuteReader();
                    consumer      s = new consumer();
                    while (r.Read())
                    {
                        s.personalInfoID = int.Parse(r["personalInfoID"].ToString());

                        s.email          = r["email"].ToString();
                        s.consumerID     = int.Parse(r["consumerID"].ToString());
                        s.password       = r["password"].ToString();
                        s.firstName      = r["firstName"].ToString();
                        s.country        = r["country"].ToString();
                        s.city           = r["city"].ToString();
                        ViewBag.consumer = s;
                        con.Close();
                        return(RedirectToAction("home", "Home", s));
                    }
                }
            }
            else if (u.role == 2 && u.password == u.repassword)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Connection  = con;//بربط ال command على الداتابيز
                cmd.CommandText = "addSupplier";
                cmd.Parameters.AddWithValue("@supplierName", u.firstName);
                cmd.Parameters.AddWithValue("@email", u.email);
                cmd.Parameters.AddWithValue("@password", u.password);
                cmd.Parameters.AddWithValue("@country", u.country);
                cmd.Parameters.AddWithValue("@city", u.city);
                cmd.Parameters.AddWithValue("@role", u.role);
                cmd.Parameters.AddWithValue("@categoryID", u.categoryID);
                cmd.Parameters.AddWithValue("@lat", u.lat);
                cmd.Parameters.AddWithValue("@lng", u.lng);

                int x = cmd.ExecuteNonQuery();
                if (x == 2)
                {
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd2.Connection  = con;//بربط ال command على الداتابيز
                    cmd2.CommandText = "getSupplierAll";
                    cmd2.Parameters.AddWithValue("@email", u.email);


                    SqlDataReader r = cmd2.ExecuteReader();
                    supplier      s = new supplier();
                    while (r.Read())
                    {
                        s.personalInfoID = int.Parse(r["personalInfoID"].ToString());

                        s.email      = r["email"].ToString();
                        s.supplierID = int.Parse(r["supplierID"].ToString());
                        s.password   = r["password"].ToString();
                        s.name       = r["name"].ToString();
                        s.country    = r["country"].ToString();
                        s.city       = r["city"].ToString();
                        s.supImg     = r["supImg"].ToString();
                        s.categoryID = int.Parse(r["categoryID"].ToString());
                        //  ViewBag.supplier = s;
                        return(RedirectToAction("xxx", "view", s));
                    }
                }
            }
            else if (u.role == 3 && u.password == u.repassword)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Connection  = con;//بربط ال command على الداتابيز
                cmd.CommandText = "addShopOwner";
                cmd.Parameters.AddWithValue("@shopName", u.firstName);
                cmd.Parameters.AddWithValue("@email", u.email);
                cmd.Parameters.AddWithValue("@password", u.password);
                cmd.Parameters.AddWithValue("@country", u.country);
                cmd.Parameters.AddWithValue("@city", u.city);
                cmd.Parameters.AddWithValue("@role", u.role);
                cmd.Parameters.AddWithValue("@categoryID", u.categoryID);
                cmd.Parameters.AddWithValue("@lat", u.lat);
                cmd.Parameters.AddWithValue("@lng", u.lng);

                int x = cmd.ExecuteNonQuery();
                if (x == 2)
                {
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd2.Connection  = con;//بربط ال command على الداتابيز
                    cmd2.CommandText = "getShopOwnerAll";
                    cmd2.Parameters.AddWithValue("@email", u.email);


                    SqlDataReader r1 = cmd2.ExecuteReader();
                    shopOwner     s  = new shopOwner();
                    while (r1.Read())
                    {
                        s.personalInfoID = int.Parse(r1["personalInfoID"].ToString());

                        s.email       = r1["email"].ToString();
                        s.shopOwnerID = int.Parse(r1["shopOwnerID"].ToString());
                        s.password    = r1["password"].ToString();
                        s.ownerName   = r1["ownerName"].ToString();
                        s.country     = r1["country"].ToString();
                        s.city        = r1["city"].ToString();
                        s.shopImg     = r1["shopImg"].ToString();
                        s.categoryID  = int.Parse(r1["categoryID"].ToString());
                        con.Close();
                        return(RedirectToAction("xxx", "view2", s));
                    }
                }
            }
            con.Close();
            return(View("errorSignUP"));
        }
Example #5
0
        public ActionResult login(string email, string password)
        {
            SqlConnection con = new SqlConnection();

            //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";

            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection  = con;//بربط ال command على الداتابيز
            cmd.CommandText = "checkLogin";
            cmd.Parameters.AddWithValue("@email ", email);

            cmd.Parameters.AddWithValue("@password ", password);
            SqlDataReader r1 = cmd.ExecuteReader();
            int           personalInfoID, role;

            if (!r1.HasRows)
            {
                ModelState.AddModelError("invalid", "Email or Password is Wrong");
                con.Close();
                return(View());
            }
            while (r1.Read())
            {
                personalInfoID = int.Parse(r1["personalInfoID"].ToString());
                role           = int.Parse(r1["role"].ToString());
                if (role == 1)
                {
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = System.Data.CommandType.Text;
                    cmd2.CommandText = "select * from consumer where personalInfoID=" + personalInfoID;
                    cmd2.Connection  = con;
                    r1.Close();
                    SqlDataReader r2 = cmd2.ExecuteReader();
                    consumer      s  = new consumer();
                    while (r2.Read())
                    {
                        s.email      = email;
                        s.consumerID = int.Parse(r2["consumerID"].ToString());
                        s.password   = password;
                        s.firstName  = r2["firstName"].ToString();
                        s.country    = r2["country"].ToString();
                        s.city       = r2["city"].ToString();
                    }
                    ViewBag.consumer = s;
                    con.Close();
                    return(RedirectToAction("home", "Home", s));
                }
                else if (role == 2)
                {
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = System.Data.CommandType.Text;
                    cmd2.CommandText = "select * from supplier where personalInfoID=" + personalInfoID;
                    cmd2.Connection  = con;
                    r1.Close();
                    SqlDataReader r3 = cmd2.ExecuteReader();
                    supplier      s  = new supplier();
                    while (r3.Read())
                    {
                        s.personalInfoID = int.Parse(r3["personalInfoID"].ToString());

                        s.email      = email;
                        s.supplierID = int.Parse(r3["supplierID"].ToString());
                        s.password   = password;
                        s.name       = r3["name"].ToString();
                        s.country    = r3["country"].ToString();
                        s.city       = r3["city"].ToString();
                        s.supImg     = r3["supImg"].ToString();
                        return(RedirectToAction("xxx", "view", s));
                    }
                }
                else if (role == 3)
                {
                    SqlCommand cmd2 = new SqlCommand();
                    cmd2.CommandType = System.Data.CommandType.Text;
                    cmd2.CommandText = "select * from shopOwner where personalInfoID=" + personalInfoID;
                    cmd2.Connection  = con;
                    r1.Close();
                    SqlDataReader r2 = cmd2.ExecuteReader();

                    shopOwner s = new shopOwner();
                    while (r2.Read())
                    {
                        s.personalInfoID = int.Parse(r2["personalInfoID"].ToString());

                        s.email       = email;
                        s.shopOwnerID = int.Parse(r2["shopOwnerID"].ToString());
                        s.password    = password;
                        s.ownerName   = r2["ownerName"].ToString();
                        s.country     = r2["country"].ToString();
                        s.city        = r2["city"].ToString();
                        s.shopImg     = r2["shopImg"].ToString();
                        s.categoryID  = int.Parse(r2["categoryID"].ToString());
                        con.Close();
                        return(RedirectToAction("xxx", "view2", s));
                    }
                }
                con.Close();
                //return RedirectToAction("Index2", "view2", s);
            }

            return(View());
        }
Example #6
0
        public ActionResult home(consumer consumer)
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";

            //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=SouqZone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            //con.ConnectionString = "Data Source=DESKTOPcon.ConnectionString =@"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";J0TTRBH\\SQLEXPRESS;Initial Catalog=souqzone;Integrated Security=True";
            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection  = con;
            cmd.CommandText = "getConsumerShops";
            cmd.Parameters.AddWithValue("@id", consumer.consumerID);
            SqlDataReader r = cmd.ExecuteReader();


            List <shopOwner> l = new List <shopOwner>();


            while (r.Read())
            {
                shopOwner s = new shopOwner();
                s.shopName    = r["shopName"].ToString();
                s.shopImg     = r["shopImg"].ToString();
                s.consumerID  = int.Parse(r["consumerID"].ToString());
                s.shopOwnerID = int.Parse(r["shopOwnerID"].ToString());
                s.categoryID  = int.Parse(r["categoryID"].ToString());
                //s.rate = float.Parse(r["rate"].ToString());
                Session["consumerID"] = int.Parse(r["consumerID"].ToString());
                l.Add(s);
            }
            ViewBag.st1 = l;
            r.Close();


            SqlCommand cmd2 = new SqlCommand();

            cmd2.CommandType = System.Data.CommandType.StoredProcedure;
            cmd2.Connection  = con;
            cmd2.CommandText = "getShopsOffers";
            cmd2.Parameters.AddWithValue("@id", consumer.consumerID);
            SqlDataReader r2 = cmd2.ExecuteReader();


            List <shopOwner> l2 = new List <shopOwner>();


            while (r2.Read())
            {
                shopOwner s = new shopOwner();
                s.shopName     = r2["shopName"].ToString();
                s.shopImg      = r2["shopImg"].ToString();
                s.discount     = float.Parse(r2["discount"].ToString());
                s.city         = r2["city"].ToString();
                s.categoryID   = int.Parse(r2["categoryID"].ToString());
                s.shopOwnerID  = int.Parse(r2["shopOwnerID"].ToString());
                s.categoryType = r2["categoryType"].ToString();

                // s.discount = r2["discount"] != null ? double.Parse(r2["discount"].ToString()) : 0;
                l2.Add(s);
            }
            ViewBag.st2 = l2;

            con.Close();



            return(View(l));
        }
Example #7
0
        public ActionResult Index2(int shopOnwerId)
        {
            SqlConnection con = new SqlConnection();

            //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";

            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection  = con;//بربط ال command على الداتابيز
            cmd.CommandText = "getshopOwner";
            cmd.Parameters.AddWithValue("@hisPersonalinfoID", shopOnwerId);
            SqlDataReader r  = cmd.ExecuteReader();
            shopOwner     lt = new shopOwner();

            while (r.Read())
            {
                lt.shopName       = r["shopName"].ToString();
                lt.shopImg        = r["shopImg"].ToString();
                lt.shopOwnerID    = int.Parse(r["shopOwnerID"].ToString());
                lt.personalInfoID = int.Parse(r["personalInfoID"].ToString());
                lt.email          = Session["email"].ToString();
                lt.categoryID     = r["categoryID"].ToString() == "" ? 1 : int.Parse(r["categoryID"].ToString());
            }

            // ViewBag.supplierData = lt;
            r.Close();
            //-----------------------------------------------------
            SqlCommand cmd2 = new SqlCommand();

            cmd2.CommandType = System.Data.CommandType.Text;
            cmd2.Connection  = con;//بربط ال command على الداتابيز
            cmd2.CommandText = "select * from product where product.shopOwnerID=" + shopOnwerId;
            SqlDataReader  r2  = cmd2.ExecuteReader();
            List <product> lt1 = new List <product>();

            while (r2.Read())
            {
                product i = new product();
                i.name        = r2["name"].ToString();
                i.picture     = r2["picture"].ToString();
                i.shopOwnerID = int.Parse(r2["shopOwnerID"].ToString());
                i.categoryID  = int.Parse(r2["categoryID"].ToString());
                i.price       = float.Parse(r2["price"].ToString());
                i.productID   = int.Parse(r2["productID"].ToString());
                lt1.Add(i);
            }

            r2.Close();
            //-------------------------------------------------------

            /* SqlCommand cmd3 = new SqlCommand();
             * cmd3.CommandType = System.Data.CommandType.StoredProcedure;
             * cmd3.Connection = con;
             * cmd3.CommandText = "getSupplierPackage";
             * cmd3.Parameters.AddWithValue("@hisPersonalinfoID", id);
             * SqlDataReader r3 = cmd3.ExecuteReader();
             * List<package> lt3 = new List<package>();
             * while (r3.Read())
             * {
             *   package sp = new package();
             *   sp.img = r3["img"].ToString();
             *   sp.name = r3["name"].ToString();
             *   sp.price = float.Parse(r3["price"].ToString());
             *   sp.details = r3["details"].ToString();
             *   sp.supplierID = int.Parse(r3["supplierID"].ToString());
             *   sp.categoryID = int.Parse(r3["categoryID"].ToString());
             *   sp.packageID = int.Parse(r3["packageID"].ToString());
             *
             *   lt3.Add(sp);
             * }
             * r3.Close();*/
            r2.Close();

            //ViewBag.shopOwnerItems = lt1;
            ViewBag.package = lt1;
            //  ViewBag.suppackage = lt3;

            SqlCommand cmd4 = new SqlCommand();

            cmd4.CommandType = System.Data.CommandType.Text;
            cmd4.Connection  = con;
            cmd4.CommandText = "select name,picture,price,ShopOwnerOffers.description,ShopOwnerOffers.location ,offerID,ShopOwnerOffers.productID,ShopOwnerOffers.shopOwnerID from ShopOwnerOffers , product where product.productID=ShopOwnerOffers.productID";
            SqlDataReader             r5  = cmd4.ExecuteReader();
            List <shopOffersProducts> lt5 = new List <shopOffersProducts>();

            while (r5.Read())
            {
                shopOffersProducts sp1 = new shopOffersProducts();
                sp1.picture     = r5["picture"].ToString();
                sp1.name        = r5["name"].ToString();
                sp1.price       = float.Parse(r5["price"].ToString());
                sp1.description = r5["description"].ToString();
                sp1.location    = r5["location"].ToString();
                sp1.offerID     = int.Parse(r5["offerID"].ToString());
                sp1.productID   = int.Parse(r5["productID"].ToString());
                sp1.shopOwnerID = int.Parse(r5["shopOwnerID"].ToString());

                lt5.Add(sp1);
            }

            ViewBag.supoffers = lt5;
            r5.Close();
            SqlCommand getMsg = new SqlCommand();

            getMsg.CommandType = System.Data.CommandType.Text;
            getMsg.Connection  = con;
            getMsg.CommandText = "	select distinct * from chat where mto = '"+ lt.email + "'  order by msgID desc";
            SqlDataReader r6 = getMsg.ExecuteReader();

            if (!r6.HasRows)
            {
                ViewBag.MyMsg = null;
            }
            else
            {
                List <chat> allChat = new List <chat>();
                while (r6.Read())
                {
                    if (allChat.FirstOrDefault(c => c.mfrom == r6["mfrom"].ToString()) == null)
                    {
                        chat chat = new chat();
                        //chat.msgID = int.Parse(r6["msgID"].ToString());
                        chat.mdate      = r6["mdate"].ToString();
                        chat.mfrom      = r6["mfrom"].ToString();
                        chat.mto        = r6["mto"].ToString();
                        chat.msgcontent = r6["msgcontent"].ToString();
                        allChat.Add(chat);
                    }
                    else
                    {
                        break;
                    }
                    //if (allChat.FirstOrDefault(c => c.mfrom == int.Parse(r6["mfrom"].ToString())) == null)
                    //{

                    // }
                }
                ViewBag.MyMsg = allChat;
            }


            Session["shopOwner"] = shopOnwerId;

            r6.Close();

            //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            SqlCommand cmd6 = new SqlCommand();

            cmd6.CommandType = System.Data.CommandType.StoredProcedure;
            cmd6.Connection  = con;//بربط ال command على الداتابيز
            cmd6.CommandText = "getshopsstatistaics";
            cmd6.Parameters.AddWithValue("@shopOwnerID", 1);
            SqlDataReader    r7          = cmd6.ExecuteReader();
            List <DataPoint> dataPoints1 = new List <DataPoint>();

            while (r7.Read())
            {
                DataPoint d = new DataPoint(r7["month"].ToString(), int.Parse(r7["procount"].ToString()));

                dataPoints1.Add(d);
            }
            ViewBag.DataPoints1 = JsonConvert.SerializeObject(dataPoints1);
            // ViewBag.supplierData = lt;
            r7.Close();
            SqlCommand cmd5 = new SqlCommand();

            cmd5.CommandType = System.Data.CommandType.Text;
            cmd5.Connection  = con;
            cmd5.CommandText = "select distinct su.supImg,su.supplierID,su.phone,su.city,su.companyName,su.country,su.lat,su.lng,su.name from supplier su,shopOwner sp  where su.categoryID=(select categoryID from shopOwner where shopOwnerID=" + shopOnwerId + ") and su.city=(select city from shopOwner where shopOwnerID=" + shopOnwerId + ")";
            SqlDataReader   r8  = cmd5.ExecuteReader();
            List <supplier> lt7 = new List <supplier>();

            while (r8.Read())
            {
                supplier sp1 = new supplier();
                sp1.supplierID  = int.Parse(r8["supplierID"].ToString());
                sp1.companyName = r8["companyName"].ToString();
                sp1.supImg      = r8["supImg"].ToString();
                sp1.name        = r8["name"].ToString();
                sp1.country     = r8["country"].ToString();
                sp1.city        = (r8["city"].ToString());
                sp1.phone       = r8["phone"].ToString();
                sp1.lat         = float.Parse(r8["lat"].ToString());
                sp1.lng         = float.Parse(r8["lng"].ToString());
                lt7.Add(sp1);
            }
            ViewBag.Suppliers = lt7;
            r8.Close();
            con.Close();

            return(View(lt));
        }
Example #8
0
        public ActionResult Index(int idd)
        {
            SqlConnection con = new SqlConnection();

            //con.ConnectionString = "Data Source=souqzone.database.windows.net;Initial Catalog=souqzone;Integrated Security=False;User ID=souqzone_admin;Password=Az@00000;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            con.ConnectionString = @"Data Source=DESKTOP-J0TTRBH\SQLEXPRESS;Initial Catalog=test99;Integrated Security=True";

            con.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection  = con;//بربط ال command على الداتابيز
            cmd.CommandText = "getSupplier";
            cmd.Parameters.AddWithValue("@hisPersonalinfoID", idd);
            SqlDataReader r  = cmd.ExecuteReader();
            supplier      lt = new supplier();

            while (r.Read())
            {
                lt.name = r["name"].ToString();
                if (r["companyName"].ToString() != null)
                {
                    lt.companyName = r["companyName"].ToString();
                }
                lt.supImg     = r["supImg"].ToString();
                lt.categoryID = r["categoryID"].ToString() == "" ? 1 : int.Parse(r["categoryID"].ToString());
                lt.supplierID = int.Parse(r["supplierID"].ToString());
                lt.email      = Session["email"].ToString();
            }
            ViewBag.supplierData = lt;
            r.Close();
            //-----------------------------------------------------
            SqlCommand cmd2 = new SqlCommand();

            cmd2.CommandType = System.Data.CommandType.StoredProcedure;
            cmd2.Connection  = con;//بربط ال command على الداتابيز
            cmd2.CommandText = "getSupplierCategories";
            cmd2.Parameters.AddWithValue("@hisPersonalinfoID", idd);
            SqlDataReader           r2  = cmd2.ExecuteReader();
            List <supplierCategory> lt2 = new List <supplierCategory>();

            while (r2.Read())
            {
                supplierCategory p = new supplierCategory();
                p.type        = r2["type"].ToString();
                p.CategoryImg = r2["CategoryImg"].ToString();
                lt2.Add(p);
            }
            r2.Close();
            //-------------------------------------------------------
            SqlCommand cmd3 = new SqlCommand();

            cmd3.CommandType = System.Data.CommandType.StoredProcedure;
            cmd3.Connection  = con;
            cmd3.CommandText = "getSupplierPackage";
            cmd3.Parameters.AddWithValue("@supplierID", idd);
            SqlDataReader  r3  = cmd3.ExecuteReader();
            List <package> lt3 = new List <package>();

            while (r3.Read())
            {
                package sp = new package();
                sp.img        = r3["img"].ToString();
                sp.name       = r3["name"].ToString();
                sp.price      = float.Parse(r3["price"].ToString());
                sp.details    = r3["details"].ToString();
                sp.supplierID = int.Parse(r3["supplierID"].ToString());
                sp.categoryID = int.Parse(r3["categoryID"].ToString());
                sp.packageID  = int.Parse(r3["packageID"].ToString());

                lt3.Add(sp);
            }
            r3.Close();
            r2.Close();

            ViewBag.package    = lt2;
            ViewBag.suppackage = lt3;

            SqlCommand cmd4 = new SqlCommand();

            cmd4.CommandType = System.Data.CommandType.Text;
            cmd4.Connection  = con;
            cmd4.CommandText = "select img,name,price,offers.description,location ,offerID,offers.packageID,package.supplierID from package , offers where package.packageID=offers.packageID";
            SqlDataReader         r5  = cmd4.ExecuteReader();
            List <SupplierOffers> lt5 = new List <SupplierOffers>();

            while (r5.Read())
            {
                SupplierOffers sp1 = new SupplierOffers();
                sp1.img         = r5["img"].ToString();
                sp1.name        = r5["name"].ToString();
                sp1.price       = float.Parse(r5["price"].ToString());
                sp1.description = r5["description"].ToString();
                sp1.location    = r5["location"].ToString();
                sp1.offerID     = int.Parse(r5["offerID"].ToString());
                sp1.packageID   = int.Parse(r5["packageID"].ToString());
                sp1.supplierID  = int.Parse(r5["supplierID"].ToString());
                lt5.Add(sp1);
            }

            ViewBag.supoffers = lt5;
            r5.Close();

            SqlCommand getMsg = new SqlCommand();

            getMsg.CommandType = System.Data.CommandType.Text;
            getMsg.Connection  = con;
            getMsg.CommandText = "	select distinct * from chat where mto = '"+ lt.email + "'  order by msgID desc";
            SqlDataReader r7 = getMsg.ExecuteReader();

            if (!r7.HasRows)
            {
                ViewBag.MyMsg = null;
            }
            else
            {
                List <chat> allChat = new List <chat>();
                while (r7.Read())
                {
                    if (allChat.FirstOrDefault(c => c.mfrom == r7["mfrom"].ToString()) == null)
                    {
                        chat chat = new chat();
                        //chat.msgID = int.Parse(r6["msgID"].ToString());
                        chat.mdate      = r7["mdate"].ToString();
                        chat.mfrom      = r7["mfrom"].ToString();
                        chat.mto        = r7["mto"].ToString();
                        chat.msgcontent = r7["msgcontent"].ToString();
                        allChat.Add(chat);
                    }
                    else
                    {
                        break;
                    }
                    //if (allChat.FirstOrDefault(c => c.mfrom == int.Parse(r6["mfrom"].ToString())) == null)
                    //{

                    // }
                }
                ViewBag.MyMsg = allChat;
            }
            r7.Close();

            Session["supplierID"] = idd;

            SqlCommand cmd5 = new SqlCommand();

            cmd5.CommandType = System.Data.CommandType.Text;
            cmd5.Connection  = con;
            cmd5.CommandText = "select DISTINCT shopOwnerID,shopName,ownerName,shopOwner.phone,shopImg,shopOwner.country,shopOwner.city, shopOwner.lat,shopOwner.lng from shopOwner ,supplier where shopOwner.categoryID = (select categoryID from supplier where supplierID =" + idd + ")and shopOwner.city=(select supplier.city from supplier where supplierID = " + idd + ")";
            SqlDataReader    r6  = cmd5.ExecuteReader();
            List <shopOwner> lt6 = new List <shopOwner>();

            while (r6.Read())
            {
                shopOwner sp1 = new shopOwner();
                sp1.shopOwnerID = int.Parse(r6["shopOwnerID"].ToString());
                sp1.shopName    = r6["shopName"].ToString();
                sp1.shopImg     = r6["shopImg"].ToString();
                sp1.ownerName   = r6["ownerName"].ToString();
                sp1.country     = r6["country"].ToString();
                sp1.city        = (r6["city"].ToString());
                sp1.phone       = r6["phone"].ToString();

                lt6.Add(sp1);
            }

            ViewBag.shops = lt6;



            con.Close();
            return(View(lt));
        }