public ShopperCommandHandler( IShopperRepository eventRepository, IMediatorHandler mediatorHandler, INotificationHandler <DomainNotification> notifications) : base(mediatorHandler, notifications) { this.repository = eventRepository; }
public AuthorizationCommandHandler(IUnitOfWork uow, IDomainNotification notifications, JwtTokenConfig jwtTokenConfig, IUserRepository userRepository, IPasswordHasherService passwordHasherService, IShopperRepository shopperRepository) : base(uow, notifications) { _jwtTokenConfig = jwtTokenConfig; _userRepository = userRepository; _passwordHasherService = passwordHasherService; _shopperRepository = shopperRepository; }
public ShopperCommandHandler(IUnitOfWork uow, IDomainNotification notifications, IUserRepository userRepository, IPasswordHasherService passwordHasherService, IShopperRepository shopperRepository, IShopperAddressRepository shopperAddressRepository) : base(uow, notifications) { _userRepository = userRepository; _passwordHasherService = passwordHasherService; _shopperRepository = shopperRepository; _shopperAddressRepository = shopperAddressRepository; }
public Response <Model.Shopper> Create(Model.Shopper entity) { IShopperRepository shopperRepository = null; IAddressRepository addressRepository = null; Validator <Model.Shopper> validator = ValidationFactory.CreateValidator <Model.Shopper>("Create"); Validator <Model.Address> validatorAddress = ValidationFactory.CreateValidator <Model.Address>("Create"); try { #region Validation if (!validator.Validate(entity).IsValid) { response.Status = ResponseStatus.ErrorValidation; response.ErrorValue = (int)ErrorCode.InvalidData; foreach (var result in validator.Validate(entity)) { if (!response.Validations.ContainsKey(result.Key)) { response.Validations.Add(result.Key, result.Message); } } return(response); } if (!validatorAddress.Validate(entity).IsValid) { response.Status = ResponseStatus.ErrorValidation; response.ErrorValue = (int)ErrorCode.InvalidData; foreach (var result in validatorAddress.Validate(entity)) { if (!response.Validations.ContainsKey(result.Key)) { response.Validations.Add(result.Key, result.Message); } } return(response); } #endregion Validation using (var ctx = new ChickenScratchContext()) { // Set default entity.FromDate = DateTime.UtcNow; entity.LastActivity = DateTime.MinValue; // Create Customer shopperRepository = new ShopperRepository(ctx); shopperRepository.Insert(entity); // Create Adrress addressRepository = new AddressRepository(ctx); addressRepository.Add(entity.Address); shopperRepository.Save(); response.Result = entity; response.Status = ResponseStatus.Success; } return(response); } catch (Exception ex) { throw ex; } }