public PartialViewResult product_changeParameter(int nomenclatureId, string parameter, string value, string currentParameters)
        {
            Product product= new Product();

            product = DAL.GetProduct(nomenclatureId, DAL.GetNewFeaturesSetId(nomenclatureId, parameter, value, currentParameters));

            return PartialView("product_changeParameter", product);
        }
        public static List<Product> GetProducts(int GroupId)
        {
            List<Product> products = new List<Product>();
            using (DBContext db = new DBContext())
            {
                List<int> _nomenclatureIds = db.NomenclatureInStores.Where(x => x.Amount > 0).Select(x => x.NomenclatureId).ToList();
                List<int> nomenclatureIds = new List<int>();

                foreach (int _nomenclatureId in _nomenclatureIds)
                {
                    bool a = nomenclatureIds.Exists(x => x == _nomenclatureId);
                    if (!nomenclatureIds.Exists(x => x == _nomenclatureId)) nomenclatureIds.Add(_nomenclatureId);
                }

                foreach (int nomenclatureId in nomenclatureIds)
                {
                    Product product = new Product();
                    product.Id = nomenclatureId;
                    product.Name = db.Nomenclature.Find(nomenclatureId).Name;
                    product.Image = db.NomenclatureViews.FirstOrDefault(x => x.NomenclatureId == nomenclatureId).Image + "1.jpg";
                    product.currentParameters = db.NomenclatureInStores.FirstOrDefault(x => x.NomenclatureId == nomenclatureId && x.Amount > 0).FeaturesSet.ToString();

                    if (db.Nomenclature.Find(nomenclatureId).GroupId == GroupId) products.Add(product);
                }
            }

            return products;
        }
        public static Product GetProduct(int NomenclatureId, int FeaturesSetId)
        {
            Product product = new Product();
            List<string> gallery = new List<string>();

            using (DBContext db = new DBContext())
            {

                product.Id = NomenclatureId;
                product.Name = db.Nomenclature.Find(NomenclatureId).Name.ToString();
                product.Description = db.Nomenclature.Find(NomenclatureId).Description;

                int counter = 1;
                string path = AppDomain.CurrentDomain.BaseDirectory + @"/Content/nomenclature/pictures_small/";
                string filename = db.NomenclatureViews.FirstOrDefault(x => x.NomenclatureId == NomenclatureId && x.FeaturesSetId == FeaturesSetId).Image.ToString() + counter + ".jpg";

                product.Image = filename;

                while (File.Exists(path + filename))
                {
                    gallery.Add(filename);
                    counter++;
                    filename = db.NomenclatureViews.FirstOrDefault(x => x.NomenclatureId == NomenclatureId && x.FeaturesSetId == FeaturesSetId).Image.ToString() + counter + ".jpg";
                }

                product.Gallery = gallery;

                List<Parameter> parameters = new List<Parameter>();
                for (int i = 0; i < 2; i++)
                {
                    Parameter par = new Parameter();
                    par.Id = i + 1;
                    par.Name = db.Characteristics.Find(i + 1).Name;
                    par.Values = new List<string>();
                    par.SelectedValue = string.Empty;
                    parameters.Add(par);
                }
                product.Parameters = parameters;

                List<int> FeaturesSets = db.NomenclatureInStores.Where(x => x.NomenclatureId == NomenclatureId && x.Amount > 0).Select(x => x.FeaturesSet).ToList();
                foreach (var item in FeaturesSets)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        product.Parameters[i].SelectedValue = db.FeaturesOfNomenclatures.FirstOrDefault(x => x.FeaturesSetId == FeaturesSetId && x.CharacteristicId == (i + 1)).Value;
                        product.Parameters[i].Values.AddRange(db.FeaturesOfNomenclatures.Where(x => x.CharacteristicId == (i+1) && x.FeaturesSetId == item).Select(x => x.Value).ToList());
                    }
                }

                for (int i = 0; i < 2; i++)
                {
                    List<string> _values = new List<string>();

                    for (int k = 0; k < product.Parameters[i].Values.Count; k++)
                    {
                        if (_values == null)
                        {
                            _values = new List<string>() { product.Parameters[i].Values[k] };
                        }
                        else
                        {
                            if (!_values.Exists(x => x == product.Parameters[i].Values[k])) _values.Add(product.Parameters[i].Values[k]);
                        }

                    }

                    product.Parameters[i].Values = _values;
                }

                string currentParameters = string.Empty;
                List<Characteristic> characteristics = new List<Characteristic>();
                characteristics = db.Characteristics.ToList();
                foreach (Characteristic charactericstic in characteristics)
                    currentParameters += charactericstic.Name + "=" + db.FeaturesOfNomenclatures.FirstOrDefault(x => x.FeaturesSetId == FeaturesSetId && x.CharacteristicId == charactericstic.Id).Value + " ";

                product.currentParameters = currentParameters.Substring(0, currentParameters.Count() - 1);

            }

            return product;
        }