Ejemplo n.º 1
0
        public void AddAdvertisement(Advertisement advertisement)
        {
            const string logPrefix = "AdvertisementService: AddAdvertisement() ";

            try
            {
                _logger.Debug(logPrefix + advertisement);

                if (!advertisement.IsValid)
                {
                    var errorMessages = string.Join("\n", advertisement.GetValidationErrors());
                    throw new ValidationException("Validation errors: " + errorMessages);
                }

                var dataAccessFactory       = new DataAccessFactory(_configuration.DataProvider, _logger);
                var advertisementRepository = dataAccessFactory.GetAdvertisementRepository();
                advertisementRepository.Create(advertisement);
            }
            catch (ValidationException ex)
            {
                _logger.Debug(logPrefix + ex);
                // I don't mind returning the StackTrace and errors for a validation error
                throw;
            }
            catch (Exception ex)
            {
                _logger.Error(logPrefix + ex);
                throw new Exception("Exception thrown. Check server logs");
            }
        }
Ejemplo n.º 2
0
        public Task SaveAsync()
        {
            ValidationErrors = _advertisement.GetValidationErrors();

            if (!ValidationErrors.Any())
            {
                return(_service.AddAdvertisementAsync(_advertisement));
            }

            return(null);
        }