public static void GenerateDataIfRequired() { var weekOfYear = new WeekOfYear() { Week = TimeEntry.GetIso8601WeekOfYear(DateTime.Now), Year = DateTime.Now.Year }; var firstDayOfCurrentWeek = TimeEntry.GetIso8601FirstDateOfWeek(weekOfYear.Year, weekOfYear.Week); var previousWeekStart = firstDayOfCurrentWeek - TimeSpan.FromDays(7); weekOfYear = new WeekOfYear() { Week = TimeEntry.GetIso8601WeekOfYear(previousWeekStart), Year = previousWeekStart.Year }; using (var instance = new GenerateTimeEntryData()) { if (instance.IsThereDataForWeek(weekOfYear)) { return; } instance.GenerateData(weekOfYear); } }
// override for custom implementation protected override bool ValidateUser(string userName, string password) { GenerateTimeEntryData.GenerateDataIfRequired(); var timeEntryUser = _context.TimeEntryUsers.FirstOrDefault(u => u.UserName == userName); if (timeEntryUser == null) { return(false); } var security = _context.Securities.FirstOrDefault(s => s.UserId == timeEntryUser.Id); if (security == null) { // for this sample, we will create a security entry for the user using the supplied password security = new Security() { UserId = timeEntryUser.Id, Salt = GenerateSalt() }; security.Password = HashPassword(password, security.Salt); _context.Securities.AddObject(security); _context.SaveChanges(); // In the real world, we would, of course: //return false; } return(DoPasswordsMatch(password, security.Salt, security.Password)); //return base.ValidateUser(userName, password); }