public ActionResult GetObjectByHash(string hash)
        {
            JsonMessage jm = new JsonMessage();

            try
            {
                if (hash == "" || hash == null)
                {
                    jm.Object = ConstructorToJson(constructor);
                }
                else
                {
                    ConstructorModel _constructor = new ConstructorModel();
                    PaletteModel _palette = new PaletteModel();
                    ParseQueryString(hash, _constructor, _palette);
                    jm.Object = ConstructorToJson(_constructor, _palette);
                }
                jm.Result = true;
                jm.Message = "Операция выполнена успешно";
            }
            catch (Exception ex)
            {
                jm.Result = false;
                jm.Message = ex.Message;
            }

            return Json(jm);
        }
Ejemplo n.º 2
0
        public static ConstructorModel Get()
        {
            ConstructorModel result = null;

            SessionManager sm = new SessionManager();

            object CachedConstructorModel = sm.Get("ConstructorModel");
            if (CachedConstructorModel != null)
            {
                result = CachedConstructorModel as ConstructorModel;
            }
            else
            {
                result = new ConstructorModel();

                sm.Set("ConstructorModel", result);
            }

            return result;
        }
        public void ParseQueryString(string QueryString, ConstructorModel _constructor, PaletteModel _palette)
        {
            NameValueCollection qscoll = HttpUtility.ParseQueryString(QueryString);
            if (qscoll.Count > 0)
            {
                string t = qscoll["t"];
                if (t != null)
                {
                    try
                    {
                        _constructor.SetCurrentModel(t);
                    }
                    catch { }
                }

                string cl = qscoll["cl"];
                if (cl != null) {
                    try
                    {
                        _palette.SetClothById(Convert.ToInt32(cl));
                        _constructor.Model.SetHeight(constructor.Model.Height);
                    }
                    catch { }
                }

                string sh = qscoll["sh"];
                if (sh != null)
                {
                    try
                    {
                        _constructor.Model.SetShapeById(Convert.ToInt32(sh));
                    }
                    catch { }
                }

                string ds = qscoll["ds"];
                if (ds != null)
                {
                    try
                    {
                        _constructor.Model.DriverSide = (DriverSide)Enum.Parse(typeof(DriverSide), ds, true);
                    }
                    catch { }
                }

                string w = qscoll["w"];
                if (w != null)
                {
                    try
                    {
                        _constructor.Model.SetWidth(Convert.ToDouble(w));
                    }
                    catch { }
                }

                string h = qscoll["h"];
                if (h != null)
                {
                    try
                    {
                        _constructor.Model.SetHeight(Convert.ToDouble(h));
                    }
                    catch { }
                }

                string mag = qscoll["mag"];
                if (mag != null)
                {
                    try
                    {
                        _constructor.Model.UseMagnet = Convert.ToBoolean(mag);
                    }
                    catch { }
                }
            }
        }
        private string ConstructorToJson(ConstructorModel _constructor, PaletteModel _palette)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("width", _constructor.Model.Width.ToString());
            dictionary.Add("height", _constructor.Model.Height.ToString());
            dictionary.Add("price_dimention", _constructor.Model.PriceDimention.ToString());
            dictionary.Add("amount", _constructor.Model.Amount.ToString());
            dictionary.Add("cloth_name", _palette.SelectedCloth.Name);
            dictionary.Add("cloth_subname", _palette.SelectedCloth.SubName);
            dictionary.Add("cloth_img", _palette.SelectedCloth.Img);
            dictionary.Add("min_payment", _constructor.Model.MinPayment.ToString());
            dictionary.Add("hash", _constructor.Model.Hash.ToString());

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return serializer.Serialize(dictionary);
        }
 private string ConstructorToJson(ConstructorModel _constructor)
 {
     return ConstructorToJson(_constructor, _constructor.Model.palette);
 }