Exemplo n.º 1
0
        public ActionResult Login(string validationMessage = null, string redirectionUrl = null)
        {
            string redirectUrl = WebUtility.UrlDecode(redirectionUrl);
            bool   webauth     = BoolParser.Parse(Db.SscisParam.Where(p => p.ParamKey.Equals(SSCISParameters.WEBAUTHON, StringComparison.OrdinalIgnoreCase)).Single().ParamValue);
            string testAuthParametr;

            if (webauth)
            {
                string webAuth = Db.SscisParam.Where(p => p.ParamKey.Equals(SSCISParameters.WEBAUTHURL)).Single().ParamValue.ToString();

                if (redirectionUrl != null)
                {
                    testAuthParametr = webAuth + "?redirect=" + WebUtility.UrlEncode(redirectionUrl);
                }
                else
                {
                    testAuthParametr = webAuth;
                }


                return(Redirect(testAuthParametr));
            }
            ViewBag.Title = "Login";
            MetaLogin model = new MetaLogin
            {
                ValidationMessage = validationMessage,
                RedirectionUrl    = redirectionUrl
            };

            return(View(model));
        }
Exemplo n.º 2
0
        private void UpdateDataBaseZoo(List <string[]> rows)
        {
            ObservableCollection <Animal> collection = new ObservableCollection <Animal>();

            foreach (var row in rows)
            {
                collection.Add(new Animal
                {
                    AnimalName = row[0],
                    Hair       = BoolParser.Parse(row[1])?"+":"-",
                    Feathers   = BoolParser.Parse(row[2]) ? "+" : "-",
                    Eggs       = BoolParser.Parse(row[3]) ? "+" : "-",
                    Milk       = BoolParser.Parse(row[4]) ? "+" : "-",
                    Airbourne  = BoolParser.Parse(row[5]) ? "+" : "-",
                    Aquatic    = BoolParser.Parse(row[6]) ? "+" : "-",
                    Predator   = BoolParser.Parse(row[7]) ? "+" : "-",
                    Toothed    = BoolParser.Parse(row[8]) ? "+" : "-",
                    Backbone   = BoolParser.Parse(row[9]) ? "+" : "-",
                    Breathes   = BoolParser.Parse(row[10]) ? "+" : "-",
                    Venomous   = BoolParser.Parse(row[11]) ? "+" : "-",
                    Fins       = BoolParser.Parse(row[12]) ? "+" : "-",
                    Legs       = int.Parse(row[13]),
                    Tail       = BoolParser.Parse(row[14]) ? "+" : "-",
                    Domestic   = BoolParser.Parse(row[15]) ? "+" : "-",
                    Catsize    = BoolParser.Parse(row[16]) ? "+" : "-",
                    Type       = int.Parse(row[17])
                });
            }
            ObservableCollection <ClassifyAnimal> classify = new ObservableCollection <ClassifyAnimal>();

            classify.Add(new ClassifyAnimal());
            dataGridClassify.ItemsSource = classify;
            dataGrid.ItemsSource         = collection;
        }
Exemplo n.º 3
0
        public ActionResult Create()
        {
            int             userId      = (int)HttpContext.Session.GetInt32("userId");
            List <Approval> approvals   = db.Approval.Where(a => a.IdTutor == userId).ToList();
            List <int>      subjectsIds = new List <int>();

            foreach (Approval app in approvals)
            {
                subjectsIds.Add(app.IdSubject);
            }

            if (!BoolParser.Parse(db.SscisParam.Single(p => p.ParamKey.Equals(SSCISParameters.STANDARTEVENTLENGTH)).ParamValue))
            {
                ViewBag.LessonLength = db.SscisParam.Single(p => p.ParamKey.Equals(SSCISParameters.STANDARTEVENTLENGTH)).ParamValue;
            }
            else
            {
                ViewBag.LessonLength = "2";
            }

            if (db.SscisUser.Find(userId).IdRoleNavigation == db.EnumRole.Single(r => r.Role.Equals(SSCISResources.Resources.ADMIN)))
            {
                ViewBag.SubjectID = new SelectList(db.EnumSubject.Where(s => s.IdParent == null && s.Lesson == false), "Id", "Code");
                ViewBag.TutorID   = new SelectList(db.SscisUser, "Id", "Login");
            }
            else
            {
                ViewBag.SubjectID = new SelectList(db.EnumSubject.Where(s => subjectsIds.Contains(s.Id)), "Id", "Code");
                ViewBag.TutorID   = new SelectList(db.SscisUser.Where(t => t.Id == userId), "Id", "Login");
            }
            return(View());
        }
Exemplo n.º 4
0
        private void zoo_example()
        {
            string path = @"zoo.txt";

            Headers = new string[] {
                "Hair", "Feathers", "Eggs", "Milk", "Airborne", "Aquatic",
                "Predator", "Toothed", "Backbone", "Breathes", "Venomous", "Fins", "Legs", "Tail",
                "Domestic", "Catsize"
            };
            Result = "Animal type";

            List <string[]> rows  = new List <string[]>();
            List <string[]> dummy = new List <string[]>();

            foreach (var animalData in File.ReadAllLines(path))
            {
                List <string> data = new List <string>();
                string[]      line = animalData.Split(',');
                for (int i = 0; i < line.Length; ++i)
                {
                    if (i == 13 || i == 17 || i == 0)
                    {
                        data.Add(line[i]);
                    }
                    else
                    {
                        data.Add(BoolParser.Parse(line[i]).ToString());
                    }
                }
                dummy.Add(data.ToArray());
                data.RemoveAt(0);
                rows.Add(data.ToArray());
            }
            UpdateDataBaseZoo(dummy);
            tcMain.Clear();
            tree = DecisionTreeTools.BuildTree(rows);
            DecisionTreeTools.Prune(tree.NextFalseNode.NextTrueNode.NextFalseNode.NextTrueNode, 1.01);
            DecisionTreeTools.Prune(tree.NextFalseNode.NextTrueNode.NextTrueNode.NextFalseNode, 1.01);
            PrintTree(tree);


            listBoxZoo.Items.Clear();
            listBoxZoo.Items.Add(
                "1 -- (41) aardvark, antelope, bear, boar, buffalo, calf, cavy, cheetah, deer, dolphin, elephant, fruitbat, giraffe, girl, goat, gorilla, hamster, hare, leopard, lion, lynx, mink, mole, mongoose, opossum, oryx, platypus, polecat, pony, porpoise, puma, pussycat, raccoon, reindeer, seal, sealion, squirrel, vampire, vole, wallaby,wolf ");
            listBoxZoo.Items.Add(
                "2 -- (20) chicken, crow, dove, duck, flamingo, gull, hawk, kiwi, lark, ostrich, parakeet, penguin, pheasant, rhea, skimmer, skua, sparrow, swan, vulture, wren ");
            listBoxZoo.Items.Add("3 -- (5) pitviper, seasnake, slowworm, tortoise, tuatara");
            listBoxZoo.Items.Add(
                "4 -- (13) bass, carp, catfish, chub, dogfish, haddock, herring, pike, piranha, seahorse, sole, stingray, tuna ");
            listBoxZoo.Items.Add("5 -- (4) frog, frog, newt, toad ");
            listBoxZoo.Items.Add("6 -- (8) flea, gnat, honeybee, housefly, ladybird, moth, termite, wasp ");
            listBoxZoo.Items.Add(
                "7 -- (10) clam, crab, crayfish, lobster, octopus, scorpion, seawasp, slug, starfish, worm");

            listBoxZoo.Visibility = Visibility.Visible;
        }
Exemplo n.º 5
0
 public SmartWatchDataParser(SmartWatchExcelData fileData, IDataRepository repository) : base(fileData)
 {
     _nameParser           = new StringParser <SmartWatchColumnNames>(SmartWatchColumnNames.Name);
     _priceParser          = new PriceParser <SmartWatchColumnNames>(SmartWatchColumnNames.Price);
     _descriptionParser    = new StringParser <SmartWatchColumnNames>(SmartWatchColumnNames.Description);
     _manufacturerParser   = new ManufacturerParser <SmartWatchColumnNames>(SmartWatchColumnNames.Manufacturer, repository);
     _connectionTypeParser = new ConnectionTypeParser <SmartWatchColumnNames>(SmartWatchColumnNames.InterfaceForConnecting, repository);
     _screenDiagonalParser = new DoubleParser <SmartWatchColumnNames>(SmartWatchColumnNames.ScreenDiagonal);
     _pulsometerParser     = new BoolParser <SmartWatchColumnNames>(SmartWatchColumnNames.Pulsometer);
     _simCardParser        = new BoolParser <SmartWatchColumnNames>(SmartWatchColumnNames.SimCard);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Returns a bool value stored in this object.
 /// </summary>
 public bool AsBool(bool defaultValue = false)
 {
     if (rawObject is bool)
     {
         return((bool)rawObject);
     }
     if (rawObject is string)
     {
         return(BoolParser.Parse(((string)rawObject).ToLower()));
     }
     return(defaultValue);
 }
Exemplo n.º 7
0
        private void Debug_Click(object sender, EventArgs e)
        {
            BddSharp.AST.VarList.ResetDic();

            BoolParser parser = new BoolParser();
            Scanner    sc     = new Scanner();
            TextReader tr     = new StringReader(ExpressionBox.Text);

            CategorizeVariables(VarsBox.Text);

            Ast           = parser.Parse(sc.Scan(tr));
            DebugBox.Text = Ast.print();
        }
Exemplo n.º 8
0
        public void ParseTest()
        {
            BoolParser target = new BoolParser();

            System.Collections.Generic.IEnumerator <BddSharp.Parser.Token> ts = null; // TODO: Initialize to an appropriate value

            IBoolExpr expected = null;
            IBoolExpr actual;

            actual = target.Parse(ts);

            Assert.AreEqual(expected, actual, "BddSharp.Parser.BoolParser.parse did not return the expected value.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 9
0
        public ActionResult Create(MetaEvent model)
        {
            model.Event = new Event();
            if (ModelState.IsValid && model.Date >= DateTime.Now)
            {
                for (int i = 0; i < model.Recurrence; i++)
                {
                    Event newEvent = new Event();
                    newEvent.IdTutorNavigation = db.SscisUser.Find(model.TutorID);
                    newEvent.IdTutor           = model.TutorID;
                    newEvent.IsCancelled       = false;
                    if (newEvent.IdTutorNavigation.IdRoleNavigation.Role.Equals(SSCISResources.Resources.ADMIN))
                    {
                        newEvent.IsAccepted = true;
                    }
                    else
                    {
                        newEvent.IsAccepted = false;
                    }
                    newEvent.IsExtraLesson = false;
                    newEvent.TimeFrom      = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, model.TimeFrom.Hour, model.TimeFrom.Minute, 0);

                    if (!BoolParser.Parse(db.SscisParam.Single(p => p.ParamKey.Equals(SSCISParameters.STANDARTEVENTLENGTH)).ParamValue))
                    {
                        int hour = Convert.ToInt32(db.SscisParam.Where(p => p.ParamKey.Equals(SSCISParameters.STANDARTEVENTLENGTH)).Single().ParamValue);
                        newEvent.TimeTo = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, model.TimeFrom.Hour + hour, model.TimeFrom.Minute, 0);
                    }
                    else
                    {
                        newEvent.TimeTo = model.Event.TimeFrom.AddHours(2);
                    }

                    newEvent.IdSubjectNavigation   = db.EnumSubject.Find(model.SubjectID);
                    newEvent.IdSubject             = (int)model.SubjectID;
                    newEvent.IdApplicantNavigation = null;
                    newEvent.IdApplicant           = null;

                    int increase = i * 7;
                    newEvent.TimeFrom = newEvent.TimeFrom.AddDays(increase);
                    newEvent.TimeTo   = newEvent.TimeTo.AddDays(increase);

                    db.Event.Add(newEvent);
                    db.SaveChanges();
                }
                return(RedirectToAction("TutorEvents", new { created = 1 }));
            }
            return(RedirectToAction("Create"));
        }
Exemplo n.º 10
0
        public BMC()
        {
            CodeInput = new antlr.LexerSharedInputState(new StringReader(String.Empty));

            Lexer  = new BoolLexer(CodeInput);
            Parser = new BoolParser(Lexer);

            ErrorLog = String.Empty;

            BoolProgAST = (CommonAST)Parser.getAST();

            m_BddManager = new BddManager();

            ProgramCFG = new CFG(BoolProgAST, m_BddManager);

            m_PathEdges = new Dictionary <CFGNode, PathEdges>();

            m_SummaryEdges = new Dictionary <CFGNode, Bdd>();
        }
Exemplo n.º 11
0
        public ActionResult HelpMe()
        {
            ViewBag.SubjectID = new SelectList(Db.EnumSubject.Where(s => s.IdParent == null), "Id", "Code");
            int userId = 0;

            if (HttpContext.Session.GetInt32("userId").HasValue)
            {
                userId = (int)HttpContext.Session.GetInt32("userId");;
            }

            bool extraLessonEnable = true;

            extraLessonEnable = BoolParser.Parse(Db.SscisParam.Single(p => p.ParamKey.Equals(SSCISParameters.EXTRALESSONENABLE, StringComparison.OrdinalIgnoreCase)).ParamValue);
            string text = Db.SscisParam.Where(p => p.ParamKey.Equals(SSCISParameters.POTREBUJIPOMOCHTML, StringComparison.OrdinalIgnoreCase)).Single().ParamValue;

            ViewBag.TextHelpMe = WebUtility.HtmlDecode(text);

            ViewBag.Title             = "Potřebuji pomoc";
            ViewBag.PersonalTimeTable = personalTimetable.RenderEvents(Db, userId);
            ViewBag.PublicTimeTable   = timeTableRenderer.RenderPublic(Db);
            ViewBag.ExtraLessonEnable = extraLessonEnable;
            return(View());
        }
Exemplo n.º 12
0
        public void BasicTests()
        {
            var parser = new BoolParser();

            // must evaluate to true
            Assert.True(parser.ParseOrDefault("true"));
            Assert.True(parser.ParseOrDefault("t"));
            Assert.True(parser.ParseOrDefault("yes"));
            Assert.True(parser.ParseOrDefault("ja"));
            Assert.True(parser.ParseOrDefault("1"));
            Assert.True(parser.ParseOrDefault("y"));
            Assert.True(parser.ParseOrDefault("j"));
            Assert.True(parser.ParseOrFallback("", true));

            // must evaluate to false
            Assert.False(parser.ParseOrDefault("false"));
            Assert.False(parser.ParseOrDefault("False"));
            Assert.False(parser.ParseOrDefault("FALSE"));
            Assert.False(parser.ParseOrDefault("F"));
            Assert.False(parser.ParseOrDefault("No"));
            Assert.False(parser.ParseOrDefault("Nein"));
            Assert.False(parser.ParseOrDefault("N"));
            Assert.False(parser.ParseOrDefault(""));
        }
Exemplo n.º 13
0
        private void Execute_Click(object sender, EventArgs e)
        {
            BddSharp.AST.VarList.ResetDic();

            BoolParser parser = new BoolParser();
            Scanner    sc     = new Scanner();
            TextReader tr     = new StringReader(ExpressionBox.Text);

            CategorizeVariables(VarsBox.Text);

            Ast = parser.Parse(sc.Scan(tr));
            BoolExpr.execute(Ast, "foo");


            if (ExpressionBox.Text == string.Empty)
            {
                MessageBox.Show("Error: No expression provided.");
            }
            else
            {
                Thread.Sleep(4000);
                System.Diagnostics.Process.Start("results\\foo.jpg", null);
            }
        }
Exemplo n.º 14
0
        private void AddQuestionToForm(DynamicForm formModel, QuestionDto question)
        {
            IEnumerable <string> options;

            var questionFieldName = question.FieldName;

            switch (question.QuestionType)
            {
            case QuestionType.Text:
                formModel.Add(questionFieldName, string.Empty);
                break;

            case QuestionType.TextArea:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new MultilineTextAttribute(5));
                break;

            case QuestionType.Number:
                formModel.Add(questionFieldName, default(int));
                break;

            case QuestionType.Slider:
                formModel.Add(questionFieldName, default(int));
                formModel.AddAttribute(questionFieldName, new SliderAttribute());
                break;

            case QuestionType.Currency:
                formModel.Add(questionFieldName, default(decimal));
                formModel.AddAttribute(questionFieldName, new DataTypeAttribute(DataType.Currency));
                break;

            case QuestionType.Date:
                formModel.Add(questionFieldName, default(DateTime));
                formModel.AddAttribute(questionFieldName, new DataTypeAttribute(DataType.Date));
                break;

            case QuestionType.DateTime:
                formModel.Add(questionFieldName, default(DateTime));
                formModel.AddAttribute(questionFieldName, new DataTypeAttribute(DataType.DateTime));
                break;

            case QuestionType.PhoneNumber:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new DataTypeAttribute(DataType.PhoneNumber));
                break;

            case QuestionType.Email:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new DataTypeAttribute(DataType.EmailAddress));
                break;

            case QuestionType.Website:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new DataTypeAttribute(DataType.Url));
                break;

            case QuestionType.Checkbox:
                formModel.Add(questionFieldName, false);
                question.DefaultAnswer = BoolParser.IsTrue(question.DefaultAnswer) ? "true" : "";
                break;

            case QuestionType.YesButton:
                formModel.Add(questionFieldName, false);
                formModel.AddAttribute(questionFieldName, new BooleanYesButtonAttribute());
                question.DefaultAnswer = BoolParser.IsTrue(question.DefaultAnswer) ? "true" : "";
                break;

            case QuestionType.Dropdown:
                formModel.Add(questionFieldName, string.Empty);
                options = question.LookupTable != null?question.LookupTable.LookupTableItems.Select(lti => lti.Text) : new List <string>();

                formModel.AddAttribute(questionFieldName, new DropdownAttribute(options));
                break;

            case QuestionType.DropdownMany:
                formModel.Add(questionFieldName, new List <string>());
                options = question.LookupTable != null?question.LookupTable.LookupTableItems.Select(lti => lti.Text) : new List <string>();

                formModel.AddAttribute(questionFieldName, new DropdownAttribute(options));
                break;

            case QuestionType.RadioListTrueFalse:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new TrueFalseCheckboxOrRadioAttribute());
                break;

            case QuestionType.RadioListYesNo:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new YesNoCheckboxOrRadioAttribute());
                break;

            case QuestionType.RadioList:
                formModel.Add(questionFieldName, string.Empty);
                options = question.LookupTable != null?question.LookupTable.LookupTableItems.Select(lti => lti.Text) : new List <string>();

                formModel.AddAttribute(questionFieldName, new CheckboxOrRadioAttribute(options));
                break;

            case QuestionType.RadioListButtons:
                formModel.Add(questionFieldName, string.Empty);
                options = question.LookupTable != null?question.LookupTable.LookupTableItems.Select(lti => lti.Text) : new List <string>();

                formModel.AddAttribute(questionFieldName, new CheckboxOrRadioButtonsAttribute(options));
                break;

            case QuestionType.RadioListButtonsYesNo:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new YesNoCheckboxOrRadioButtonsAttribute());
                break;

            case QuestionType.RadioListButtonsTrueFalse:
                formModel.Add(questionFieldName, string.Empty);
                formModel.AddAttribute(questionFieldName, new TrueFalseCheckboxOrRadioButtonsAttribute());
                break;

            case QuestionType.CheckboxList:
                formModel.Add(questionFieldName, new List <string>());
                options = question.LookupTable != null?question.LookupTable.LookupTableItems.Select(lti => lti.Text) : new List <string>();

                formModel.AddAttribute(questionFieldName, new CheckboxOrRadioAttribute(options));
                break;

            case QuestionType.CheckboxListButtons:
                formModel.Add(questionFieldName, new List <string>());
                options = question.LookupTable != null?question.LookupTable.LookupTableItems.Select(lti => lti.Text) : new List <string>();

                formModel.AddAttribute(questionFieldName, new CheckboxOrRadioButtonsAttribute(options));
                break;

            case QuestionType.File:
                formModel.Add(questionFieldName, new FormFile(null, 0, 0, "", ""));
                break;

            case QuestionType.FileImage:
                formModel.Add(questionFieldName, new FormFile(null, 0, 0, "", ""));
                formModel.AddAttribute(questionFieldName, new FileImageAcceptAttribute());
                break;

            case QuestionType.FileVideo:
                formModel.Add(questionFieldName, new FormFile(null, 0, 0, "", ""));
                formModel.AddAttribute(questionFieldName, new FileVideoAcceptAttribute());
                break;

            case QuestionType.FileAudio:
                formModel.Add(questionFieldName, new FormFile(null, 0, 0, "", ""));
                formModel.AddAttribute(questionFieldName, new FileAudioAcceptAttribute());
                break;

            case QuestionType.FileImageVideo:
                formModel.Add(questionFieldName, new FormFile(null, 0, 0, "", ""));
                formModel.AddAttribute(questionFieldName, new FileImageVideoAcceptAttribute());
                break;

            case QuestionType.MultipleFiles:
                formModel.Add(questionFieldName, new List <FormFile>());
                break;

            case QuestionType.MultipleFilesImage:
                formModel.Add(questionFieldName, new List <FormFile>());
                formModel.AddAttribute(questionFieldName, new FileImageAcceptAttribute());
                break;

            case QuestionType.MultipleFilesVideo:
                formModel.Add(questionFieldName, new List <FormFile>());
                formModel.AddAttribute(questionFieldName, new FileVideoAcceptAttribute());
                break;

            case QuestionType.MultipleFilesAudio:
                formModel.Add(questionFieldName, new List <FormFile>());
                formModel.AddAttribute(questionFieldName, new FileAudioAcceptAttribute());
                break;

            case QuestionType.MultipleFilesImageVideo:
                formModel.Add(questionFieldName, new List <FormFile>());
                formModel.AddAttribute(questionFieldName, new FileImageVideoAcceptAttribute());
                break;

            default:
                throw new Exception("QuestionType not Mapped");
            }

            //Add Default Values
            if (!string.IsNullOrEmpty(question.DefaultAnswer))
            {
                foreach (var defaultValue in question.DefaultAnswer.Split(','))
                {
                    formModel[questionFieldName] = defaultValue;
                }
            }

            //Add Question Text
            //Add Placeholder
            formModel.AddAttribute(questionFieldName, new DisplayAttribute()
            {
                Name = question.QuestionText, Prompt = question.Placeholder
            });

            //Add Help Text
            if (!string.IsNullOrEmpty(question.HelpText))
            {
                formModel.AddAttribute(questionFieldName, new HelpTextAttribute(question.HelpText));
            }

            //Add Validation
            foreach (var questionValidation in question.Validations)
            {
                switch (questionValidation.ValidationType)
                {
                case QuestionValidationType.Required:
                    var validation = new RequiredAttribute();

                    if (!string.IsNullOrWhiteSpace(questionValidation.CustomValidationMessage))
                    {
                        validation.ErrorMessage = questionValidation.CustomValidationMessage;
                    }
                    formModel.AddAttribute(questionFieldName, validation);
                    break;

                default:
                    throw new Exception("ValidationType not Mapped");
                }
            }

            //Add Conditional Questions
            //foreach (var questionQuestion in question.Questions)
            //{
            //    var logicQuestion = questionQuestion.LogicQuestion;
            //    await AddQuestionToFormAsync(formModel, logicQuestion, cancellationToken);
            //}
        }
Exemplo n.º 15
0
 public static Maybe <bool> ParseToBool(this string source)
 {
     return(BoolParser.Parse(source));
 }
Exemplo n.º 16
0
        public static void CreateInstance()
        {
            BoolParser instance = new BoolParser();

            instance.Parse(true);
        }
 /// <summary>
 /// Generic process boolean function. Can be redefined in children classes. Calls the <see cref="SetBoolean"/> function to add this boolean to the <see cref="BooleanProperties"/> dictionary.
 /// </summary>
 /// <param name="values">The <see cref="StringValues"/> containing the raw data to be parsed.</param>
 protected virtual void ProcessBoolean(StringValues values)
 {
     SetBoolean(values.InformationLabel, BoolParser.GetValue(values.Values[0]));
 }
Exemplo n.º 18
0
 public static Either <TLeft, bool> ParseToBool <TLeft>(this Either <TLeft, string> source, TLeft left)
 {
     return(source.FlatMap(x => BoolParser.Parse(x, left)));
 }
Exemplo n.º 19
0
 public static Either <TLeft, bool> ParseToBool <TLeft>(this string source, TLeft left)
 {
     return(BoolParser.Parse(source, left));
 }
 public void SetUp()
 {
     this.SUT = new BoolParser ();
 }
Exemplo n.º 21
0
        public ActionResult HelpMe(MetaEvent model)
        {
            if (model != null)
            {
                model.Event = new Event();

                if (ModelState.IsValid)
                {
                    int userId = (int)HttpContext.Session.GetInt32("userId");

                    model.Event.TimeFrom = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, model.TimeFrom.Hour, model.TimeFrom.Minute, 0);
                    if (!BoolParser.Parse(Db.SscisParam.Single(p => p.ParamKey.Equals(SSCISParameters.EXTRAEVENTLENGTH, StringComparison.OrdinalIgnoreCase)).ParamValue))
                    {
                        int hour = Convert.ToInt32(Db.SscisParam.Where(p => p.ParamKey.Equals(SSCISParameters.EXTRAEVENTLENGTH, StringComparison.OrdinalIgnoreCase)).Single().ParamValue);
                        model.Event.TimeTo = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, model.TimeFrom.Hour + hour, model.TimeFrom.Minute, 0);
                    }
                    else
                    {
                        model.Event.TimeTo = model.Event.TimeFrom.AddHours(1);
                    }
                    model.Event.IdSubjectNavigation   = Db.EnumSubject.Find(model.SubjectID);
                    model.Event.IdTutorNavigation     = null;
                    model.Event.IdTutor               = null;
                    model.Event.IsAccepted            = false;
                    model.Event.IsCancelled           = false;
                    model.Event.IsExtraLesson         = true;
                    model.Event.IdApplicantNavigation = Db.SscisUser.Find(userId);
                    string comment = model.Comment.ToString();
                    model.Event.ExtraComment = model.Comment.ToString();

                    Db.Event.Add(model.Event);
                    Db.SaveChanges();

                    int newId = model.Event.Id;

                    EmailMessage        emailMessage = new EmailMessage();
                    List <EmailAddress> listTo       = new List <EmailAddress>();

                    foreach (var item in Db.Approval)
                    {
                        if (item.IdSubject == model.SubjectID)
                        {
                            if (item.IdTutorNavigation.Email != null && item.IdTutorNavigation.Email.Length > 2)
                            {
                                EmailAddress emailTo = new EmailAddress();
                                emailTo.Name    = item.IdTutorNavigation.Login;
                                emailTo.Address = item.IdTutorNavigation.Email;
                                listTo.Add(emailTo);
                            }
                        }
                    }

                    string subjectCode = Db.EnumSubject.Where(s => s.Id == model.SubjectID).Single().Code;

                    emailMessage.ToAddresses = listTo;

                    emailMessage.Subject = string.Format(_configuration.GetValue <string>("EmailMessageConfigs:ExtraLectionEmail:Subject"), subjectCode);
                    emailMessage.Content = string.Format(_configuration.GetValue <string>("EmailMessageConfigs:ExtraLectionEmail:Content"), comment, subjectCode, SSCHttpContext.AppBaseUrl, newId);

                    _emailService.Send(emailMessage);
                    return(RedirectToAction("HelpMe"));
                }
            }
            return(RedirectToAction("HelpMe"));
        }
Exemplo n.º 22
0
        public async Task PopulateFormModelFromDbAsync(DynamicForm formModel, string formSubmissionId, string sectionUrlSlug, CancellationToken cancellationToken = default(CancellationToken))
        {
            FormSectionSubmissionDto sectionSubmission = null;

            if (!string.IsNullOrEmpty(formSubmissionId) && !string.IsNullOrEmpty(sectionUrlSlug))
            {
                var formSubmissionGuid = new Guid(formSubmissionId);
                sectionSubmission = await _dynamicFormsApplicationServices.FormSectionSubmissionApplicationService.GetOneAsync(cancellationToken, fss => fss.FormSubmissionId == formSubmissionGuid && fss.UrlSlug == sectionUrlSlug, true);
            }

            if (sectionSubmission != null)
            {
                var properties = formModel.GetProperties();

                foreach (var propertyName in formModel.GetDynamicMemberNames())
                {
                    var persistedValue = sectionSubmission.QuestionAnswers.Where(qa => qa.FieldName == propertyName).FirstOrDefault();
                    if (persistedValue != null)
                    {
                        bool isCollection = formModel.IsCollectionProperty(propertyName);
                        var  property     = properties.Find(propertyName, true);

                        if (isCollection)
                        {
                            var genericCollectionType = typeof(List <>).MakeGenericType(property.PropertyType.GetGenericArguments()[0]);
                            var newCollection         = Activator.CreateInstance(genericCollectionType);

                            formModel[propertyName] = newCollection;

                            var addMethod = genericCollectionType.GetMethod("Add");

                            foreach (var csvSplit in persistedValue.Answer.Split(','))
                            {
                                var convertedValue = Convert.ChangeType(csvSplit.Trim(), property.PropertyType.GetGenericArguments()[0]);
                                addMethod.Invoke(newCollection, new object[] { convertedValue });
                            }
                        }
                        else if (property.PropertyType == typeof(DateTime))
                        {
                            if (!String.IsNullOrWhiteSpace(persistedValue.Answer))
                            {
                                //ISO 8601
                                var parsedValue = DateTime.Parse(persistedValue.Answer, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
                                formModel[propertyName] = parsedValue;
                            }
                            else
                            {
                                formModel[propertyName] = new DateTime();
                            }
                        }
                        else if (property.PropertyType == typeof(bool))
                        {
                            formModel[propertyName] = BoolParser.GetValue(persistedValue.Answer);
                        }
                        else if (property.PropertyType == typeof(decimal))
                        {
                            var convertedValue = decimal.Parse(persistedValue.Answer, NumberStyles.Currency);
                            formModel[propertyName] = convertedValue;
                        }
                        else
                        {
                            var convertedValue = Convert.ChangeType(persistedValue.Answer, property.PropertyType);
                            formModel[propertyName] = convertedValue;
                        }
                    }
                }
            }
        }