public User CreateUser(User userToCreate) { User createdUser = new User() { UserSpecializations = userToCreate.UserSpecializations, UserPhoneNumber = userToCreate.UserPhoneNumber, UserYearsOfExperience = userToCreate.UserYearsOfExperience, DescriptionOfUser = userToCreate.DescriptionOfUser, Name = userToCreate.Name, LastName = userToCreate.Name, BirthDate = userToCreate.BirthDate, Age = userToCreate.Age, City = userToCreate.City, State = userToCreate.State, PostalCode = userToCreate.PostalCode, Country = userToCreate.Country, DateCreated = DateTime.Now, LastModified = DateTime.Now }; _context.Users.Add(createdUser); _context.SaveChanges(); return(createdUser); }
public IActionResult Create(string reference, string path, string name) { if (ModelState.IsValid) { gitCloneServices.GitClone(reference, path); gitInitService.GitInit(path); var repos = new Repos { Name = name, Path = path }; _context.Add(repos); _context.SaveChanges(); var analysis = new Analysis { Date = DateTime.Now, Repos = _context.Repos.SingleOrDefault(x => x.Id == repos.Id) }; _context.Add(analysis); _context.SaveChanges(); int RepoId = repos.Id; string Path = path; int AnalysisId = analysis.Id; counterChange.CounterChangeFileInLocalrepositiry(RepoId, Path, AnalysisId); } return(View("Index")); }
static void Main(string[] args) { Console.WriteLine("Creating Default Db Context"); //To connect to an sql or azure sql server jusr use: UseSqlServer(connectionString) var options = new DbContextOptionsBuilder <RepositoryDbContext>() .UseSqlite("Data Source=endavaUniversity.db") //.UseLoggerFactory(loggerFactory) .Options; using (var db = new RepositoryDbContext(options)) { // Create var user = new User { FirstName = "Maria", LastName = "Antuanetta" }; Console.WriteLine($"Inserting a new user: {user.FirstName} {user.LastName}."); db.Add(user); db.SaveChanges(); // Read Console.WriteLine("Querying for a user"); var returnedUser = db.Users .OrderBy(u => u.Id) .Where(u => u.FirstName.Equals(user.FirstName)).First(); Console.WriteLine($"User: {returnedUser.FirstName} {returnedUser.LastName}; Id: {returnedUser.Id}"); // Update Console.WriteLine("Updating the user (Carlos) and adding a wallet"); returnedUser.LastName = "Carlos"; returnedUser.Wallets.Add( new Wallet { Amount = 100, Currency = "USD", }); db.SaveChanges(); // Read Console.WriteLine("Querying for an updated user"); var updatedUser = db.Users .OrderBy(u => u.Id) .Where(u => u.FirstName.Equals(user.FirstName)).First(); Console.WriteLine($"User: {updatedUser.FirstName} {updatedUser.LastName}; Id: {updatedUser.Id}"); Console.WriteLine($"User' wallet Id: {updatedUser.Wallets.First()?.Id}"); Console.WriteLine($"Wallet' user Id: {updatedUser.Wallets.First()?.UserId}"); // Delete Console.WriteLine("Delete the user"); db.Remove(updatedUser); db.SaveChanges(); } }
public void UpdateEntity(TEntity entity, bool isSave = true) { if (isSave) { RepositoryDbContext.SaveChanges(); } }
public async Task Returns_All_Items() { var model1 = new ServiceApiDescriptionBuilder().WithServiceId("AllItem1").Build(); var model2 = new ServiceApiDescriptionBuilder().WithServiceId("AllItem2").Build(); using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.RemoveRange(context.Apis.ToArray()); context.Apis.Add(model1.ToEntity()); context.Apis.Add(model2.ToEntity()); context.SaveChanges(); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object); var services = (await store.GetAllAsync()).OrderBy(s => s.ServiceId).ToList(); services.Should().HaveCount(2); services[0].ServiceId.Should().Be(model1.ServiceId); services[0].ApiDocument.Info.Title.Should().Be(model1.ApiDocument.Info.Title); services[1].ServiceId.Should().Be(model2.ServiceId); services[1].ApiDocument.Info.Title.Should().Be(model2.ApiDocument.Info.Title); } }
public async Task Updates_ApiDocument_On_Existing_Item() { var model = new ServiceApiDescriptionBuilder().WithServiceId("Updates_DisplayName_On_Existing_Item").Build(); using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.Add(model.ToEntity()); context.SaveChanges(); } model.ApiDocument.Info.Title = "New title"; using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object); await store.StoreAsync(model); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var item = context.Apis.SingleOrDefault(s => s.ServiceId == model.ServiceId); item.Should().NotBeNull(); var document = OpenApiDocumentHelper.ReadFromJson(item.ApiDocument); document.Info.Title.Should().Be(model.ApiDocument.Info.Title); } }
public SignInResult PasswordSignIn(string loginName, string password, bool rememberMe, bool shouldLockout = false) { var result = new SignInResult(); using (var context = new RepositoryDbContext()) { var md5Password = Globals.GetMd5(password); var user = context.Set <WdUser>() .FirstOrDefault(obj => obj.LoginName == loginName && obj.Password == md5Password && obj.IsEnabled); if (user == null) { result.Status = SignInStatus.Failure; result.ErrorElement = "Password"; result.ErrorMessage = "无效的用户名或登陆密码"; return(result); } FormsAuthentication.SetAuthCookie(loginName, false); user.LastLoginDateTime = DateTime.Now; context.SaveChanges(); } result.Status = SignInStatus.Success; return(result); }
public void InsertEntity(TEntity entity, bool isSave = true) { Entities.Add(entity); if (isSave) { RepositoryDbContext.SaveChanges(); } }
/// <summary> /// /// </summary> public void SeedCustomers() { string customerData = System.IO.File.ReadAllText("Data/CustomerSeedData.json"); var customers = JsonConvert.DeserializeObject <List <CustomerModel> >(customerData); _customerDbContext.AddRange(customers); _customerDbContext.SaveChanges(); }
public void DeleteEntity(TEntity entity, bool isSave = true) { Entities.Remove(entity); if (isSave) { RepositoryDbContext.SaveChanges(); } }
public DbContextFixture() { var options = new DbContextOptionsBuilder <RepositoryDbContext>() .UseInMemoryDatabase("VendingMachine") .Options; Context = new RepositoryDbContext(options); Context.Coins.AddRange(TestData.Coins); Context.Products.AddRange(TestData.Products); Context.SaveChanges(); }
public void SaveDataMock() { if (this.usersMock != null && this.usersMock.Any()) { dbContextMock.Users.AddRange(this.usersMock); } if (this.userFeedbacksMock != null && this.userFeedbacksMock.Any()) { dbContextMock.UserFeedbacks.AddRange(this.userFeedbacksMock); } dbContextMock.SaveChanges(); }
public Account CreateAccount(Account accountToCreate) { Account newAcc = new Account() { AccountEmailAsLoginHash = Hashing.HashPassword(accountToCreate.AccountEmailAsLoginHash), AccountPasswordHash = Hashing.HashPassword(accountToCreate.AccountPasswordHash), DateCreated = DateTime.Now, LastModified = DateTime.Now, }; _context.Accounts.Add(newAcc); _context.SaveChanges(); User newUsr = new User() { UserEmailAdressHash = Hashing.HashPassword(accountToCreate.AccountEmailAsLoginHash) }; _context.Users.Add(newUsr); _context.SaveChanges(); return(newAcc); }
public async Task Removes_Existing_Item() { var model = new ServiceApiDescriptionBuilder().WithServiceId("Removes_Existing_Item").Build(); using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.Add(model.ToEntity()); context.SaveChanges(); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object); await store.RemoveAsync(model.ServiceId); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.SingleOrDefault(s => s.ServiceId == model.ServiceId).Should().BeNull(); } }
public async Task Returns_Item_When_Api_Exists() { var model = new ServiceApiDescription { ServiceId = "Returns_Item_When_Api_Exists" }; using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.Add(model.ToEntity()); context.SaveChanges(); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object); var item = await store.FindByServiceIdAsync(model.ServiceId); item.Should().NotBeNull(); } }
private static void CreateUsers(RepositoryDbContext context) { var users = new List <User>(); var currentUsers = context.Users.ToList(); for (int i = 0; i < 10; i++) { var newUser = new User(Guid.NewGuid(), $"Nickname_{i}", $"User{i}", $"user.{i}@testUsers.com"); var existingUser = currentUsers.FirstOrDefault(cu => cu.NickName.Equals(newUser.NickName) && cu.Name.Equals(newUser.Name)); if (existingUser == null) { users.Add(newUser); } } if (users.Any() && users.Count > 0) { context.Users.AddRange(users); context.SaveChanges(); } }
public async Task Returns_Item_With_All_Properties_When_Api_Exists() { var model = new ServiceApiDescriptionBuilder().Build(); using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { context.Apis.Add(model.ToEntity()); context.SaveChanges(); } using (var context = new RepositoryDbContext(DbContextOptions, StoreOptions)) { var store = new ApiStore(context, new Mock <ILogger <ApiStore> >().Object); var item = await store.FindByServiceIdAsync(model.ServiceId); item.Should().NotBeNull(); item.ServiceId.Should().Be(model.ServiceId); // TODO check api document } }
public RepositoryActionResult <User> ConnectUserWithAccount(User userToConnect, Account accountToConnect) { try { if (userToConnect == null || accountToConnect == null) { return(new RepositoryActionResult <User>(userToConnect, RepositoryActionStatus.NotFound)); } User userToCon = _context.Users .Where(u => u.UserId == userToConnect.UserId) .FirstOrDefault(); Account accountToCon = _context.Accounts .Where(a => a.AccountId == accountToConnect.AccountId) .FirstOrDefault(); userToCon.UserEmailAdressHash = accountToCon.AccountEmailAsLoginHash; accountToCon.AccountOfUserId = userToCon.UserId; _context.SaveChanges(); var checkUser = _context.Users.Where(u => u.UserEmailAdressHash == userToConnect.UserEmailAdressHash).FirstOrDefault(); if (checkUser == null) { return(new RepositoryActionResult <User>(checkUser, RepositoryActionStatus.NotFound)); } else { return(new RepositoryActionResult <User>(checkUser, RepositoryActionStatus.Connected)); } } catch (Exception) { throw; } }
public void Save() { _context.SaveChanges(); }
public int Save() { return(Db.SaveChanges()); }
public void Complete() { _context.SaveChanges(); }
/// <summary> /// /// </summary> /// <param name="serviceProvider"></param> public static void Initialize(IServiceProvider serviceProvider) { using (RepositoryDbContext context = new RepositoryDbContext( serviceProvider.GetRequiredService <DbContextOptions <RepositoryDbContext> >())) { // Look for any customer list if (context.Customers.Any()) { return; // Data was already seeded } List <AddressModel> addressList = new List <AddressModel>() { new AddressModel() { AddressLine1 = "201 Malagasang 1-D", AddressLine2 = "209 Bucandala 5", City = "Imus City", State = "Cavite", CustomerId = 1 }, new AddressModel() { AddressLine1 = "155 Bayan Luma", AddressLine2 = "199 Aust 5", City = "Imus City", State = "Cavite", CustomerId = 1 }, new AddressModel() { AddressLine1 = "198 Guadalupe Nuevo", AddressLine2 = "8797 Northern Lights", City = "Makati City", State = "Metro Manila", CustomerId = 2 }, new AddressModel() { AddressLine1 = "6789 HV Dela Costa", AddressLine2 = "8694 Camella", City = "Pasay City", State = "Metro Manila", CustomerId = 2 }, new AddressModel() { AddressLine1 = "4623 Bacoor", AddressLine2 = "Sabang St.", City = "Quezon City", State = "Metro Manila", CustomerId = 3 }, new AddressModel() { AddressLine1 = "903 Bel-Air", AddressLine2 = "Dasmarinas St.", City = "Las Pinas City", State = "Metro Manila", CustomerId = 4 }, new AddressModel() { AddressLine1 = "8323 Perea", AddressLine2 = "Subah", City = "Cubao City", State = "Metro Manila", CustomerId = 5 } }; ICollection <AddressModel> addressColletion = addressList; context.Customers.AddRange ( new CustomerModel() { Id = 1, FullName = "Juan Dela Cruz", Age = 25, DateOfBirth = DateTime.Parse("10/02/1995"), Address = addressColletion }, new CustomerModel() { Id = 2, FullName = "Jane Doe", Age = 24, DateOfBirth = DateTime.Parse("04/02/1996"), Address = addressColletion }, new CustomerModel() { Id = 3, FullName = "Marco Fuentes", Age = 23, DateOfBirth = DateTime.Parse("08/02/1997"), Address = addressColletion }, new CustomerModel() { Id = 4, FullName = "Mary Jane Herrera", Age = 23, DateOfBirth = DateTime.Parse("05/02/1997"), Address = addressColletion }, new CustomerModel() { Id = 5, FullName = "Catriona Grey", Age = 23, DateOfBirth = DateTime.Parse("09/02/1997"), Address = addressColletion } ); context.SaveChanges(); } }
public int Complete() { return(db.SaveChanges()); }