Esempio n. 1
0
        public ActionResult GetResult(Selection selection)
        {
            //Convert the object from the page in a string array
            string[] selectedCheckBoxes = selection.Ids;

            List <int> stylePhotographList = new List <int>();
            List <int> brandSetList        = new List <int>();
            List <int> wordingList         = new List <int>();

            //Work on every checkbox that the page sent to us
            for (int i = 0; i < selectedCheckBoxes.Length; i++)
            {
                //Clean the string
                selectedCheckBoxes[i] = selectedCheckBoxes[i].Replace("chb_", string.Empty);
                //Split the name of the checkbox to know wich type it is and its Id
                string[] temp = selectedCheckBoxes[i].Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);

                //For each type we act in different way
                switch (temp[0])
                {
                //For StylePhotograph
                case "SP":
                    //We get the fashionflavor of the StylePhotograph selected
                    stylePhotographList.Add(Convert.ToInt32(temp[1]));
                    break;

                //For BrandSet
                case "BS":
                    //We get the fashionflavor of the BrandSet selected
                    brandSetList.Add(Convert.ToInt32(temp[1]));
                    break;

                //For Wording
                case "W":
                    //We get the fashionflavor of the BrandSet selected
                    wordingList.Add(Convert.ToInt32(temp[1]));
                    break;
                }
            }

            QuizController       qc     = new QuizController(fashionFlavorRepository, stylePhotographRepository, brandSetRepository, wordingRepository, new FlavorSelectionService());
            List <FashionFlavor> result = qc.DetermineFlavors(stylePhotographList, brandSetList, wordingList) as List <FashionFlavor>;

            if (result.Count == 2)
            {
                return(Json(new
                {
                    Single = false,
                    FashionFlavor1Id = result[0].Id,
                    FashionFlavor1Name = result[0].Name,
                    FashionFlavor1Result = 50,
                    FashionFlavor2Id = result[1].Id,
                    FashionFlavor2Name = result[1].Name,
                    FashionFlavor2Result = 50
                }));
            }
            return(Json(new
            {
                Single = true,
                FashionFlavor1Id = result[0].Id,
                FashionFlavor1Name = result[0].Name,
                FashionFlavor1Result = 50
            }));
        }