Example #1
0
        public async Task <IActionResult> Create([Bind("AccountID,Username,Password,Role")] Account account)
        {
            if (ModelState.IsValid)
            {
                account.AccountID = Guid.NewGuid();

                // Password Hash
                string tempPassword = account.Password;
                var    hash         = Security.GenerateSaltedHash(tempPassword);
                string hashedString = Convert.ToBase64String(hash);
                account.Password = hashedString;

                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("WebCheckID,Name,Domain,Delay,CreateDate,AccountID")] WebCheck webCheck)
        {
            if (ModelState.IsValid)
            {
                var userAccount = GetUserAccountAsync().Result;
                webCheck.WebCheckID = Guid.NewGuid();
                webCheck.CreateDate = DateTime.Now;
                webCheck.AccountID  = userAccount.AccountID;

                _context.Add(webCheck);
                await _context.SaveChangesAsync();

                WebCheckHelper.CreateRecurringEvent(webCheck);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountID"] = new SelectList(_context.Accounts, "AccountID", "Password", webCheck.AccountID);
            return(View(webCheck));
        }