Exemplo n.º 1
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                Number.When   = DateTime.Now;
                Number.Result = "Result: ";

                if (Number.Value % 3 == 0)
                {
                    Number.Result += "Fizz";
                }
                if (Number.Value % 5 == 0)
                {
                    Number.Result += "Buzz";
                }
                if (Number.Result == "Result: ")
                {
                    Number.Result = "Your number: " + Number.Value.ToString() + " does not meet the FizzBuzz conditions.";
                }

                if (_signInManager.IsSignedIn(User))
                {
                    Number.UserID = _userManager.GetUserId(User);
                }

                _context.Number.Add(Number);

                _context.SaveChanges();
                var SessionFizzBuzz = HttpContext.Session.GetString("SessionFizzBuzz");


                List <Num> ListOfSearches;

                if (SessionFizzBuzz == null)
                {
                    ListOfSearches = new List <Num>();
                }
                else
                {
                    ListOfSearches = JsonConvert.DeserializeObject <List <Num> >(SessionFizzBuzz);
                }

                ListOfSearches.Add(Number);

                HttpContext.Session.SetString("SessionFizzBuzz", JsonConvert.SerializeObject(ListOfSearches));
            }
            return(Page());
        }
Exemplo n.º 2
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                Number.When   = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                Number.Result = "Result: ";

                if (Number.Value % 3 == 0)
                {
                    Number.Result += "Fizz";
                }
                if (Number.Value % 5 == 0)
                {
                    Number.Result += "Buzz";
                }
                if (Number.Result == "Result: ")
                {
                    Number.Result = "Your number: " + Number.Value.ToString() + " does not meet the FizzBuzz conditions.";
                }

                var SessionFizzBuzz = HttpContext.Session.GetString("SessionFizzBuzz");


                List <Num> ListOfSearches;

                if (SessionFizzBuzz == null)
                {
                    ListOfSearches = new List <Num>();
                }
                else
                {
                    ListOfSearches = JsonConvert.DeserializeObject <List <Num> >(SessionFizzBuzz);
                }

                ListOfSearches.Add(Number);

                HttpContext.Session.SetString("SessionFizzBuzz", JsonConvert.SerializeObject(ListOfSearches));
            }
            return(Page());
        }