Esempio n. 1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(VoteItemModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VoteItemModelExists(VoteItemModel.ItemID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Categories.Add(CategoryModel);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            var mailRgx = @"^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$";
            var passRgx = @"(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{8,}";

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Regex.IsMatch(UserModel.Email, mailRgx))
            {
                if (Regex.IsMatch(UserModel.Password, passRgx))
                {
                    var list = _context.Users.ToList();
                    var i    = 0;
                    while (i < list.Count() && UserModel.Email != list[i].Email)
                    {
                        i++;
                    }
                    if (i == list.Count())
                    {
                        _context.Users.Add(UserModel);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("./Index"));
                    }
                    else
                    {
                        return(base.Content("<script>alert('Email already exist, choose different email'); window.location.href = \"./Create\"</script>", "text/html", Encoding.UTF8));
                    }
                }
                else
                {
                    return(base.Content("<script>alert('Password at least 8 characters long and contin uppercase, lowercase and numeric'); window.location.href = \"./Create\"</script>", "text/html", Encoding.UTF8));
                }
            }
            else
            {
                return(base.Content("<script>alert('Email is not valid'); window.location.href = \"./Create\"</script>", "text/html", Encoding.UTF8));
            }
        }