Example #1
0
        public async Task <ActionResult <HomeAccount> > PostHomeAccount(HomeAccount homeAccount)
        {
            _context.HomeAccount.Add(homeAccount);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetHomeAccount", new { id = homeAccount.AccountId }, homeAccount));
        }
Example #2
0
        public async Task <IActionResult> PutHomeAccount(int id, HomeAccount homeAccount)
        {
            if (id != homeAccount.AccountId)
            {
                return(BadRequest());
            }

            _context.Entry(homeAccount).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HomeAccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public IActionResult Logoff(HomeAccount account)
 {
     try
     {
         HttpContext.Session.Clear();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Register(HomeAccount account)
        {
            Console.WriteLine("User input data, from register");
            Console.WriteLine("Username: "******"Password: "******"Email: " + account.EmailAddress);
            Console.WriteLine("First Name: " + account.FirstName);
            Console.WriteLine("Last Name: " + account.LastName);
            Console.WriteLine("Address: " + account.HomeAccountAddress);
            Console.WriteLine("PIN: " + account.AccountPin);
            Console.WriteLine("Phone Number: " + account.PhoneNumber);


            if (account.AccountPin == 0)
            {
                ViewBag.Message = "Unable to register, PIN must be a numerical value";
            }
            else if (account.PhoneNumber == 0 || account.PhoneNumber.ToString().Length != 10)
            {
                ViewBag.Message = "Unable to register, phone number must be valid";
            }
            else if (!isValidEmail(account.EmailAddress))
            {
                ViewBag.Message = "Unable to register, invalid email address";
            }
            else
            {
                try
                {
                    using (mypidbContext db = new mypidbContext())
                    {
                        db.HomeAccount.Add(account);
                        db.SaveChanges();
                    }
                    ViewBag.Message = account.EmailAddress + " successfully registered";
                }
                catch
                {
                    ViewBag.Message = "Unable to register user, please try again.";
                }
            }
            return(View());
        }
        public IActionResult Index(HomeAccount account)
        {
            using (mypidbContext db = new mypidbContext())
            {
                HomeAccount loggedInAccount = db.HomeAccount.Where(x => x.AccountUsername == account.AccountUsername && x.AccountPassword == account.AccountPassword).FirstOrDefault();
                if (loggedInAccount == null)
                {
                    ViewBag.Message = "Incorrect username or password, please try again";
                    return(View());
                }
                else
                {
                    //Save user info to session
                    HttpContext.Session.SetInt32("Id", loggedInAccount.AccountId);
                    HttpContext.Session.SetString("Username", loggedInAccount.AccountUsername);

                    return(RedirectToAction("UserTable"));
                }
            }
        }