Пример #1
0
        public static List <string> GetFeatureList(product_features p_feature)
        {
            List <string> output = new List <string>();

            foreach (var kv in product_feature_to_string)
            {
                if (kv.Key(p_feature))
                {
                    output.Add(GetFeatureDict()[kv.Value]);
                }
            }
            return(output);
        }
Пример #2
0
        public ActionResult AddProduct(product pr, string sMale, string sFemale, product_features pf, string sleeveLong, string sleeveShort, int[] size, int[] color, product_info pi, HttpPostedFileBase[] img)
        {
            if (sleeveLong == "long")
            {
                pf.sleeve_id = 1;
            }
            else if (sleeveShort == "short")
            {
                pf.sleeve_id = 2;
            }

            if (pf.material_id == 0)
            {
                pf.material_id = null;
            }

            if (pf.neckline_id == 0)
            {
                pf.neckline_id = null;
            }

            if (pf.pattern_id == 0)
            {
                pf.pattern_id = null;
            }

            if (pf.pocket_id == 0)
            {
                pf.pocket_id = null;
            }

            if (pf.upper_fit_id == 0)
            {
                pf.pocket_id = null;
            }

            if (pf.base_id == 0)
            {
                pf.base_id = null;
            }

            if (pf.bottom_fit_id == 0)
            {
                pf.bottom_fit_id = null;
            }


            eshop_entities.product_features.Add(pf);
            eshop_entities.SaveChanges();



            if (sMale == "male")
            {
                pr.sex_id = 1;
            }
            else if (sFemale == "female")
            {
                pr.sex_id = 2;
            }

            if (pr.sub_category_id == 0)
            {
                pr.sub_category_id = null;
            }


            pr.product_features_id = pf.id;

            pr.approved = true;

            eshop_entities.product.Add(pr);
            eshop_entities.SaveChanges();

            for (int i = 0; i < size.Length; i++)
            {
                size_prod_pivot sp = new size_prod_pivot();
                sp.size_id    = (byte)size[i];
                sp.product_id = pf.id;

                eshop_entities.size_prod_pivot.Add(sp);
                eshop_entities.SaveChanges();
            }

            for (int i = 0; i < color.Length; i++)
            {
                color_prod_pivot cp = new color_prod_pivot();
                cp.color_id   = (byte)color[i];
                cp.product_id = pf.id;

                eshop_entities.color_prod_pivot.Add(cp);
                eshop_entities.SaveChanges();
            }

            for (int i = 0; i < img.Length; i++)
            {
                string path       = "";
                string path_small = "";

                if (img[i] != null)
                {
                    Image myImg = Image.FromStream(img[i].InputStream);

                    Bitmap bm = new Bitmap(myImg, 600, 750);
                    path = "/Content/images/" + Guid.NewGuid() + System.IO.Path.GetExtension(img[i].FileName);
                    bm.Save(Server.MapPath(path));

                    Bitmap bm_small = new Bitmap(myImg, 100, 125);
                    path_small = "/Content/images/" + Guid.NewGuid() + "small" + System.IO.Path.GetExtension(img[i].FileName);
                    bm.Save(Server.MapPath(path_small));
                }

                elite_shopping.Models.picture pc = new picture();
                pc.medium     = path;
                pc.product_id = pf.id;

                eshop_entities.picture.Add(pc);
                eshop_entities.SaveChanges();

                elite_shopping.Models.picture pc_small = new picture();
                pc_small.small      = path_small;
                pc_small.product_id = pf.id;

                eshop_entities.picture.Add(pc_small);
                eshop_entities.SaveChanges();
            }


            return(RedirectToAction("Product"));
        }
Пример #3
0
        public static List <KeyValuePair <string, KeyValuePair <string, bool> > > GetFeatureKVList(product_features p_feature)
        {
            List <KeyValuePair <string, KeyValuePair <string, bool> > > output = new List <KeyValuePair <string, KeyValuePair <string, bool> > >();

            foreach (var kv in product_feature_to_string)
            {
                string name = kv.Value;
                string text = GetFeatureDict()[name];
                bool   ret  = kv.Key(p_feature);
                output.Add(new KeyValuePair <string, KeyValuePair <string, bool> > (
                               name,
                               new KeyValuePair <string, bool>(text, ret)
                               ));
            }
            return(output);
        }
Пример #4
0
        public JsonResult sort(product_features pf, string fit_id, string[] color, string[] size, string sleeve, string category_id, product[] prod_arg)
        {
            elite_shoppingEntities eshopping_entities = new elite_shoppingEntities();

            eshopping_entities.Configuration.ProxyCreationEnabled = false;

            byte sl = 0;

            if (sleeve == "long")
            {
                sl = 1;
            }
            else
            {
                sl = 0;
            }

            List <product_features> s_product_features = eshopping_entities.product_features.ToList();
            //List<product> prod = eshopping_entities.product.AsNoTracking().ToList();
            List <product>          prod          = prod_arg.ToList();
            List <size_prod_pivot>  size_product  = eshopping_entities.size_prod_pivot.ToList();
            List <color_prod_pivot> color_product = eshopping_entities.color_prod_pivot.ToList();
            bool unFeature = true;


            if (pf.material_id > 0)
            {
                s_product_features = s_product_features.Where(x => x.material_id == pf.material_id).ToList();
                unFeature          = false;
            }

            if (pf.neckline_id > 0)
            {
                s_product_features = s_product_features.Where(x => x.neckline_id == pf.neckline_id).ToList();
                unFeature          = false;
            }

            if (pf.pattern_id > 0)
            {
                s_product_features = s_product_features.Where(x => x.pattern_id == pf.pattern_id).ToList();
                unFeature          = false;
            }

            if (pf.pocket_id > 0)
            {
                s_product_features = s_product_features.Where(x => x.pocket_id == pf.pocket_id).ToList();
                unFeature          = false;
            }

            if (pf.sleeve_id > 0)
            {
                s_product_features = s_product_features.Where(x => x.sleeve_id == sl).ToList();
                unFeature          = false;
            }

            try
            {
                if (int.Parse(fit_id) > 0)
                {
                    s_product_features = s_product_features.Where(x => x.upper_fit_id == byte.Parse(fit_id) || x.bottom_fit_id == byte.Parse(fit_id)).ToList();
                    unFeature          = false;
                }
            }
            catch (Exception ex)
            {
            }

            if (pf.base_id > 0)
            {
                s_product_features = s_product_features.Where(x => x.base_id == pf.base_id).ToList();
                unFeature          = false;
            }

            if (s_product_features.Count > 0)
            {
                try
                {
                    prod = prod.Where(x => x.sub_category_id == byte.Parse(category_id)).ToList();
                }
                catch (Exception ex)
                {
                }

                List <IEnumerable <product> > p_instance = new List <IEnumerable <product> >();

                if (!unFeature)
                {
                    foreach (product_features item in s_product_features)
                    {
                        p_instance.Add(prod.Where(x => x.product_features_id == item.id).ToList());
                    }

                    prod.Clear();

                    foreach (var item in p_instance)
                    {
                        prod = prod.Union(item).ToList();
                    }
                }


                try
                {
                    if (size.Length > 0 && color.Length > 0 && prod.Count > 0)
                    {
                        foreach (product item in prod)
                        {
                            size_product = size_product.Where(x => x.product_id == item.id).ToList();
                        }

                        foreach (product item in prod)
                        {
                            color_product = color_product.Where(x => x.product_id == item.id).ToList();
                        }

                        foreach (string item in size)
                        {
                            size_product = size_product.Union(size_product.Where(x => x.size_id == int.Parse(item))).ToList();
                        }

                        foreach (string item in color)
                        {
                            color_product = color_product.Union(color_product.Where(x => x.color_id == int.Parse(item))).ToList();
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                List <IEnumerable <picture> > pic_instance = new List <IEnumerable <picture> >();
                List <picture> pics = eshopping_entities.picture.ToList();

                foreach (product item in prod)
                {
                    //pics = pics.Union(pics.Where(x=>x.product_id==item.id)).ToList();
                    pic_instance.Add(pics.Where(x => x.product_id == item.id).ToList());
                }

                pics.Clear();

                foreach (var item in pic_instance)
                {
                    pics = pics.Union(item).ToList();
                }

                List <discount> dscount = new List <discount>();

                if (pics.Count > 0)
                {
                    return(Json(new { data = prod, pictures = pics }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new EmptyResult(), JsonRequestBehavior.AllowGet));
        }