//
        // GET: /Category/Edit/5

        public ActionResult Edit(int id = 0)
        {
            if (Session["swi"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["swi"] != null && Session["isadmin"] == "no")
            {
                return(RedirectToAction("Index", "Customers"));
            }

            Categories categories = db.category.Find(id);

            if (categories == null)
            {
                return(HttpNotFound());
            }
            Itemadder it = new Itemadder();


            it.p   = new List <Properites>();
            it.pv  = new List <string>();
            it.ind = new List <int>();

            it.item_name = categories.Name;
            it.cat_id    = categories.Cat_Id;
            return(View(it));
        }
示例#2
0
        public ActionResult Newest_Product()
        {
            List <Itemadder> itmAdr_lst = new List <Itemadder>();
            List <Items>     itm_lst    = new List <Items>();
            //---------------
            List <Categories> cat_lst = (from a in dbcat.category select a).ToList();
            List <Items>      it_lst  = (from a in dbitem.item select a).ToList();

            if (it_lst.Count != 0)
            {
                foreach (var i in cat_lst)
                {
                    var reslt = (from t in dbitem.item where t.Cat_Id == i.Cat_Id select t.T_Id).ToList();
                    if (reslt != null && reslt.Count != 0)
                    {
                        int itm_last_id = (from t in dbitem.item where t.Cat_Id == i.Cat_Id select t.T_Id).Max();
                        //-----------make itm
                        Items it = new Items();
                        it.Cat_Id = i.Cat_Id;
                        it.T_Id   = itm_last_id;
                        it.T_Name = (from a in dbitem.item where itm_last_id == a.T_Id select a.T_Name).First();
                        itm_lst.Add(it);
                        //-----------make prop
                        ItemController asd   = new ItemController();
                        Itemadder      itmAd = asd.add_prop_item(it);

                        var g = from a in ratdb.itrat where a.Id == itmAd.item_id select a;
                        foreach (var b in g)
                        {
                            itmAd.up   = b.Up;
                            itmAd.down = b.Down;
                        }
                        int shop_id = (from a in shopit.shopit where a.T_Id == itmAd.item_id select a.S_Id).First();
                        itmAd.shop_name = (from a in shopdb.shop where a.S_Id == shop_id select a.About).First();
                        itmAd.shop_id   = shop_id;
                        //var q_date = from n in dbitem.item
                        //        group n by n.T_Id into g
                        //        select new { AccountId = g.Key, Date = g.Max(t => t.) };
                        //itmAd.time_added = q_date;
                        itmAdr_lst.Add(itmAd);
                    }
                }
            }
            ViewBag.Newest_Product_Got = itmAdr_lst;
            return(View());
        }
        public ActionResult Create(Itemadder categories)
        {
            if (Session["swi"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["swi"] != null && Session["isadmin"] == "no")
            {
                return(RedirectToAction("Index", "Customers"));
            }

            ViewBag.message = "";

            if (ModelState.IsValid)
            {
                //db.category.Add(categories);
                //db.SaveChanges();
                try
                {
                    int id = 0;
                    var q3 = from a in db.category
                             select a;
                    foreach (var a in q3)
                    {
                        id = a.Cat_Id;
                    }
                    Categories ca = new Categories(categories.cat_name);
                    ca.Cat_Id = id + 1;
                    db.category.Add(ca);
                    categories.cat_id = ca.Cat_Id;
                    db.SaveChanges();

                    return(RedirectToAction("Prop", categories));
                }
                catch (Exception e)
                {
                    ViewBag.message = "INVALID ENTER";
                    return(View(categories));
                }
            }

            return(View(categories));
        }
        //
        // GET: /Support/

        public ActionResult Index()
        {
            Itemadder          t = new Itemadder();
            CustomersDBContext c = new CustomersDBContext();

            t.pv         = new List <string>();
            t.ind        = new List <int>();
            t.name_admin = new List <string>();
            var tt = from a in c.customer where a.Admin == 1 select a;

            foreach (var item in tt)
            {
                t.pv.Add(item.E_mail);
                t.name_admin.Add(item.Cust_Nme);
                t.ind.Add(item.Phone);
            }



            return(View(t));
        }
        public ActionResult Prop(Itemadder it)
        {
            if (Session["swi"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["swi"] != null && Session["isadmin"] == "no")
            {
                return(RedirectToAction("Index", "Customers"));
            }


            if (it.ind != null)
            {
                it.ind.Add(it.ind.Count);
                it.pv.Add("Date");
                it.ind.Add(it.ind.Count);
                it.pv.Add("Model");
                it.ind.Add(it.ind.Count);
                it.pv.Add("Image");


                try
                {
                    var s2 = from a in db.category
                             orderby a.Cat_Id descending
                             select a;
                    Categories so = s2.First();
                    it.cat_id = so.Cat_Id;
                    int id = 0;
                    var q3 = from a in pdb.Properites
                             select a;
                    foreach (var a in q3)
                    {
                        id = a.P_Id;
                    }
                    bool exist = false;

                    for (int i = 0; i < it.pv.Count; i++)
                    {
                        exist = false;
                        string x = it.pv[i];
                        var    q = from a in pdb.Properites
                                   where a.P_Name.ToLower() == x.ToLower()
                                   select a;

                        foreach (var b in q)
                        {
                            exist = true;
                            Cat_pro cap = new Cat_pro();
                            cap.Cat_Id = it.cat_id;
                            cap.P_Id   = b.P_Id;
                            catpro.catpro.Add(cap);
                        }
                        if (exist == false)
                        {
                            Properites p = new Properites(it.pv[i]);
                            id++;
                            p.P_Id = id;
                            pdb.Properites.Add(p);
                            pdb.SaveChanges();
                            var eq = from d in pdb.Properites where d.P_Name == p.P_Name select d;

                            Properites r   = eq.First();
                            Cat_pro    cap = new Cat_pro();
                            cap.Cat_Id = it.cat_id;
                            cap.P_Id   = r.P_Id;
                            catpro.catpro.Add(cap);
                        }
                    }
                    pdb.SaveChanges();
                    catpro.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception r)
                {
                    ViewBag.message = "INVALID ENTER";
                    it.ind          = null;
                    return(View(it));
                }
            }
            else
            {
                it.p   = new List <Properites>();
                it.pv  = new List <string>();
                it.ind = new List <int>();
                for (int i = 0; i < it.counter; i++)
                {
                    it.pv.Add("");
                    it.ind.Add(0);
                }
                ViewBag.counter = it.counter;
                return(View(it));
            }
        }
        public ActionResult Edit(Itemadder it)
        {
            if (Session["swi"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["swi"] != null && Session["isadmin"] == "no")
            {
                return(RedirectToAction("Index", "Customers"));
            }

            ViewBag.message = "";
            if (it.pv != null)
            {
                if (it.pv.Contains("") || it.pv.Contains(null))
                {
                    return(RedirectToAction("Index"));
                }
                try
                {
                    List <int> ignore = new List <int>();
                    int        id     = 0;
                    var        e      = from a in pdb.Properites
                                        select a;
                    foreach (var a in e)
                    {
                        id = a.P_Id;
                    }
                    Categories cat = new Categories(it.cat_name);
                    cat.Cat_Id          = it.cat_id;
                    db.Entry(cat).State = EntityState.Modified;
                    db.SaveChanges();

                    bool exist = false;
                    for (int i = 0; i < it.pv.Count; i++)
                    {
                        string x  = it.pv[i];
                        var    q1 = from a in pdb.Properites
                                    where a.P_Name.ToLower() == x.ToLower()
                                    select a;
                        foreach (var b in q1)
                        {
                            exist = true;
                            //Cat_pro cap = new Cat_pro();
                            //cap.Cat_Id = it.cat_id;
                            //cap.P_Id = b.P_Id;
                            //catpro.catpro.Add(cap);
                            ignore.Add(b.P_Id);
                        }
                        if (exist == false)
                        {
                            Properites p = new Properites(it.pv[i]);
                            id++;
                            p.P_Id = id;
                            ignore.Add(p.P_Id);
                            Cat_pro cap = new Cat_pro();
                            cap.Cat_Id = it.cat_id;
                            cap.P_Id   = p.P_Id;
                            catpro.catpro.Add(cap);
                            pdb.Properites.Add(p);
                        }
                    }


                    var ee = from a in catpro.catpro
                             where a.Cat_Id == it.cat_id
                             select a;

                    foreach (var t in ee)
                    {
                        if (ignore.Contains(t.P_Id))
                        {
                        }

                        else
                        {
                            Properites d2 = (from a in pdb.Properites where a.P_Name.ToLower() == "model" select a).First();
                            Properites d3 = (from a in pdb.Properites where a.P_Name.ToLower() == "date" select a).First();
                            Properites d4 = (from a in pdb.Properites where a.P_Name.ToLower() == "image" select a).First();
                            if (t.P_Id != d2.P_Id && t.P_Id != d3.P_Id && t.P_Id != d4.P_Id)
                            {
                                catpro.catpro.Remove(t);
                            }
                        }
                    }



                    /* Categories cat = new Categories(it.cat_name);
                     * cat.Cat_Id = it.cat_id;
                     * db.Entry(cat).State = EntityState.Modified;
                     * db.SaveChanges();*/



                    pdb.SaveChanges();
                    catpro.SaveChanges();
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch { ViewBag.message = "INVALID ENTER"; return(View(it)); }
            }
            else
            {
                it.p   = new List <Properites>();
                it.pv  = new List <string>();
                it.ind = new List <int>();
                int counter = 0;

                it.item_name = it.cat_name;

                var q6 = from s in catpro.catpro
                         where s.Cat_Id == it.cat_id

                         select s;


                foreach (var d in q6)
                {
                    Properites ty = (from a in pdb.Properites where a.P_Id == d.P_Id select a).First();
                    if (ty.P_Name.ToLower() != "date" && ty.P_Name.ToLower() != "model" && ty.P_Name.ToLower() != "image")
                    {
                        counter++;
                        it.ind.Add(d.P_Id);
                    }
                }
                int y  = 0;
                var q5 = from s in pdb.Properites

                         select s;

                foreach (var a in q5)
                {
                    if (it.ind.Contains(a.P_Id))
                    {
                        it.p.Add(a);
                        it.pv.Add(a.P_Name);
                    }
                }


                ViewBag.number = counter;
                return(View(it));
            }
        }
示例#7
0
        public ActionResult MostRated_Product()
        {
            List <Itemadder> itmAdr_lst = new List <Itemadder>();
            List <Items>     itm_lst    = new List <Items>();
            //---------------
            List <Categories> cat_lst = (from a in dbcat.category select a).ToList();
            List <Items>      it_lst  = (from a in dbitem.item select a).ToList();

            if (it_lst.Count != 0)
            {
                foreach (var i in cat_lst)
                {
                    var reslt = (from t in dbitem.item where t.Cat_Id == i.Cat_Id select t.T_Id).ToList();
                    if (reslt != null && reslt.Count != 0)
                    {
                        var  itms_dd       = from t in dbitem.item where t.Cat_Id == i.Cat_Id select t.T_Id;
                        int  maxRate       = int.MinValue;
                        int  maxRate_itmID = 0;
                        bool isAnyRated    = false;
                        int  id_lst_itm    = 0;
                        foreach (var id in itms_dd)
                        {
                            var iteeasd = from a in ratdb.itrat where id == a.Id select a;
                            if (iteeasd != null && iteeasd.ToList().Count != 0)
                            {
                                Item_rate itrt = (from a in ratdb.itrat where id == a.Id select a).First();
                                int       r    = itrt.Up - itrt.Down;
                                if (maxRate < r)
                                {
                                    maxRate       = r;
                                    maxRate_itmID = id;
                                }
                                isAnyRated = true;
                            }
                            id_lst_itm = id;
                        }
                        if (!isAnyRated)
                        {
                            maxRate_itmID = id_lst_itm;
                        }
                        //-----------make itm
                        Items it = new Items();
                        it.Cat_Id = i.Cat_Id;
                        if (maxRate_itmID != null && maxRate_itmID != 0)
                        {
                            it.T_Id   = maxRate_itmID;
                            it.T_Name = (from a in dbitem.item where maxRate_itmID == a.T_Id select a.T_Name).First();
                            itm_lst.Add(it);
                            //-----------make prop
                            ItemController asd   = new ItemController();
                            Itemadder      itmAd = asd.add_prop_item(it);

                            var g = from a in ratdb.itrat where a.Id == itmAd.item_id select a;
                            foreach (var b in g)
                            {
                                itmAd.up   = b.Up;
                                itmAd.down = b.Down;
                            }
                            int shop_id = (from a in shopit.shopit where a.T_Id == itmAd.item_id select a.S_Id).First();
                            itmAd.shop_name = (from a in shopdb.shop where a.S_Id == shop_id select a.About).First();
                            itmAd.shop_id   = shop_id;
                            //itmAd.time_added =
                            itmAdr_lst.Add(itmAd);
                        }
                    }
                }
            }
            ViewBag.MostRated_Product_Got = itmAdr_lst;
            return(View());
        }