Esempio n. 1
0
 /// should not need this had it her to stop the error: "There is no argument given that corresponds to the required formal parameter"
 /// if it is asking for that you need to ass  : base (dbContext, logger, UnitOfWork) to the def
 //public AppRepository() { }
 public AppRepository(ApplicationDbContext dbContext, ILoggerManager logger, IAppUnitOfWork unitOfWork)
 {
     _Context       = dbContext;
     _Table         = dbContext.Set <TEntity>();
     _Logger        = logger;
     _AppUnitOfWork = unitOfWork;
 }
 public void HandleCreate(CreateProductCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         if (company == null)
         {
             throw new DomainException("The assigned company not found");
         }
         User creator = uow.Users.FirstOrDefault(u => u.Id == command.CreatedByUserId);
         if (creator == null)
         {
             throw new DomainException("Can not find creator");
         }
         var product = new Product
         {
             Company    = company,
             Name       = command.Name,
             Comment    = command.Comment,
             Quantity   = command.Quantity,
             Sku        = command.Sku,
             Properties = new List <ProductProperty>(command.Properties),
             IsActive   = command.IsActive,
             CreatedAt  = DateTime.Now,
             CreatedBy  = creator
         };
         uow.ProductRepository.Add(product);
         uow.SaveChanges();
         command.ProductId = product.Id;
     }
 }
Esempio n. 3
0
        /// <summary>
        ///     Initiate controller with injectors.
        /// </summary>
        /// <param name="unitOfWork"></param>
        /// <param name="mapper"></param>
        /// <param name="baseTimeService"></param>
        /// <param name="relationalDbService"></param>
        /// <param name="encryptionService"></param>
        /// <param name="profileService"></param>
        /// <param name="systemBaseTimeService"></param>
        /// <param name="externalAuthenticationService"></param>
        /// <param name="sendMailService"></param>
        /// <param name="emailCacheService"></param>
        /// <param name="jwtConfigurationOptions"></param>
        /// <param name="applicationSettings"></param>
        /// <param name="logger"></param>
        /// <param name="vgyService"></param>
        /// <param name="profileCacheService"></param>
        /// <param name="captchaService"></param>
        /// <param name="realTimeService"></param>
        /// <param name="userDomain"></param>
        public UserController(
            IAppUnitOfWork unitOfWork,
            IMapper mapper,
            IBaseTimeService baseTimeService,
            IBaseRelationalDbService relationalDbService,
            IBaseEncryptionService encryptionService,
            IAppProfileService profileService,
            IBaseTimeService systemBaseTimeService,
            IExternalAuthenticationService externalAuthenticationService,
            ISendMailService sendMailService,
            IEmailCacheService emailCacheService,
            IOptions <AppJwtModel> jwtConfigurationOptions,
            IOptions <ApplicationSetting> applicationSettings,
            ILogger <UserController> logger,
            IVgyService vgyService,
            IBaseKeyValueCacheService <int, User> profileCacheService,
            ICaptchaService captchaService,

            IUserDomain userDomain) : base(
                unitOfWork, mapper, baseTimeService,
                relationalDbService, profileService)
        {
            _logger            = logger;
            _profileService    = profileService;
            _sendMailService   = sendMailService;
            _emailCacheService = emailCacheService;
            _captchaService    = captchaService;

            _userDomain = userDomain;
        }
Esempio n. 4
0
 public TicketService(
     IAppUnitOfWork uow,
     ITicketFactory ticketFactory)
 {
     _uow           = uow;
     _ticketFactory = ticketFactory;
 }
 /// <summary>
 /// Handle delete command.
 /// </summary>
 public void HandleDelete(DeleteCompanyCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         uow.CompanyRepository.Remove(company);
         uow.SaveChanges();
     }
 }
Esempio n. 6
0
 public UserAppService(IDemoRepository repository,
                       IAppUnitOfWork unitOfWork,
                       UserDomainService userDomainService,
                       ILockProvider lockProvider)
     : base(repository, unitOfWork)
 {
     _userDomainService = userDomainService;
     _lockProvider      = lockProvider;
 }
Esempio n. 7
0
 /// <summary>
 ///     Initialize base controller with injectors.
 /// </summary>
 /// <param name="unitOfWork"></param>
 /// <param name="mapper"></param>
 /// <param name="baseTimeService"></param>
 /// <param name="relationalDbService"></param>
 /// <param name="profileService"></param>
 public ApiBaseController(IAppUnitOfWork unitOfWork, IMapper mapper, IBaseTimeService baseTimeService,
                          IBaseRelationalDbService relationalDbService, IAppProfileService profileService)
 {
     UnitOfWork          = unitOfWork;
     Mapper              = mapper;
     BaseTimeService     = baseTimeService;
     RelationalDbService = relationalDbService;
     ProfileService      = profileService;
 }
Esempio n. 8
0
 /// <summary>
 ///     Initiate requirement handler with injectors.
 /// </summary>
 /// <param name="unitOfWork"></param>
 /// <param name="profileService"></param>
 /// <param name="httpContextAccessor"></param>
 /// <param name="profileCacheService"></param>
 public SolidAccountRequirementHandler(
     IAppUnitOfWork unitOfWork,
     IAppProfileService profileService, IHttpContextAccessor httpContextAccessor,
     IBaseKeyValueCacheService <int, User> profileCacheService)
 {
     _unitOfWork          = unitOfWork;
     _profileService      = profileService;
     _httpContextAccessor = httpContextAccessor;
     _profileCacheService = profileCacheService;
 }
Esempio n. 9
0
 public IndexModel(
     UserManager <AppUser> userManager,
     SignInManager <AppUser> signInManager,
     IEmailSender emailSender,
     IAppUnitOfWork uow)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _uow           = uow;
 }
Esempio n. 10
0
        public void OneTimeSetUp()
        {
            var dbContext = new AppDbContext(new DbContextOptionsBuilder <AppDbContext>()
                                             .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                             .Options);

            uow = new AppUnitOfWork(dbContext);
            disposables.Add(uow);

            Mapper.Initialize(cfg => cfg.AddProfile <AutoMapperProfile>());
        }
Esempio n. 11
0
        public void OneTimeSetUp()
        {
            var dbContext = new AppDbContext(new DbContextOptionsBuilder <AppDbContext>()
                                             .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                             .Options);

            uow = new AppUnitOfWork(dbContext);
            disposables.Add(uow);

            var config = new MapperConfiguration(cfg => cfg.AddProfile <AutoMapperProfile>());

            mapper = config.CreateMapper();
        }
 /// <summary>
 /// Handle update command.
 /// </summary>
 public void HandleUpdate(UpdateCompanyCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         if (uow.Companies.Any(c => c.Name == command.Name.Trim() && c.Id != command.CompanyId))
         {
             throw new DomainException("The company with the same name already exists.");
         }
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         company.Name = command.Name;
         uow.SaveChanges();
     }
 }
Esempio n. 13
0
 public RegisterModel(
     UserManager <AppUser> userManager,
     SignInManager <AppUser> signInManager,
     ILogger <RegisterModel> logger,
     IEmailSender emailSender,
     IAppUnitOfWork uow)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _logger        = logger;
     _emailSender   = emailSender;
     _uow           = uow;
 }
Esempio n. 14
0
        private void CreateAdmin(IAppUnitOfWork uow)
        {
            var command = new CreateUserCommand
            {
                FirstName = "Admin",
                LastName  = "Admin",
                Email     = "*****@*****.**",
                Password  = "******",
                Role      = UserRole.Admin
            };

            pipelineService.HandleCommand(command);

            AdminId = command.UserId;
        }
 public void HandleDelete(DeleteProductCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Product product = uow.ProductRepository.Get(command.ProductId, Product.IncludeAll);
         if (product == null)
         {
             throw new NotFoundException("Deleted product not found");
         }
         // Delete properties before
         uow.ProductPropertyRepository.RemoveRange(product.Properties);
         uow.ProductRepository.Remove(product);
         uow.SaveChanges();
     }
 }
 public void HandleUpdate(UpdateProductCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         Product product = uow.ProductRepository.Get(command.ProductId, Product.IncludeAll);
         Company company = uow.CompanyRepository.Get(command.CompanyId);
         if (company == null)
         {
             throw new DomainException("The assigned company not found");
         }
         User updater = uow.Users.FirstOrDefault(u => u.Id == command.UpdatedByUserId);
         if (updater == null)
         {
             throw new DomainException("Can not find updater");
         }
         // Delete properties
         foreach (ProductProperty removedProperty in product.Properties.Where(oldP => !command.Properties.Any(newP => newP.Id == oldP.Id)).ToList())
         {
             product.Properties.Remove(removedProperty);
             uow.ProductPropertyRepository.Remove(removedProperty);
         }
         // Update existing properties
         foreach (ProductProperty existProperty in product.Properties)
         {
             ProductProperty updatedProperty = command.Properties.SingleOrDefault(pp => pp.Id == existProperty.Id);
             existProperty.Name  = updatedProperty.Name;
             existProperty.Value = updatedProperty.Value;
         }
         // Add new properties
         foreach (ProductProperty property in command.Properties.Where(pp => pp.Id == 0))
         {
             product.Properties.Add(property);
         }
         product.Company   = company;
         product.Name      = command.Name;
         product.Comment   = command.Comment;
         product.Quantity  = command.Quantity;
         product.Sku       = command.Sku;
         product.IsActive  = command.IsActive;
         product.UpdatedAt = DateTime.Now;
         uow.SaveChanges();
     }
 }
Esempio n. 17
0
 public UserDomain(IBaseEncryptionService encryptionService,
                   IAppUnitOfWork unitOfWork,
                   IExternalAuthenticationService externalAuthenticationService,
                   IBaseKeyValueCacheService <int, User> profileCacheService,
                   IBaseTimeService baseTimeService,
                   IBaseRelationalDbService relationalDbService,
                   IAppProfileService profileService,
                   IVgyService vgyService,
                   IOptions <ApplicationSetting> applicationSettingOptions,
                   IOptions <AppJwtModel> appJwt)
 {
     _encryptionService             = encryptionService;
     _unitOfWork                    = unitOfWork;
     _externalAuthenticationService = externalAuthenticationService;
     _baseTimeService               = baseTimeService;
     _applicationSettings           = applicationSettingOptions.Value;
     _relationalDbService           = relationalDbService;
     _appJwt = appJwt.Value;
     _profileCacheService = profileCacheService;
     _vgyService          = vgyService;
     _profileService      = profileService;
 }
 /// <summary>
 /// Handle create command.
 /// </summary>
 public void HandleCreate(CreateCompanyCommand command, IAppUnitOfWorkFactory uowFactory)
 {
     using (IAppUnitOfWork uow = uowFactory.Create())
     {
         if (uow.Companies.Any(c => c.Name == command.Name.Trim()))
         {
             throw new DomainException("The company with the same name already exists.");
         }
         User creator = uow.Users.FirstOrDefault(u => u.Id == command.CreatedByUserId);
         if (creator == null)
         {
             throw new DomainException("Cannot find creator.");
         }
         var company = new Company
         {
             Name      = command.Name,
             CreatedBy = creator
         };
         uow.CompanyRepository.Add(company);
         uow.SaveChanges();
         command.CompanyId = company.Id;
     }
 }