public static void Seed(EfDbContext context, List<Organization> organizations) { foreach (var tour in CoverYourBasesTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); foreach (var tour in CrunchFitnessTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); foreach (var tour in TheLegendsContinueTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); foreach (var tour in LetsRallyTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); foreach (var tour in GetTheDriftTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); foreach (var tour in GetSuperBowlTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); foreach (var tour in GetImbibeRideTours(organizations)) context.Tours.AddOrUpdate(t => t.Code, tour); try { context.SaveChanges(); } catch (DbEntityValidationException dbex) { foreach (var dbEntityValidationResult in dbex.EntityValidationErrors) foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) Debug.WriteLine("{0}: {1}", dbValidationError.PropertyName, dbValidationError.ErrorMessage); throw; } }
public static void Seed(EfDbContext context) { var endereco = new Endereco("Rua teste", "complemento teste", "numero teste", "bairroteste", "cidadeteste", Uf.SP, new Cep("06414-110")); context.Usuarios.AddOrUpdate(x => x.Login, new Usuario("adminMaster", new Cpf("40914294830"), new Email("*****@*****.**"), "testeteste", "testeteste", endereco)); }
public void TestMethod1() { using (var db = new EfDbContext()) { //var product = new Product(); //db.Products.Add(product); //db.SaveChanges(); } }
public static void Seed(EfDbContext context) { try { context.Countries.AddOrUpdate(c => c.Iso, Countries()); context.SaveChanges(); context.States.AddOrUpdate(c => c.Abbreviation, States()); context.SaveChanges(); } catch (DbEntityValidationException dbex) { foreach (var dbEntityValidationResult in dbex.EntityValidationErrors) foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) Debug.WriteLine("{0}: {1}", dbValidationError.PropertyName, dbValidationError.ErrorMessage); throw; } }
internal static void DoSeed(EfDbContext context) { context.DsUser.Add(new User { Id = Guid.NewGuid(), Account = "admin", Password = Encrypt.AesEncrypt("hy1216"), CreateDate = DateTime.Now, Creater = Guid.Empty, Email = "*****@*****.**", NickName = "Allyn", Phone = "13838383388", Disabled = false, Modifier = Guid.Empty, UpdateDate = DateTime.MaxValue }); context.SaveChanges(); }
public static MembershipCreateStatus Register(string Username, string Password, string Email, bool IsApproved, string FirstName, string LastName) { MembershipCreateStatus CreateStatus; System.Web.Security.Membership.CreateUser(Username, Password, Email, null, null, IsApproved, Guid.NewGuid(), out CreateStatus); if (CreateStatus == MembershipCreateStatus.Success) { using (EfDbContext Context = new EfDbContext()) { User User = Context.Users.FirstOrDefault(Usr => Usr.Username == Username); User.FirstName = FirstName; User.LastName = LastName; Context.SaveChanges(); } if (IsApproved) { FormsAuthentication.SetAuthCookie(Username, false); } } return CreateStatus; }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { if (string.IsNullOrEmpty(username)) { return false; } using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.Username == username); if (User != null) { Context.Users.Remove(User); Context.SaveChanges(); return true; } else { return false; } } }
/// <summary> /// Lấy thông tin đơn vị theo khóa chính bảng đơn vị /// </summary> /// <param name="orgId"></param> /// <returns></returns> /// CreatedBy: NVMANH (20/06/2020) public static Organization GetOrganizationByOrganizationId(Guid orgId) { using EfDbContext dbContex = new EfDbContext(); return(dbContex.Organization.Where(o => o.OrganizationId == orgId).FirstOrDefault()); }
public SubProjectRepository(EfDbContext context) : base(context) { }
public ProductRepository(EfDbContext context) : base(context) { _context = context; }
public Repository(EfDbContext context) { this._context = context; _dbSet = _context.Set <TEntity>(); }
protected Repository(EfDbContext context) { Context = context; }
public CustomerService(EfDbContext dbContext, IEventBus eventBus, IStateManager stateManager) { this.dbContext = dbContext; this.eventBus = eventBus; this.stateManager = stateManager; }
public MailController(EfDbContext dbContext) : base(new SocialPackageMailSender(new SocialPackageSmtpClient(dbContext))) { this.dbContext = dbContext; }
static void Main(string[] args) { using (EfDbContext context = new EfDbContext()) { var dbContext = new EfDbContext(); DbInitializer.Initialize(context); IRepository repository = new EfRepository(context); var suppliers = repository.SuppliersForCategory("Phone"); Console.WriteLine("Phone Suppliers:"); Console.WriteLine("----------------------------------"); foreach (var supplier in suppliers) { Console.WriteLine($"Supplier: {supplier.Name}\n" + $"\tCity: {supplier.City}"); //Console.WriteLine("----------------------------------"); } var products = repository.ProductsForCategory("Phone"); Console.WriteLine(""); Console.WriteLine("Phones:"); Console.WriteLine("----------------------------------"); foreach (var product in products) { Console.WriteLine($"Product: {product.Name}\n" + $"\tPrice: {product.Price}\n" + $"\tSupplier: {product.Supplier.Name}\n" + $"\tCity: {product.Supplier.City}"); //Console.WriteLine("----------------------------------"); } products = repository.ProductsOfSupplier("Samsung"); Console.WriteLine(""); Console.WriteLine("Samsung Products:"); Console.WriteLine("----------------------------------"); foreach (var product in products) { Console.WriteLine($"Product: {product.Name}\n" + $"\tCategory: {product.Category.Name}\n" + $"\tPrice: {product.Price}"); //Console.WriteLine("----------------------------------"); } products = repository.ProductsByConditions(maxPrice: 600, supplierCity: "Seoul"); Console.WriteLine(""); Console.WriteLine("Products From Seoul whith price less than or equal 600:"); Console.WriteLine("----------------------------------"); foreach (var product in products) { Console.WriteLine($"Product: {product.Name}\n" + $"\tCategory: {product.Category.Name}\n" + $"\tPrice: {product.Price}\n" + $"\tSupplier: {product.Supplier.Name}"); //Console.WriteLine("----------------------------------"); } } Console.ReadKey(); }
public AccountRepository(EfDbContext context) : base(context) { }
public AuthenticationRepository(EfDbContext context) { _context = context; }
public SecurityService(HttpSessionState session = null) { _context = new EfDbContext(); _session = session ?? HttpContext.Current.Session; _session.Timeout = 120; }
public EfUnitOfWork(string connectionString) { _db = new EfDbContext(connectionString); }
public TicketLineRepository(EfDbContext context) { this.context = context; this.context.Database.Log = new Action <string>(TicketLineRepository.logger.Trace); }
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection MembershipUsers = new MembershipUserCollection(); using (EfDbContext Context = new EfDbContext()) { totalRecords = Context.Users.Count(); IQueryable<User> Users = Context.Users.OrderBy(Usrn => Usrn.Username).Skip(pageIndex * pageSize).Take(pageSize); foreach (User user in Users) { MembershipUsers.Add(new MembershipUser(System.Web.Security.Membership.Provider.Name, user.Username, user.UserId, user.Email, null, null, user.IsApproved, user.IsLockedOut, user.CreateDate.Value, user.LastLoginDate.Value, user.LastActivityDate.Value, user.LastPasswordChangedDate.Value, user.LastLockoutDate.Value)); } } return MembershipUsers; }
public PermissionQueryService(EfDbContext dbContext, IStateManager stateManager) { this.dbContext = dbContext; this.stateManager = stateManager; }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (string.IsNullOrEmpty(username)) { status = MembershipCreateStatus.InvalidUserName; return null; } if (string.IsNullOrEmpty(password)) { status = MembershipCreateStatus.InvalidPassword; return null; } if (string.IsNullOrEmpty(email)) { status = MembershipCreateStatus.InvalidEmail; return null; } string HashedPassword = Crypto.HashPassword(password); if (HashedPassword.Length > 128) { status = MembershipCreateStatus.InvalidPassword; return null; } using (EfDbContext Context = new EfDbContext()) { if (Context.Users.Where(Usr => Usr.Username == username).Any()) { status = MembershipCreateStatus.DuplicateUserName; return null; } if (Context.Users.Where(Usr => Usr.Email == email).Any()) { status = MembershipCreateStatus.DuplicateEmail; return null; } User NewUser = new User { UserId = Guid.NewGuid(), Username = username, Password = HashedPassword, IsApproved = isApproved, Email = email, CreateDate = DateTime.UtcNow, LastPasswordChangedDate = DateTime.UtcNow, PasswordFailuresSinceLastSuccess = 0, LastLoginDate = DateTime.UtcNow, LastActivityDate = DateTime.UtcNow, LastLockoutDate = DateTime.UtcNow, IsLockedOut = false, LastPasswordFailureDate = DateTime.UtcNow }; Context.Users.Add(NewUser); Context.SaveChanges(); status = MembershipCreateStatus.Success; return new MembershipUser(System.Web.Security.Membership.Provider.Name, NewUser.Username, NewUser.UserId, NewUser.Email, null, null, NewUser.IsApproved, NewUser.IsLockedOut, NewUser.CreateDate.Value, NewUser.LastLoginDate.Value, NewUser.LastActivityDate.Value, NewUser.LastPasswordChangedDate.Value, NewUser.LastLockoutDate.Value); } }
public EsGoodsRepository(IElasticSearchRepository <EsGoodsDto> elasticRepo, EfDbContext efDbContext) { this.elasticRepo = elasticRepo; this.efDbContext = efDbContext; }
public RemoveTestCommandHandler(EfDbContext context) : base(context) { }
public UserRepository(EfDbContext efDbContext) { _efDbContext = efDbContext; }
public MuseumService(EfDbContext context) { _context = context; }
public override bool ValidateUser(string username, string password) { if (string.IsNullOrEmpty(username)) { return false; } if (string.IsNullOrEmpty(password)) { return false; } using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.Username == username); if (User == null) { return false; } if (!User.IsApproved) { return false; } if (User.IsLockedOut) { return false; } String HashedPassword = User.Password; Boolean VerificationSucceeded = (HashedPassword != null && Crypto.VerifyHashedPassword(HashedPassword, password)); if (VerificationSucceeded) { User.PasswordFailuresSinceLastSuccess = 0; User.LastLoginDate = DateTime.UtcNow; User.LastActivityDate = DateTime.UtcNow; } else { int Failures = User.PasswordFailuresSinceLastSuccess; if (Failures < MaxInvalidPasswordAttempts) { User.PasswordFailuresSinceLastSuccess += 1; User.LastPasswordFailureDate = DateTime.UtcNow; } else if (Failures >= MaxInvalidPasswordAttempts) { User.LastPasswordFailureDate = DateTime.UtcNow; User.LastLockoutDate = DateTime.UtcNow; User.IsLockedOut = true; } } Context.SaveChanges(); if (VerificationSucceeded) { return true; } else { return false; } } }
public UnitOfWork(EfDbContext context) { _context = context; }
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline) { if (providerUserKey is Guid) { } else { return null; } using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.Find(providerUserKey); if (User != null) { if (userIsOnline) { User.LastActivityDate = DateTime.UtcNow; Context.SaveChanges(); } return new MembershipUser(System.Web.Security.Membership.Provider.Name, User.Username, User.UserId, User.Email, null, null, User.IsApproved, User.IsLockedOut, User.CreateDate.Value, User.LastLoginDate.Value, User.LastActivityDate.Value, User.LastPasswordChangedDate.Value, User.LastLockoutDate.Value); } else { return null; } } }
public AccountService(EfDbContext context) { _context = context; }
public override bool UnlockUser(string userName) { using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.Username == userName); if (User != null) { User.IsLockedOut = false; User.PasswordFailuresSinceLastSuccess = 0; Context.SaveChanges(); return true; } else { return false; } } }
public HomeController(EfDbContext context, DataManager dataManager) { _context = context; _dataManager = dataManager; }
public SeriesService() { _context = new EfDbContext(); }
public ToDoDtoRepository(EfDbContext dbContext) { _dbContext = dbContext; }
static void Main(string[] args) { using (var efDbContext = new EfDbContext()) { ChangeTracking(efDbContext); //SqlIsNull(efDbContext); //SqlWhere(efDbContext); //QuerySql(efDbContext); //饥饿加载 //var querycustomer = efDbContext.Customer.Include("Orders").FirstOrDefault(); //var querycustomer = efDbContext.Customer.FirstOrDefault(); //显示加载 //efDbContext.Entry(querycustomer).Collection(d => d.Orders).Load(); //var queryOrders = querycustomer.Orders; //ModelAdded(efDbContext); //ModelUnChanged(efDbContext); //ModelModified(efDbContext); //ModelDeleted(efDbContext); //var student = new Student //{ // Name = "Jeffcky", // Age = 26, // CreatedTime = DateTime.Now, // ModifiedTime = DateTime.Now, // Courses = new List<Course> // { // new Course // { // Name="C#", // MaximumStrength=12, // CreatedTime=DateTime.Now, // ModifiedTime=DateTime.Now // }, // new Course // { // Name="EntityFrameWork6.X", // MaximumStrength=12, // CreatedTime=DateTime.Now, // ModifiedTime=DateTime.Now // } // } //}; //Course course = new Course //{ // Name = "WebApi", // MaximumStrength = 12, // CreatedTime = DateTime.Now, // ModifiedTime = DateTime.Now, // Students = new List<Student> // { // new Student // { // Name="Raviendra", // Age=25, // CreatedTime=DateTime.Now, // ModifiedTime=DateTime.Now // }, // new Student // { // Name="Pradeep", // Age=25, // CreatedTime=DateTime.Now, // ModifiedTime=DateTime.Now // } // } //}; //efDbContext.Student.Add(student); //efDbContext.SaveChanges(); //var customer = new Customer //{ // Name = "chenjie", // Email = "*****@*****.**", // CreatedTime = DateTime.Now, // ModifiedTime = DateTime.Now, // Orders = new List<Order> //{ // new Order // { // Quanatity=12, // Price=1500, // CreatedTime=DateTime.Now, // ModifiedTime=DateTime.Now // },new Order // { // Quanatity=10, // Price=2500, // CreatedTime=DateTime.Now, // ModifiedTime=DateTime.Now // } //} //}; //efDbContext.Customer.Add(customer); //efDbContext.SaveChanges(); //efDbContext.Blogs.Add(new Model.Blog() //{ // Name = "陈杰", // Url = "http://www.cnblogs.com/chen-jie" //}); //efDbContext.SaveChanges(); //var query = (from b in efDbContext.BullingDetails.OfType<BankAccount>() select b).ToList(); //var users = new User //{ // BirthDate = DateTime.Now, // CreatedTime = DateTime.Now, // ModifiedTime = DateTime.Now, // Name = "chenjie", // IDNumber = "46031399108274789" //}; //efDbContext.User.Add(users); //efDbContext.SaveChanges(); //var user = efDbContext.User.Find(1); ////原始值 //var originaValues = efDbContext.Entry(user).ComplexProperty(u => u.Address).OriginalValue; ////当前值 //var currentValues = efDbContext.Entry(user).ComplexProperty(u => u.Address).CurrentValue; } }
public override MembershipUser GetUser(string username, bool userIsOnline) { if (string.IsNullOrEmpty(username)) { return null; } using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.Username == username); if (User != null) { if (userIsOnline) { User.LastActivityDate = DateTime.UtcNow; Context.SaveChanges(); } return new MembershipUser(System.Web.Security.Membership.Provider.Name, User.Username, User.UserId, User.Email, null, null, User.IsApproved, User.IsLockedOut, User.CreateDate.Value, User.LastLoginDate.Value, User.LastActivityDate.Value, User.LastPasswordChangedDate.Value, User.LastLockoutDate.Value); } else { return null; } } }
public Repository(EfDbContext context) { _context = context; }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { if (string.IsNullOrEmpty(username)) { return false; } if (string.IsNullOrEmpty(oldPassword)) { return false; } if (string.IsNullOrEmpty(newPassword)) { return false; } using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.Username == username); if (User == null) { return false; } String HashedPassword = User.Password; Boolean VerificationSucceeded = (HashedPassword != null && Crypto.VerifyHashedPassword(HashedPassword, oldPassword)); if (VerificationSucceeded) { User.PasswordFailuresSinceLastSuccess = 0; } else { int Failures = User.PasswordFailuresSinceLastSuccess; if (Failures < MaxInvalidPasswordAttempts) { User.PasswordFailuresSinceLastSuccess += 1; User.LastPasswordFailureDate = DateTime.UtcNow; } else if (Failures >= MaxInvalidPasswordAttempts) { User.LastPasswordFailureDate = DateTime.UtcNow; User.LastLockoutDate = DateTime.UtcNow; User.IsLockedOut = true; } Context.SaveChanges(); return false; } String NewHashedPassword = Crypto.HashPassword(newPassword); if (NewHashedPassword.Length > 128) { return false; } User.Password = NewHashedPassword; User.LastPasswordChangedDate = DateTime.UtcNow; Context.SaveChanges(); return true; } }
public void Test0040() { var testDateTime = DateTime.Now; #region テストデータ準備 var testEntity = TestUtilLib.GenarateRandomTodoTask(); var testEntity1 = new TodoTask().CopyValuesFrom(testEntity); var testEntity2 = new TodoTask().CopyValuesFrom(testEntity); var testEntity3 = new TodoTask().CopyValuesFrom(testEntity); var testEntity4 = new TodoTask().CopyValuesFrom(testEntity); var testEntity5 = new TodoTask().CopyValuesFrom(testEntity); { int i = 1; testEntity1.TodoTaskId = i++.ToString(); testEntity1.DueDate = testDateTime.Date.AddMilliseconds(-1); // 昨日の 23:59:59.999 testEntity2.TodoTaskId = i++.ToString(); testEntity2.DueDate = testDateTime.Date; // 本日の 00:00:00.000 testEntity3.TodoTaskId = i++.ToString(); testEntity3.DueDate = testDateTime; // 本日の今の時刻 testEntity4.TodoTaskId = i++.ToString(); testEntity4.DueDate = testDateTime.Date.AddDays(1).AddMilliseconds(-1); // 本日の 23:59:59.999 testEntity5.TodoTaskId = i++.ToString(); testEntity5.DueDate = testDateTime.Date.AddDays(1); // 明日の 00:00:00.000 } using (var context = new EfDbContext()) { context.Add(testEntity1); context.Add(testEntity2); context.Add(testEntity3); context.Add(testEntity4); context.Add(testEntity5); context.SaveChanges(); } using (var context = new EfDbContext()) Assert.AreEqual(5, context.TodoTasks.Count()); #endregion var parameter = new EditViewSearch.Parameter { SearchConditionsDateTo = testDateTime }; IRequest request = new Request { Parameter = parameter }; EditViewSearch logic = new EditViewSearch(); IResponse response = logic.DoProcess(request); var searchResults = ((EditViewSearch.Result)response.Result).TodoTasks; Assert.AreEqual(4, searchResults.Count); { int i = 0; Assert.AreEqual(testEntity1.TodoTaskId, searchResults[i++].TodoTaskId); Assert.AreEqual(testEntity2.TodoTaskId, searchResults[i++].TodoTaskId); Assert.AreEqual(testEntity3.TodoTaskId, searchResults[i++].TodoTaskId); Assert.AreEqual(testEntity4.TodoTaskId, searchResults[i++].TodoTaskId); } }
public override int GetNumberOfUsersOnline() { DateTime DateActive = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(Convert.ToDouble(System.Web.Security.Membership.UserIsOnlineTimeWindow))); using (EfDbContext Context = new EfDbContext()) { return Context.Users.Where(Usr => Usr.LastActivityDate > DateActive).Count(); } }
public void Test0050() { var subjectMatch = "検索条件"; var subjectUnMatch = "検索_条件"; var testDateTime = DateTime.Now; var yesterday = testDateTime.Date.AddDays(-1); var today = testDateTime.Date; var tommorow = testDateTime.Date.AddDays(1); #region テストデータ準備 var testEntity = TestUtilLib.GenarateRandomTodoTask(); var testEntity1 = new TodoTask().CopyValuesFrom(testEntity); var testEntity2 = new TodoTask().CopyValuesFrom(testEntity); var testEntity3 = new TodoTask().CopyValuesFrom(testEntity); var testEntity4 = new TodoTask().CopyValuesFrom(testEntity); var testEntity5 = new TodoTask().CopyValuesFrom(testEntity); var testEntity6 = new TodoTask().CopyValuesFrom(testEntity); { int i = 1; testEntity1.TodoTaskId = i++.ToString(); testEntity1.Subject = subjectMatch; testEntity1.DueDate = yesterday; testEntity2.TodoTaskId = i++.ToString(); testEntity2.Subject = subjectUnMatch; testEntity2.DueDate = yesterday; testEntity3.TodoTaskId = i++.ToString(); testEntity3.Subject = subjectMatch; testEntity3.DueDate = today; testEntity4.TodoTaskId = i++.ToString(); testEntity4.Subject = subjectUnMatch; testEntity4.DueDate = today; testEntity5.TodoTaskId = i++.ToString(); testEntity5.Subject = subjectMatch; testEntity5.DueDate = tommorow; testEntity6.TodoTaskId = i++.ToString(); testEntity6.Subject = subjectUnMatch; testEntity6.DueDate = tommorow; } using (var context = new EfDbContext()) { context.Add(testEntity1); context.Add(testEntity2); context.Add(testEntity3); context.Add(testEntity4); context.Add(testEntity5); context.Add(testEntity6); context.SaveChanges(); } using (var context = new EfDbContext()) Assert.AreEqual(6, context.TodoTasks.Count()); #endregion var parameter = new EditViewSearch.Parameter { SearchConditionsText = subjectMatch, SearchConditionsDateFrom = testDateTime, SearchConditionsDateTo = testDateTime, }; IRequest request = new Request { Parameter = parameter }; EditViewSearch logic = new EditViewSearch(); IResponse response = logic.DoProcess(request); var searchResults = ((EditViewSearch.Result)response.Result).TodoTasks; Assert.AreEqual(1, searchResults.Count); { int i = 0; Assert.AreEqual(testEntity3.TodoTaskId, searchResults[i++].TodoTaskId); } }
public override string GetUserNameByEmail(string email) { using (EfDbContext Context = new EfDbContext()) { User User = null; User = Context.Users.FirstOrDefault(Usr => Usr.Email == email); if (User != null) { return User.Username; } else { return string.Empty; } } }
public void Test0020() { #region テストデータ準備 var testEntity = TestUtilLib.GenarateRandomTodoTask(); var testEntity1 = new TodoTask().CopyValuesFrom(testEntity); var testEntity2 = new TodoTask().CopyValuesFrom(testEntity); var testEntity3 = new TodoTask().CopyValuesFrom(testEntity); var testEntity4 = new TodoTask().CopyValuesFrom(testEntity); var testEntity5 = new TodoTask().CopyValuesFrom(testEntity); { int i = 1; testEntity1.TodoTaskId = i++.ToString(); testEntity1.Subject = "検索条件"; testEntity2.TodoTaskId = i++.ToString(); testEntity2.Subject = "_検索条件"; testEntity3.TodoTaskId = i++.ToString(); testEntity3.Subject = "検索条件_"; testEntity4.TodoTaskId = i++.ToString(); testEntity4.Subject = "_検索条件_"; testEntity5.TodoTaskId = i++.ToString(); testEntity5.Subject = "検索_条件"; } using (var context = new EfDbContext()) { context.Add(testEntity1); context.Add(testEntity2); context.Add(testEntity3); context.Add(testEntity4); context.Add(testEntity5); context.SaveChanges(); } using (var context = new EfDbContext()) Assert.AreEqual(5, context.TodoTasks.Count()); #endregion var parameter = new EditViewSearch.Parameter { SearchConditionsText = "検索条件" }; IRequest request = new Request { Parameter = parameter }; EditViewSearch logic = new EditViewSearch(); IResponse response = logic.DoProcess(request); var searchResults = ((EditViewSearch.Result)response.Result).TodoTasks; Assert.AreEqual(4, searchResults.Count); { int i = 0; Assert.AreEqual(testEntity1.TodoTaskId, searchResults[i++].TodoTaskId); Assert.AreEqual(testEntity2.TodoTaskId, searchResults[i++].TodoTaskId); Assert.AreEqual(testEntity3.TodoTaskId, searchResults[i++].TodoTaskId); Assert.AreEqual(testEntity4.TodoTaskId, searchResults[i++].TodoTaskId); } }
public string CreateAccount(string userName, string password, bool requireConfirmationToken) { if (string.IsNullOrEmpty(userName)) { throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName); } if (string.IsNullOrEmpty(password)) { throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword); } string hashedPassword = Crypto.HashPassword(password); if (hashedPassword.Length > 128) { throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword); } using (EfDbContext Context = new EfDbContext()) { if (Context.Users.Where(Usr => Usr.Username == userName).Any()) { throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName); } string token = string.Empty; if (requireConfirmationToken) { token = GenerateToken(); } User NewUser = new User { UserId = Guid.NewGuid(), Username = userName, Password = hashedPassword, IsApproved = !requireConfirmationToken, Email = string.Empty, CreateDate = DateTime.UtcNow, LastPasswordChangedDate = DateTime.UtcNow, PasswordFailuresSinceLastSuccess = 0, LastLoginDate = DateTime.UtcNow, LastActivityDate = DateTime.UtcNow, LastLockoutDate = DateTime.UtcNow, IsLockedOut = false, LastPasswordFailureDate = DateTime.UtcNow, ConfirmationToken = token }; Context.Users.Add(NewUser); Context.SaveChanges(); return token; } }
public CategoryRepository(EfDbContext efDbContext) { _efDbContext = efDbContext; }
public MessageRepository(EfDbContext context) : base(context) { }
public SeedData WithResults(EfDbContext context) { // Look for any movies. if (context.Results.Any()) { return(this); // DB has been seeded } var now = DateTime.UtcNow; context.Results.AddRange( new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1), Url = "/information", IsSuccessStatusCode = true, StatusCode = 100, HeaderLength = 1000, ResponseLength = 2000, TotalLength = 3000, RequestSentTicks = 10000, ResponseTicks = 20000, TotalTicks = 30000, ResponseHeaders = "StatusCode: 200", CreatedDateTimeUtc = now.AddSeconds(1), CreatedByUserName = Environment.UserName }, new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1), Url = "/successful", IsSuccessStatusCode = true, StatusCode = 200, TotalTicks = 10000, TotalLength = 1000, ResponseHeaders = "Headers", CreatedDateTimeUtc = now.AddSeconds(2), CreatedByUserName = Environment.UserName }, new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1.1), Url = "/successful", IsSuccessStatusCode = true, StatusCode = 200, TotalTicks = 30000, TotalLength = 1000, ResponseHeaders = "Headers", CreatedDateTimeUtc = now.AddSeconds(2.2), CreatedByUserName = Environment.UserName }, new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1), Url = "/successful0001", IsSuccessStatusCode = true, StatusCode = 200, TotalTicks = 20000, TotalLength = 2000, ResponseHeaders = "Headers", CreatedDateTimeUtc = now.AddSeconds(3), CreatedByUserName = Environment.UserName }, new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1), Url = "/redirection", IsSuccessStatusCode = true, StatusCode = 300, ResponseHeaders = "Headers", CreatedDateTimeUtc = now.AddSeconds(4), CreatedByUserName = Environment.UserName }, new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1), Url = "/clientError", IsSuccessStatusCode = true, StatusCode = 400, ResponseHeaders = "Headers", CreatedDateTimeUtc = now.AddSeconds(5), CreatedByUserName = Environment.UserName }, new GlutResultItem { GlutProjectName = "Test", GlutProjectRunId = 1, StartDateTimeUtc = now, EndDateTimeUtc = now.AddSeconds(1), Url = "/serverError", IsSuccessStatusCode = true, StatusCode = 500, ResponseHeaders = null, Exception = new Exception("some error").ToString(), CreatedDateTimeUtc = now.AddSeconds(6), CreatedByUserName = Environment.UserName } ); context.SaveChanges(); return(this); }