public async Task <ActionResult> LogIn(LogOnModel model) { if (ModelState.IsValid) { var user = await userService.Validate(model.UserName, model.Password); if (user != null) { if (user.Expires != null && user.Expires <= DateTime.Now) { FlashHelper.Add("Account has expired.", FlashType.Error); return(new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" } })); } HttpContext.Session.Add(SessionName, user.UserName); return(new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" } })); } FlashHelper.Add("Invalid login information.", FlashType.Error); } return(View(model)); }
public async Task <ActionResult> Create(CreateModel model) { if (ModelState.IsValid) { var user = await userService.GetUser(model.UserName); if (user != null) { FlashHelper.Add(string.Format("User with the username {0} aready exists.", model.UserName), FlashType.Error); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } var userObject = new User() { Id = Guid.NewGuid(), UserName = model.UserName }; if (model.Expires != null) { DateTime?expires = null; DateTime tryDate; if (DateTime.TryParseExact(model.Expires.Trim() + " 00:00:00", "dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out tryDate)) { expires = tryDate; } else { FlashHelper.Add( string.Format("\"{0}\" was not reconiced as a date of the format dd/mm/yyyy.", model.Expires), FlashType.Error); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } userObject.Expires = expires; } await userService.CreateUser(userObject, model.Password); FlashHelper.Add(string.Format("User with the username {0} have been created.", model.UserName), FlashType.Success); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } return(View(model)); }
public async Task <ActionResult> Delete(string username, AreYouSureModel model) { await userService.DeleteUser(username); FlashHelper.Add(string.Format("{0} have been deleted.", username), FlashType.Notice); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); }
public async Task <ActionResult> Delete(Guid id, AreYouSureModel model) { Project project = await databaseService.GetProject(id); await databaseService.DeleteProject(id); FlashHelper.Add(string.Format("{0} have been deleted.", project.Name), FlashType.Notice); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Measurements" }, { "action", "Index" } })); }
public async Task <ActionResult> Edit(string username, EditModel model) { if (ModelState.IsValid) { DateTime?expires = null; if (model.Expires != null) { DateTime tryDate; if (DateTime.TryParseExact(model.Expires.Trim() + " 00:00:00", "dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out tryDate)) { expires = tryDate; } else { FlashHelper.Add( string.Format("\"{0}\" was not reconiced as a date of the format dd/mm/yyyy.", model.Expires), FlashType.Error); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } } if (!String.IsNullOrWhiteSpace(model.Password) && !String.IsNullOrWhiteSpace(model.PasswordRepeat) && model.Password == model.PasswordRepeat) { await userService.UpdatePassword(username, model.Password); } await userService.UpdateExpires(username, expires); FlashHelper.Add(string.Format("{0}'s password have been changed.", model.UserName), FlashType.Success); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } return(View(model)); }
public async Task <ActionResult> Delete(Guid id, string redirect) { Project project = await databaseService.GetProject(id); if (project == null) { FlashHelper.Add(string.Format("Project with id \"{0}\" did not exist.", id), FlashType.Notice); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Measurements" }, { "action", "Index" } })); } return(View("AreYouSureModel", new AreYouSureModel() { Message = string.Format("Are you sure you want to delete \"{0}\"", project.Name), RedirectAction = "Index", Redirect = new RouteValueDictionary() })); }
public async Task <ActionResult> Delete(string username) { var user = await userService.GetUser(username); if (user == null) { FlashHelper.Add(string.Format("{0} did not exist.", username), FlashType.Notice); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } return(View("AreYouSureModel", new AreYouSureModel() { Message = string.Format("Are you sure you want to delete {0}?", username), RedirectAction = "Index", Redirect = new RouteValueDictionary() })); }
public async Task <ActionResult> Edit(string username) { var user = await userService.GetUser(username); if (user == null) { FlashHelper.Add(string.Format("{0} did not exist.", username), FlashType.Notice); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Account" }, { "action", "Index" } })); } var model = new EditModel() { UserName = user.UserName, Expires = user.Expires?.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture) ?? "" }; return(View(model)); }
public async Task <ActionResult> Readings(Guid id) { Project project = await databaseService.GetProject(id); if (project == null) { FlashHelper.Add(string.Format("Project with id \"{0}\" did not exist.", id), FlashType.Notice); return(new RedirectToRouteResult(new RouteValueDictionary() { { "controller", "Measurements" }, { "action", "Index" } })); } var readings = await databaseService.GetReading(id); return(View(new ReadingsModel() { Project = project, MajorReadings = readings.Where(x => x.Major).ToList(), MinorReadings = readings.Where(x => !x.Major).ToList() })); }
public async Task <ActionResult> Index() { var currentUserName = HttpContext.Session[SessionName]; if (currentUserName == null) { return(new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Account" }, { "action", "LogIn" } })); } var currentUser = await userService.GetUser((string)currentUserName); if (currentUser == null) { return(new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Account" }, { "action", "LogIn" } })); } if (currentUser.Expires != null) { FlashHelper.Add("A limited account dose not have access to manage user.", FlashType.Error); return(new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" } })); } var users = await userService.GetUsers(); return(View(users)); }
public async Task <ActionResult> Index(MeasurementsSearchResultModel model) { var from = DateTime.Now.AddMonths(-1); var to = DateTime.Now; var keys = Request.Form.AllKeys; // Model binding It is being very strange if (model.From == null && keys.Contains("From")) { model.From = Request.Form["From"]; } if (model.To == null && keys.Contains("To")) { model.To = Request.Form["To"]; } if (model.ProjectName == null && keys.Contains("ProjectName")) { model.ProjectName = Request.Form["ProjectName"]; } if (model.ProjectNumber == null && keys.Contains("ProjectNumber")) { model.ProjectNumber = Request.Form["ProjectNumber"]; } if (ModelState.IsValid) { if (model.From != null) { DateTime tryDate; if (DateTime.TryParseExact(model.From.Trim() + " 00:00:00", "dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out tryDate)) { from = tryDate; } else { FlashHelper.Add( string.Format("\"{0}\" was not reconiced as a date of the format dd/mm/yyyy.", model.From), FlashType.Error); } } if (model.To != null) { DateTime tryDate; if (DateTime.TryParseExact(model.To.Trim() + " 23:59:59", "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out tryDate)) { to = tryDate; } else { FlashHelper.Add( string.Format("\"{0}\" was not reconiced as a date of the format dd/mm/yyyy.", model.To), FlashType.Error); } } } model.Projects = await databaseService.SearchProjects(model.ProjectName, model.ProjectNumber, from, to); return(View(model)); }