Exemplo n.º 1
0
        public ActionResult LetterTypes(LetterTypeModel lettertype)
        {
            ClearAlerts("Alert LetterTypes M", 3);

            // get the list of letter types from Session
            List <LetterTypeModel> lettertypes = getLetterTypes();

            // we'll need to validate the data
            if (lettertypes.Exists(lt => lt.Name == lettertype.Name))
            {
                Session.Add("Alert LetterTypes M2", "Letter type name already exists. Please use a distinct name.");
            }
            if (lettertypes.Exists(lt => lt.Pattern == lettertype.Pattern))
            {
                Session.Add("Alert LetterTypes M3", "Letter type pattern already used. Please use a distinct pattern.");
            }
            if (Session["Alert LetterTypes M2"] != null || Session["Alert LetterTypes M3"] != null)
            {
                return(View());
            }

            lettertype.Id = LetterTypeProcessor.CreateLetterType(lettertype.Name, (int)Session["Language"], lettertype.Description, lettertype.Pattern);
            lettertypes.Add(lettertype);

            // lastly, we'll need to clear the values in the field
            ModelState.SetModelValue("Name", new ValueProviderResult("", "", ModelState["Name"].Value.Culture));
            ModelState.SetModelValue("Description", new ValueProviderResult("", "", ModelState["Description"].Value.Culture));

            return(View());
        }
Exemplo n.º 2
0
        //  Action Result methods for Letter Type Views
        #region Letter Types
        public ActionResult LetterTypes()
        {
            ClearAlerts("Alert LetterTypes M", 3);

            // the fail cases for this page is if there isn't a User or a language isn't selected - redirect to Index
            if (Session["User"] == null || Session["Language"] == null)
            {
                return(RedirectToAction("Index", "Language"));
            }

            // this page needs to return a list of letter types
            List <LetterTypeModel> lettertypes = getLetterTypes();

            // now, if the list isn't empty, the page should load it
            if (lettertypes.Count != 0)
            {
                return(View());
            }

            // at this point lettertypes is definitively empty, so we'll autogenerate two letter types - consonants and vowels
            LetterTypeProcessor.CreateLetterType("Consonant", (int)Session["Language"], "Basic letter type, such as b, c & d in English", 'c');
            LetterTypeProcessor.CreateLetterType("Vowel", (int)Session["Language"], "Basic letter type, such as a, e, and i in English", 'v');
            Session.Add("Alert LetterTypes M1", "There were no existing letter types - Consonant & Vowel have been auto-generated.");

            // now load the new letter types from the database
            List <LetterTypeDataModel> dmLetterTypes = LetterTypeProcessor.LoadLetterTypes((int)Session["Language"]);

            foreach (LetterTypeDataModel lettertype in dmLetterTypes)
            {
                lettertypes.Add(new LetterTypeModel
                {
                    Id          = lettertype.Id,
                    Name        = lettertype.Name,
                    Description = lettertype.Description
                });
            }

            // assign lettertypes to Session
            Session["Letter Types"] = lettertypes;

            // return the view
            return(View());
        }