public IActionResult PerformClockIn(AccountShift accountshift) { _weberpagecontext.Shift.Add(new Shift() { AccountId = accountshift.UserId, DateTimeClockedIn = DateTime.Now, ClockedIn = true }); _weberpagecontext.SaveChanges(); accountshift.DateTimeClockedIn = DateTime.Now; accountshift.ShiftId = _weberpagecontext.Shift.Where(i => i.AccountId == accountshift.UserId) .OrderByDescending(i => i.DateTimeClockedIn).First().Id; accountshift.ClockedIn = true; accountshift.Shifts = _weberpagecontext.Shift.Where(obj => obj.AccountId == ActiveUser.This.CurrentUser.Id && obj.DateTimeClockedIn > startOfWeek && obj.DateTimeClockedOut < endOfWeek).ToList(); _weberpagecontext.SaveChanges(); return(View("ClockIn", accountshift)); }
public IActionResult CreateUser(Account account) { if (ModelState.IsValid == false) { return(View("Index", account)); } if (String.IsNullOrWhiteSpace(account.Username) == false && String.IsNullOrWhiteSpace(account.Password) == false) { //go to the "database" and return whatever value is equal to the username passed in //if that username exists, it will return that username, if it does not it will return NULL Account fromDB = _weberpagecontext.Account.FirstOrDefault(ac => ac.Username == account.Username); if (fromDB == null) { _weberpagecontext.Account.Add(account); _weberpagecontext.SaveChanges(); //Now that the account exists, grab it Account dbAccount = _weberpagecontext.Account.Where(o => o.Username == account.Username && o.Password == account.Password).SingleOrDefault(); //call the index method from the WeberHomePage controller return(RedirectToAction("Index", "WeberPageHome", new { id = dbAccount.Id })); } else { // Acount DOES exist. ModelState.AddModelError("", "This account already exists. Please select a different name"); return(View("Index", account)); } } else { ModelState.AddModelError("", "Emtpy Username and Password"); return(View("Index", account)); } }