public async void SaveAccount_AccountSavedAndLoaded() { // Arrange AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { using (var dbContext = ambientDbContextLocator.Get <ApplicationContext>()) { testAccount = new AccountEntity { Name = "testAccount" }; dbContext.Accounts.Add(testAccount); await dbContextScope.SaveChangesAsync(); } } var paymentService = new PaymentService(ambientDbContextLocator, dbContextScopeFactory); var testEntry = new Payment(new PaymentEntity { ChargedAccount = testAccount }); // Act await paymentService.SavePayments(testEntry); // Assert Assert.Equal(testEntry.Data.Amount, (await paymentService.GetById(testEntry.Data.Id)).Data.Amount); }
public OperationResponse <AppUserRoleUpdateCommandOutputDTO> Update(AppUserRoleUpdateCommandInputDTO input) { var result = new OperationResponse <AppUserRoleUpdateCommandOutputDTO>(); var dbLocator = AmbientDbContextLocator.Get <IdentityDBContext>(); { var entity = dbLocator.Set <IdentityRole>().FirstOrDefault(o => o.Id == input.Id); if (entity != null) { entity.Id = input.Id; entity.Name = input.Name; entity.NormalizedName = input.NormalizedName; } dbLocator.SaveChanges(); var dbResult = dbLocator.Set <IdentityRole>().Where(o => o.Id == entity.Id).Select(o => new AppUserRoleUpdateCommandOutputDTO { Id = o.Id, Name = o.Name, NormalizedName = o.NormalizedName, }).FirstOrDefault(); result.Bag = dbResult; return(result); } }
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 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 <IEnumerable <IdentityRole> > GetRolesByUserId(string id) { var result = new OperationResponse <IEnumerable <IdentityRole> >(); 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.UserId == id).Join(dbLocator.Set <IdentityRole>(), userRole => userRole.RoleId, role => role.Id, (userRole, role) => role /* new AppUserRoleGetByIdCommandOutputUserDTO * { * Id = user.Id, * RoleId = userRole.RoleId, * UserId = user.Id * }*/).ToList(); } } catch (Exception ex) { result.AddException($"Error Geting User {id}", ex); } return(result); }
/// <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 <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 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 TestDbContextScopeWorks() { using var context = DbContextScopeFactory.CreateReadOnly(); var moviesContext = AmbientDbContextLocator.Get <MoviesContext>(); Assert.IsNotNull(moviesContext.Movies.Find(TestMovieSeededWithoutRelatedInfo.Id)); }
public override async Task Startup() { var dbContextScopeFactory = new DbContextScopeFactory(); var ambientDbContextLocator = new AmbientDbContextLocator(); using (dbContextScopeFactory.Create()) { await ambientDbContextLocator.Get <ApplicationContext>().Database.MigrateAsync(); } }
public OperationResponse Insert(ProductMedia input) { var result = new OperationResponse <ProductMediaInsertCommandOutputDTO>(); var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); dbLocator.Add(input); return(result); }
/// <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()); }
/// <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 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 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 <DomainModel.Product.AbstractProduct> GetByIdWithMedias(int id) { var result = new OperationResponse <DomainModel.Product.AbstractProduct>(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); result.Bag = dbLocator.Set <AbstractProduct>().Include(t => t.ProductMedias).Where(o => o.Id == id).FirstOrDefault(); } catch (Exception ex) { result.AddException($"Error getting Product {id}", ex); } return(result); }
public OperationResponse <Grower> GetById(int id) { var result = new OperationResponse <Grower>(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); result.Bag = dbLocator.Set <Grower>().Where(o => o.Id == id).FirstOrDefault(); } catch (Exception ex) { result.AddException($"Error getting Grower {id}", 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 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 Insert(CompositionProductBridge entity) { var result = new OperationResponse(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); dbLocator.Add(entity); } catch (Exception ex) { result.AddException($"Error adding Product Bridge", 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 <DomainModel.SaleOpportunity.SaleOpportunity> GetById(int id) { var result = new OperationResponse <DomainModel.SaleOpportunity.SaleOpportunity>(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { result.Bag = dbLocator.Set <SaleOpportunity>().Where(o => o.Id == id).FirstOrDefault(); } } catch (Exception ex) { result.AddException($"Error getting SaleOpportunity {id}", ex); } return(result); }
public OperationResponse <IEnumerable <SampleBox> > GetAll() { var result = new OperationResponse <IEnumerable <SampleBox> >(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { result.Bag = dbLocator.Set <SampleBox>().AsEnumerable(); } } catch (Exception ex) { result.AddException($"Error getting all Product ", ex); } return(result); }
public OperationResponse <IEnumerable <ColorReference> > GetAll() { var result = new OperationResponse <IEnumerable <DomainModel.Funza.ColorReference> >(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { result.Bag = dbLocator.Set <DomainModel.Funza.ColorReference>().AsEnumerable(); } } catch (Exception ex) { result.AddException($"Error getting all Funza Colors", ex); } return(result); }
public OperationResponse <Product> GetByFunzaId(int id) { var result = new OperationResponse <Product>(); try { var dbLocator = AmbientDbContextLocator.Get <FunzaDBContext>(); { result.Bag = dbLocator.Set <Product>().Where(o => o.FunzaId == id).FirstOrDefault(); } } catch (Exception ex) { result.AddException($"Error getting Funza Product {id}", ex); } return(result); }
public OperationResponse <IEnumerable <Product> > GetAll() { var result = new OperationResponse <IEnumerable <DomainModel.Product> >(); try { var dbLocator = AmbientDbContextLocator.Get <FunzaDBContext>(); { result.Bag = dbLocator.Set <DomainModel.Product>().AsEnumerable(); } } catch (Exception ex) { result.AddException($"Error getting all Funza Products", ex); } return(result); }
public OperationResponse <ColorReference> GetByFunzaId(string id) { var result = new OperationResponse <ColorReference>(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { result.Bag = dbLocator.Set <ColorReference>().Where(o => o.FunzaId == id).FirstOrDefault(); } } catch (Exception ex) { result.AddException($"Error getting Funza Color {id}", ex); } return(result); }
public OperationResponse <IEnumerable <ProductCategory> > GetAll() { var result = new OperationResponse <IEnumerable <ProductCategory> >(); try { var dbLocator = AmbientDbContextLocator.Get <RiverdaleDBContext>(); { result.Bag = dbLocator.Set <ProductCategory>().AsEnumerable(); } } catch (Exception ex) { result.AddError("Error GetAll ProductCategory", ex); } return(result); }