public OperationResponse <IEnumerable <AppUser> > GetUsersByRoleId(string id) { var result = new OperationResponse <IEnumerable <AppUser> >(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { //result.Bag = dbLocator.Set<IdentityRole>().Where(o => o.Id == id).FirstOrDefault();.Select(entityItem => new AppUserRoleGetByIdCommandOutputDTO //{ // Id = entityItem.Id, // Name = entityItem.Name, // NormalizedName = entityItem.NormalizedName, //}).FirstOrDefault(); result.Bag = dbLocator.Set <IdentityUserRole <string> >().Where(userRole => userRole.RoleId == id).Join(dbLocator.Set <AppUser>(), userRole => userRole.UserId, user => user.Id, (userRole, user) => user /* new AppUserRoleGetByIdCommandOutputUserDTO * { * Id = user.Id, * RoleId = userRole.RoleId, * UserId = user.Id * }*/).ToList(); } } catch (Exception ex) { result.AddException($"Error Geting User {id}", ex); } return(result); }
private async Task CreateRecurringPayments() { var settingsManager = new SettingsManager(new SettingsAdapter()); try { Debug.WriteLine("RecurringPayment Job started."); ApplicationContext.DbPath = GetLocalFilePath(); var ambientDbContextLocator = new AmbientDbContextLocator(); var dbContextScopeFactory = new DbContextScopeFactory(); await new RecurringPaymentManager( new RecurringPaymentService(ambientDbContextLocator, dbContextScopeFactory), new PaymentService(ambientDbContextLocator, dbContextScopeFactory)) .CreatePaymentsUpToRecur(); Debug.WriteLine("RecurringPayment Job finished."); } catch (Exception ex) { Crashes.TrackError(ex); } finally { settingsManager.LastExecutionTimeStampRecurringPayments = DateTime.Now; } }
public OperationResponse <IEnumerable <CustomerFreightout> > GetAll() { var result = new OperationResponse <IEnumerable <CustomerFreightout> >(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { result.Bag = dbLocator.Set <CustomerFreightout>().AsEnumerable() /*.Select(entityItem => new CustomerFreightoutGetAllCommandOutputDTO * { * Id = entityItem.Id, * Cost = entityItem.Cost, * CustomerFreightoutRateTypeId = entityItem.CustomerFreightoutRateTypeId, * CustomerId = entityItem.CustomerId, * DateFrom = entityItem.DateFrom, * DateTo = entityItem.DateTo, * SecondLeg = entityItem.SecondLeg, * SurchargeHourly = entityItem.SurchargeHourly, * SurchargeYearly = entityItem.SurchargeYearly, * WProtect = entityItem.WProtect, * }).ToList()*/; } } catch (Exception ex) { result.AddException($"Error getting all customer freightout", ex); } return(result); }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IAmbientDbContextLocator, AmbientDbContextLocator>(new PerScopeLifetime()); container.Register <IRepository <ApplicationUser> >((x) => new Repository <ApplicationUser>(ambientDbContextLocator)); container.Register <IRepository <ApplicationRole> >((x) => new Repository <ApplicationRole>(ambientDbContextLocator)); container.Register <IRepository <ApplicationUserRole> >((x) => new Repository <ApplicationUserRole>(ambientDbContextLocator)); container.Register <IRepository <Category> >((x) => new Repository <Category>(ambientDbContextLocator)); container.Register <IRepository <Course> >((x) => new Repository <Course>(ambientDbContextLocator)); container.Register <IRepository <LessonsPerCourse> >((x) => new Repository <LessonsPerCourse>(ambientDbContextLocator)); container.Register <IRepository <UsersPerCourses> >((x) => new Repository <UsersPerCourses>(ambientDbContextLocator)); container.Register <IRepository <Incomes> >((x) => new Repository <Incomes>(ambientDbContextLocator)); container.Register <IRepository <ReviewPerCourse> >((x) => new Repository <ReviewPerCourse>(ambientDbContextLocator)); container.Register <IRepository <CourseLessonsLearnedPerStudent> >((x) => new Repository <CourseLessonsLearnedPerStudent>(ambientDbContextLocator)); container.Register <IUserService, UserService>(); container.Register <ICategoryService, CategoryService>(); container.Register <ICourseService, CourseService>(); container.Register <IInstructorService, InstructorService>(); container.Register <ILessonService, LessonService>(); container.Register <IStudentService, StudentService>(); container.Register <IWidgetService, WidgetService>(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var ambientDbLocater = new AmbientDbContextLocator(); var container = new Container(); container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle(); container.Register<IAmbientDbContextLocator, AmbientDbContextLocator>(Lifestyle.Singleton); container.Register<IUnitOfWork>(() => new EFUnitOfWork(), Lifestyle.Scoped); container.Register<IUnitOfWorkFactory>( () => new EFUnitOfWorkFactory(System.Data.IsolationLevel.ReadUncommitted)); container.Register<IClienteRepository, ClienteRepository>(); container.Register<IClientesService, ClientesService>(); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterMvcIntegratedFilterProvider(); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }
/// <summary> /// Initializes this instance. /// </summary> public override async void Initialize() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); using (dbContextScopeFactory.Create()) { await ambientDbContextLocator.Get<ApplicationContext>().Database.MigrateAsync(); } if (Mvx.Resolve<Session>().ValidateSession()) { if (CurrentPlatform == AppPlatform.UWP) { RegisterAppStart<AccountListViewModel>(); } else { RegisterAppStart<MainViewModel>(); } } else { RegisterAppStart<LoginViewModel>(); } }
public OperationResponse <AppUserRoleInsertCommandOutputDTO> Insert(AppUserRoleInsertCommandInputDTO input) { var result = new OperationResponse <AppUserRoleInsertCommandOutputDTO>(); try { var entity = new IdentityRole { Id = input.Id, Name = input.Name, NormalizedName = input.NormalizedName, }; var dbLocator = AmbientDbContextLocator.Get <IdentityDBContext>(); { dbLocator.Add(entity); dbLocator.SaveChanges(); var dto = dbLocator.Set <IdentityRole>().Where(o => o.Id == entity.Id).Select(o => new AppUserRoleInsertCommandOutputDTO { Id = o.Id, Name = o.Name, NormalizedName = o.NormalizedName, }).FirstOrDefault(); result.Bag = dto; } } catch (Exception ex) { result.AddException(null, ex); } return(result); }
public void Add_NewUserAddedAndReturned_UpdatesRepositoryFindsUser() { //TODO: Refactor test to do ONE thing not two //ARRANGE DatabaseTestUtility.DropCreateArbeDatabase(); var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var userRepository = new UserRepository(ambientDbContextLocator); User returnUser = null; var newUser = new User { UserId = 1, Name = "Kermit", Email = "*****@*****.**" }; //ACT using (var dbContextScope = dbContextScopeFactory.Create()) { userRepository.Add(newUser); dbContextScope.SaveChanges(); } //Now using a new dbContextScope - lets grab the data using (dbContextScopeFactory.CreateReadOnly()) { returnUser = userRepository.Find(1); } //ASSERT Assert.Equal(newUser.Name, returnUser.Name); }
public void CreateNewProjectWithPhotograph() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var projectRepository = new ProjectRepository(ambientDbContextLocator); var photographs = new List<Photograph>(); photographs.Add(new Photograph { Location="home", Title="photo title" }); photographs.Add(new Photograph { Location = "home2", Title = "photo title2" }); var projectService = new ProjectServices(dbContextScopeFactory, projectRepository); Project project = new Project { Description = "test", Title = "Test title", Photographs = photographs }; projectService.CreateProject(project); }
private async Task CheckRecurringPayments(JobParameters args) { try { Debug.WriteLine("RecurringPayment Job started."); DataAccess.ApplicationContext.DbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DatabaseConstants.DB_NAME); var ambientDbContextLocator = new AmbientDbContextLocator(); var dbContextScopeFactory = new DbContextScopeFactory(); await new RecurringPaymentManager( new RecurringPaymentService(ambientDbContextLocator, dbContextScopeFactory), new PaymentService(ambientDbContextLocator, dbContextScopeFactory)) .CreatePaymentsUpToRecur(); Debug.WriteLine("RecurringPayment Job finished."); JobFinished(args, false); } catch (Exception ex) { Debug.Write(ex); } }
private async Task CheckRecurringPayments(JobParameters args) { var settingsManager = new SettingsManager(new SettingsAdapter()); try { Debug.WriteLine("RecurringPayment Job started."); DataAccess.ApplicationContext.DbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DatabaseConstants.DB_NAME); var ambientDbContextLocator = new AmbientDbContextLocator(); var dbContextScopeFactory = new DbContextScopeFactory(); await new RecurringPaymentManager( new RecurringPaymentService(ambientDbContextLocator, dbContextScopeFactory), new PaymentService(ambientDbContextLocator, dbContextScopeFactory)) .CreatePaymentsUpToRecur(); Debug.WriteLine("RecurringPayment Job finished."); JobFinished(args, false); } catch (Exception ex) { Crashes.TrackError(ex); } finally { settingsManager.LastExecutionTimeStampRecurringPayments = DateTime.Now; } }
public void Add_100_OrderItem() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var orderFactory = new OrderFactory(); using (var dbContextScope = dbContextScopeFactory.Create()) { var personRepository = new PersonRepository(ambientDbContextLocator); var orderRepository = new OrderRepository(ambientDbContextLocator); var person = personRepository.GetByName("ding.p"); var order = orderFactory.CreateOrder(person); orderRepository.Add(order); for (int i = 0; i < 100; i++) { var orderItem = order.CreateItem("A-" + i); order.OrderLine.Add(orderItem); } dbContextScope.SaveChanges(); } }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IAmbientDbContextLocator, AmbientDbContextLocator>(new PerScopeLifetime()); container.Register <IRepository <ApplicationUser> >((x) => new Repository <ApplicationUser>(ambientDbContextLocator)); container.Register <IRepository <ApplicationRole> >((x) => new Repository <ApplicationRole>(ambientDbContextLocator)); container.Register <IRepository <Course> >((x) => new Repository <Course>(ambientDbContextLocator)); container.Register <IRepository <Student> >((x) => new Repository <Student>(ambientDbContextLocator)); //eincio container.Register <IRepository <Persona> >((x) => new Repository <Persona>(ambientDbContextLocator)); container.Register <IRepository <TipoDocumento> >((x) => new Repository <TipoDocumento>(ambientDbContextLocator)); container.Register <IRepository <StudentPerCourse> >((x) => new Repository <StudentPerCourse>(ambientDbContextLocator)); container.Register <IStudentService, StudentService>(); //eincio container.Register <ITipoDocumentoService, TipoDocumentoService>(); container.Register <IPersonaService, PersonaService>(); container.Register <IStudentPerCourseService, StudentPerCourseService>(); container.Register <ICourseService, CourseService>(); container.Register <IUserService, UserService>(); }
public OperationResponse <CustomerThirdPartyAppSettingInsertCommandOutputDTO> Insert(CustomerThirdPartyAppSettingInsertCommandInputDTO input) { var result = new OperationResponse <CustomerThirdPartyAppSettingInsertCommandOutputDTO>(); var entity = new CustomerThirdPartyAppSetting { CustomerId = input.CustomerId, ThirdPartyAppTypeId = input.ThirdPartyAppTypeId, ThirdPartyCustomerId = input.ThirdPartyCustomerId, }; var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { dbLocator.Add(entity); dbLocator.SaveChanges(); var dbResult = dbLocator.Set <CustomerThirdPartyAppSetting>().Where(o => o.Id == entity.Id).Select(o => new CustomerThirdPartyAppSettingInsertCommandOutputDTO { Id = o.Id, CustomerId = o.CustomerId, CustomerName = o.Customer.Name, ThirdPartyAppTypeId = o.ThirdPartyAppTypeId, ThirdPartyCustomerId = o.ThirdPartyCustomerId, }).FirstOrDefault(); result.Bag = dbResult; return(result); } }
public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); Debug.WriteLine("RecurringPaymentTask started."); ApplicationContext.DbPath = DatabaseConstants.DB_NAME; try { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); await new RecurringPaymentManager( new RecurringPaymentService(dbContextScopeFactory, ambientDbContextLocator), new PaymentService(ambientDbContextLocator, dbContextScopeFactory)) .CreatePaymentsUpToRecur(); } catch (Exception ex) { Debug.Write(ex); Debug.WriteLine("RecurringPaymentTask stopped due to an error."); } finally { Debug.WriteLine("RecurringPaymentTask finished."); deferral.Complete(); } }
public OperationResponse <IEnumerable <IdentityRoleClaim <string> > > GetPermissionsByRoleId(string id) { var result = new OperationResponse <IEnumerable <IdentityRoleClaim <string> > >(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { //result.Bag = dbLocator.Set<IdentityRole>().Where(o => o.Id == id).FirstOrDefault();.Select(entityItem => new AppUserRoleGetByIdCommandOutputDTO //{ // Id = entityItem.Id, // Name = entityItem.Name, // NormalizedName = entityItem.NormalizedName, //}).FirstOrDefault(); result.Bag = dbLocator.Set <IdentityRoleClaim <string> >().Where(roleClaim => roleClaim.RoleId == id && roleClaim.ClaimType == "per").Select(roleClaim => roleClaim /*new AppUserRoleGetByIdCommandOutputPermissionDTO * { * RoleId = roleClaim.RoleId, * PermissionId = roleClaim.ClaimValue, * }*/).ToList(); } } catch (Exception ex) { result.AddException($"Error Geting User {id}", ex); } return(result); }
public OperationResponse Insert(ProductMedia input) { var result = new OperationResponse <ProductMediaInsertCommandOutputDTO>(); var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); dbLocator.Add(input); return(result); }
public override async Task Startup() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); using (dbContextScopeFactory.Create()) { await ambientDbContextLocator.Get <ApplicationContext>().Database.MigrateAsync(); } }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IAmbientDbContextLocator, AmbientDbContextLocator>(new PerScopeLifetime()); container.Register <IRepository <Model.Domain.Employee> >((x) => new Repository <Model.Domain.Employee>(ambientDbContextLocator)); container.Register <IEmployeeService, EmployeeService>(); }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IAmbientDbContextLocator, AmbientDbContextLocator>(new PerScopeLifetime()); container.Register <IRepository <ApplicationUser> >((x) => new Repository <ApplicationUser>(ambientDbContextLocator)); container.Register <IRepository <ApplicationRole> >((x) => new Repository <ApplicationRole>(ambientDbContextLocator)); container.Register <IRepository <ApplicationUserRole> >((x) => new Repository <ApplicationUserRole>(ambientDbContextLocator)); }
/// <summary> /// Initializes this instance. /// </summary> public override async void Initialize() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); using (dbContextScopeFactory.Create()) { await ambientDbContextLocator.Get <ApplicationContext>().Database.MigrateAsync(); } RegisterAppStart(new AppStart()); }
public PresupuestoRepositoryTests() { var ambientDbContextLocator = new AmbientDbContextLocator(); uowFactory = new EFUnitOfWorkFactory(System.Data.IsolationLevel.ReadCommitted); repository = new PresupuestoRepository(ambientDbContextLocator); clienteRepository = new ClienteRepository(ambientDbContextLocator); vehiculoRepository = new VehiculoRepository(ambientDbContextLocator); cliente = new Cliente("Carlos", "Tirado", "941", true); vehiculo = new Vehiculo("Opel", "Astra", 200); cliente2 = new Cliente("Juan", "Pérez", "941", false); vehiculo2 = new Vehiculo("Reanult", "Megane", 210); }
/// <summary> /// Setup Logic who is executed before every test /// </summary> public CategoryServiceTests() { ApplicationContext.DbPath = Path.Combine(AppContext.BaseDirectory, DatabaseConstants.DB_NAME); Dispose(); dbContextScopeFactory = new DbContextScopeFactory(); ambientDbContextLocator = new AmbientDbContextLocator(); using (dbContextScopeFactory.Create()) { ambientDbContextLocator.Get <ApplicationContext>().Database.Migrate(); } }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IAmbientDbContextLocator, AmbientDbContextLocator>(new PerScopeLifetime()); container.Register <IRepository <ApplicationUser> >((x) => new Repository <ApplicationUser>(ambientDbContextLocator)); container.Register <IRepository <ApplicationRole> >((x) => new Repository <ApplicationRole>(ambientDbContextLocator)); container.Register <IRepository <ApplicationUserRole> >((x) => new Repository <ApplicationUserRole>(ambientDbContextLocator)); container.Register <IUserService, UserService>();//Todas las clases que implementen esta interface pueden ser registradas }
public OperationResponse <CustomerFreightoutUpdateCommandOutputDTO> Update(CustomerFreightoutUpdateCommandInputDTO input) { var result = new OperationResponse <CustomerFreightoutUpdateCommandOutputDTO>(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { var entity = dbLocator.Set <CustomerFreightout>().FirstOrDefault(o => o.Id == input.Id); if (entity != null) { entity.Cost = input.Cost; entity.CustomerFreightoutRateTypeId = input.CustomerFreightoutRateTypeId; entity.CustomerId = input.CustomerId; entity.DateFrom = input.DateFrom; entity.DateTo = input.DateTo; entity.SecondLeg = input.SecondLeg; entity.SurchargeHourly = input.SurchargeHourly; entity.SurchargeYearly = input.SurchargeYearly; entity.WProtect = input.WProtect; } dbLocator.SaveChanges(); var dbResult = dbLocator.Set <CustomerFreightout>().Where(o => o.Id == entity.Id).Select(o => new CustomerFreightoutUpdateCommandOutputDTO { Id = o.Id, CustomerId = o.CustomerId, CustomerName = o.Customer.Name, Cost = o.Cost, CustomerFreightoutRateTypeId = o.CustomerFreightoutRateTypeId, DateFrom = o.DateFrom, DateTo = o.DateTo, SecondLeg = o.SecondLeg, SurchargeHourly = o.SurchargeHourly, SurchargeYearly = o.SurchargeYearly, WProtect = o.WProtect, }).FirstOrDefault(); result.Bag = dbResult; return(result); } } catch (Exception ex) { } return(result); }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IAmbientDbContextLocator, AmbientDbContextLocator>(new PerScopeLifetime()); container.Register <IRepository <Usuarios> >((x) => new Repository <Usuarios>(ambientDbContextLocator)); container.Register <IRepository <Categoria> >((x) => new Repository <Categoria>(ambientDbContextLocator)); container.Register <IUsuarioService, UsuarioService>(); container.Register <ICategoriaService, CategoriaService>(); }
public void Compose(IServiceRegistry container) { var ambientDbContextLocator = new AmbientDbContextLocator(); container.Register <IDbContextScopeFactory>((x) => new DbContextScopeFactory(null)); container.Register <IRepository <Student> >((x) => new Repository <Student>(ambientDbContextLocator)); container.Register <IRepository <Course> >((x) => new Repository <Course>(ambientDbContextLocator)); container.Register <IRepository <StudentPerCourse> >((x) => new Repository <StudentPerCourse>(ambientDbContextLocator)); container.Register <IStudentService, StudentService>(); container.Register <IStudentPerCourseService, StudentPerCourseService>(); container.Register <ICourseService, CourseService>(); }
protected LocalRepoMoviesTests(IConfig config) : base() { Config = config; var contextFactory = new TestDbContextFactory(Config); DbContextScopeFactory = new DbContextScopeFactory(contextFactory); AmbientDbContextLocator = new AmbientDbContextLocator(); MovieDetailsDbAccess = new MovieDetailsDbAccess(AmbientDbContextLocator, Mapper, config); MovieListsDbAccess = new MoviesListsDbAccess(AmbientDbContextLocator, Mapper); using var context = DbContextScopeFactory.Create(); MoviesContext.Database.EnsureDeleted(); MoviesContext.Database.EnsureCreated(); }
public void DeletePhotograph() { CreateANewPhotograph(); var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var photographRepository = new PhotographRepository(ambientDbContextLocator); var photographService = new PhotographServices(dbContextScopeFactory, photographRepository); //var userQueryService = new UserQueryService(dbContextScopeFactory, userRepository); //var userEmailService = new UserEmailService(dbContextScopeFactory); //var userCreditScoreService = new UserCreditScoreService(dbContextScopeFactory); Assert.IsTrue(photographService.RemovePhotography((new Photograph { PhotographId = Guid.Empty }))); }
public OperationResponse Add(ColorReference entity) { var result = new OperationResponse(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); dbLocator.Add(entity); } catch (Exception ex) { result.AddException($"Error adding Funza Color", ex); } return(result); }
public OperationResponse Insert(SampleBox entity) { var result = new OperationResponse(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); dbLocator.Add(entity); } catch (Exception ex) { result.AddException($"Error adding Sample Box ", ex); } return(result); }
public OperationResponse <SampleBox> GetByIdWithMedias(int id) { var result = new OperationResponse <SampleBox>(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); result.Bag = dbLocator.Set <SampleBox>() /*.Include(t => t.ProductMedias)*/.Where(o => o.Id == id).FirstOrDefault(); } catch (Exception ex) { result.AddException($"Error getting Sample Box {id}", ex); } return(result); }
/// <summary> /// Setup Logic who is executed before every test /// </summary> public PaymentRepositoryTests() { ApplicationContext.DbPath = Path.Combine(AppContext.BaseDirectory, DatabaseConstants.DB_NAME); dbContextScopeFactory = new DbContextScopeFactory(); ambientDbContextLocator = new AmbientDbContextLocator(); using (dbContextScopeFactory.Create()) { ambientDbContextLocator.Get <ApplicationContext>().Database.Migrate(); } using (var db = new ApplicationContext()) { db.Database.Migrate(); } }
public OperationResponse Add(Product entity) { var result = new OperationResponse(); try { var dbLocator = AmbientDbContextLocator.Get <FunzaDBContext>(); dbLocator.Add(entity); } catch (Exception ex) { result.AddException($"Error adding Funza Product", ex); } return(result); }
public OperationResponse Insert(ProductCategory entity) { var result = new OperationResponse(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); dbLocator.Add(entity); } catch (Exception ex) { result.AddException($"Error adding customer freightout", ex); } return(result); }
public void CreateANewPhotograph() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var photographRepository = new PhotographRepository(ambientDbContextLocator); var photographService = new PhotographServices(dbContextScopeFactory, photographRepository); //var userQueryService = new UserQueryService(dbContextScopeFactory, userRepository); //var userEmailService = new UserEmailService(dbContextScopeFactory); //var userCreditScoreService = new UserCreditScoreService(dbContextScopeFactory); Photograph newPhoto = new Photograph(); newPhoto.Location = "testlocation"; Assert.IsTrue(photographService.UploadPhotography(newPhoto)); Guid uploadID = newPhoto.PhotographId; Assert.IsTrue(photographService.RemovePhotography(newPhoto)); }
public void GetAPhotograph() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var photographRepository = new PhotographRepository(ambientDbContextLocator); var photographService = new PhotographServices(dbContextScopeFactory, photographRepository); //var userQueryService = new UserQueryService(dbContextScopeFactory, userRepository); //var userEmailService = new UserEmailService(dbContextScopeFactory); //var userCreditScoreService = new UserCreditScoreService(dbContextScopeFactory); var photo = photographService.GetPhotograph(new Guid("9a1f9e3e-b389-e511-9c5a-00249b0905d8")); foreach (var photographInProject in photo.Projects) { foreach (var actualPhoto in photographInProject.Photographs) { string a= actualPhoto.Title; } } var photo2 = photographService.GetPhotograph(new Guid("1a1f9e3e-b389-e511-9c5a-00249b0905d8")); Assert.IsNotNull(photo); }
static void Main(string[] args) { //-- Poor-man DI - build our dependencies by hand for this demo var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var userRepository = new UserRepository(ambientDbContextLocator); var userCreationService = new UserCreationService(dbContextScopeFactory, userRepository); var userQueryService = new UserQueryService(dbContextScopeFactory, userRepository); var userEmailService = new UserEmailService(dbContextScopeFactory); var userCreditScoreService = new UserCreditScoreService(dbContextScopeFactory); try { Console.WriteLine("This demo application will create a database named DbContextScopeDemo in the default SQL Server instance on localhost. Edit the connection string in UserManagementDbContext if you'd like to create it somewhere else."); Console.WriteLine("Press enter to start..."); Console.ReadLine(); //-- Demo of typical usage for read and writes Console.WriteLine("Creating a user called Mary..."); var marysSpec = new UserCreationSpec("Mary", "*****@*****.**"); userCreationService.CreateUser(marysSpec); Console.WriteLine("Done.\n"); Console.WriteLine("Trying to retrieve our newly created user from the data store..."); var mary = userQueryService.GetUser(marysSpec.Id); Console.WriteLine("OK. Persisted user: {0}", mary); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); //-- Demo of nested DbContextScopes Console.WriteLine("Creating 2 new users called John and Jeanne in an atomic transaction..."); var johnSpec = new UserCreationSpec("John", "*****@*****.**"); var jeanneSpec = new UserCreationSpec("Jeanne", "*****@*****.**"); userCreationService.CreateListOfUsers(johnSpec, jeanneSpec); Console.WriteLine("Done.\n"); Console.WriteLine("Trying to retrieve our newly created users from the data store..."); var createdUsers = userQueryService.GetUsers(johnSpec.Id, jeanneSpec.Id); Console.WriteLine("OK. Found {0} persisted users.", createdUsers.Count()); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); //-- Demo of nested DbContextScopes in the face of an exception. // If any of the provided users failed to get persisted, none should get persisted. Console.WriteLine("Creating 2 new users called Julie and Marc in an atomic transaction. Will make the persistence of the second user fail intentionally in order to test the atomicity of the transaction..."); var julieSpec = new UserCreationSpec("Julie", "*****@*****.**"); var marcSpec = new UserCreationSpec("Marc", "*****@*****.**"); try { userCreationService.CreateListOfUsersWithIntentionalFailure(julieSpec, marcSpec); Console.WriteLine("Done.\n"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(); } Console.WriteLine("Trying to retrieve our newly created users from the data store..."); var maybeCreatedUsers = userQueryService.GetUsers(julieSpec.Id, marcSpec.Id); Console.WriteLine("Found {0} persisted users. If this number is 0, we're all good. If this number is not 0, we have a big problem.", maybeCreatedUsers.Count()); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); //-- Demo of explicit database transaction. Console.WriteLine("Trying to retrieve user John within a READ UNCOMMITTED database transaction..."); // You'll want to use SQL Profiler or Entity Framework Profiler to verify that the correct transaction isolation // level is being used. var userMaybeUncommitted = userQueryService.GetUserUncommitted(johnSpec.Id); Console.WriteLine("OK. User found: {0}", userMaybeUncommitted); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); //-- Demo of disabling the DbContextScope nesting behaviour in order to force the persistence of changes made to entities // This is a pretty advanced feature that you can safely ignore until you actually need it. Console.WriteLine("Will simulate sending a Welcome email to John..."); using (var parentScope = dbContextScopeFactory.Create()) { var parentDbContext = parentScope.DbContexts.Get<UserManagementDbContext>(); // Load John in the parent DbContext var john = parentDbContext.Users.Find(johnSpec.Id); Console.WriteLine("Before calling SendWelcomeEmail(), john.WelcomeEmailSent = " + john.WelcomeEmailSent); // Now call our SendWelcomeEmail() business logic service method, which will // update John in a non-nested child context userEmailService.SendWelcomeEmail(johnSpec.Id); // Verify that we can see the modifications made to John by the SendWelcomeEmail() method Console.WriteLine("After calling SendWelcomeEmail(), john.WelcomeEmailSent = " + john.WelcomeEmailSent); // Note that even though we're not calling SaveChanges() in the parent scope here, the changes // made to John by SendWelcomeEmail() will remain persisted in the database as SendWelcomeEmail() // forced the creation of a new DbContextScope. } Console.WriteLine("Press enter to continue..."); Console.ReadLine(); //-- Demonstration of DbContextScope and parallel programming Console.WriteLine("Calculating and storing the credit score of all users in the database in parallel..."); userCreditScoreService.UpdateCreditScoreForAllUsers(); Console.WriteLine("Done."); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); Console.WriteLine("The end."); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }
public void GetAllPhotograph() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); var photographRepository = new PhotographRepository(ambientDbContextLocator); var photographService = new PhotographServices(dbContextScopeFactory, photographRepository); var photo = photographService.GetAllPhotographs(); //foreach (var photograph in photo) //{ // var tempt = photograph.Title; // foreach(var tempphot in photograph.Projects) // { // var t = tempphot.Title; // } //} Assert.IsNotNull(photo); }
public ClienteRepositoryTests() { var ambientDbContextLocator = new AmbientDbContextLocator(); uowFactory = new EFUnitOfWorkFactory(System.Data.IsolationLevel.ReadCommitted); repository = new ClienteRepository(ambientDbContextLocator); }