Beispiel #1
0
        /// <summary>
        /// Executes the command which handles a command for importing a food group from a given data provider.
        /// </summary>
        /// <param name="command">Command which imports a food group from a given data provider.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(FoodGroupImportFromDataProviderCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var dataProvider    = SystemDataRepository.Get <IDataProvider>(command.DataProviderIdentifier);
            var translationInfo = SystemDataRepository.Get <ITranslationInfo>(command.TranslationInfoIdentifier);

            IFoodGroup parentFoodGroup = null;
            var        parentKey       = command.ParentKey;

            if (string.IsNullOrWhiteSpace(parentKey) == false)
            {
                parentFoodGroup = SystemDataRepository.FoodGroupGetByForeignKey(dataProvider, parentKey);
            }

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(dataProvider), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.DataProviderIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.IsNotNull(translationInfo), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.TranslationInfoIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.HasValue(command.Key), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "Key")))
            .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.Key) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "Key")))
            .IsSatisfiedBy(() => CommonValidations.HasValue(command.Name), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "Name")))
            .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.Name) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "Name")))
            .IsSatisfiedBy(() => string.IsNullOrWhiteSpace(parentKey) || (string.IsNullOrWhiteSpace(parentKey) == false && CommonValidations.IsNotNull(parentFoodGroup)), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, parentKey, "ParentKey")))
            .Evaluate();

            var foodGroup = SystemDataRepository.FoodGroupGetByForeignKey(dataProvider, command.Key);

            if (foodGroup == null)
            {
                var insertedfoodGroup = SystemDataRepository.Insert <IFoodGroup>(new FoodGroup {
                    IsActive = true, Parent = parentFoodGroup
                });

                var foreignKey = new ForeignKey(dataProvider, insertedfoodGroup.Identifier.HasValue ? insertedfoodGroup.Identifier.Value : default(Guid), insertedfoodGroup.GetType(), command.Key);
                foreignKey.Identifier = _logicExecutor.ForeignKeyAdd(foreignKey);
                insertedfoodGroup.ForeignKeyAdd(foreignKey);

                ImportTranslation(insertedfoodGroup, translationInfo, command.Name, _logicExecutor);

                return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(insertedfoodGroup));
            }

            foodGroup.IsActive = command.IsActive;
            foodGroup.Parent   = parentFoodGroup;

            var updatedFoodGroup = SystemDataRepository.Update(foodGroup);

            ImportTranslation(updatedFoodGroup, translationInfo, command.Name, _logicExecutor);

            return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(updatedFoodGroup));
        }
Beispiel #2
0
        /// <summary>
        /// Executes the command which deletes a foreign key.
        /// </summary>
        /// <param name="command">Command which deletes a foreign key.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(ForeignKeyDeleteCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var foreignKey = SystemDataRepository.Get <IForeignKey>(command.ForeignKeyIdentifier);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(foreignKey), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.ForeignKeyIdentifier)))
            .Evaluate();

            SystemDataRepository.Delete(foreignKey);

            return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(foreignKey));
        }
Beispiel #3
0
        //return true if Db was updated
        public bool SaveAllFileLinks()
        {
            bool dbUpdated            = false;
            int  counter              = 0;
            SystemDataRepository repo = new SystemDataRepository();

            FootballDataParser parser = new FootballDataParser();
            var config = repo.GetResourceConfig(parser.GetDomain);

            Console.WriteLine("Start FootballDataParser.");
            foreach (var link in parser.GetAllLinks("1.csv"))
            {
                Console.WriteLine("link [{0}]: {1}", counter++, link);
                dbUpdated |= repo.AddResourceProcessingStatus(link, config);
            }
            Console.WriteLine("Stop FootballDataParser.");
            return(dbUpdated);
        }
        /// <summary>
        /// Executes the command which adds a translation.
        /// </summary>
        /// <param name="command">Command for adding a translation.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(TranslationAddCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var translationInfo = SystemDataRepository.Get <ITranslationInfo>(command.TranslationInfoIdentifier);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(translationInfo), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.TranslationInfoIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.HasValue(command.TranslationValue), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "TranslationValue")))
            .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.TranslationValue) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "TranslationValue")))
            .Evaluate();

            var translation = SystemDataRepository.Insert <ITranslation>(new Translation(command.TranslationOfIdentifier, translationInfo, command.TranslationValue));

            return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(translation));
        }
Beispiel #5
0
        /// <summary>
        /// Executes the command which modifies a foreign key.
        /// </summary>
        /// <param name="command">Command which modifies a foreign key.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(ForeignKeyModifyCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var foreignKey = SystemDataRepository.Get <IForeignKey>(command.ForeignKeyIdentifier);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(foreignKey), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.ForeignKeyIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.HasValue(command.ForeignKeyValue), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "ForeignKeyValue")))
            .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.ForeignKeyValue) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "ForeignKeyValue")))
            .Evaluate();

            foreignKey.ForeignKeyValue = command.ForeignKeyValue;

            var updatedForeignKey = SystemDataRepository.Update(foreignKey);

            return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(updatedForeignKey));
        }
        /// <summary>
        /// Executes the command which adds a foreign key.
        /// </summary>
        /// <param name="command">Command which adds a foreign key.</param>
        /// <returns>Service receipt.</returns>
        public virtual ServiceReceiptResponse Execute(ForeignKeyAddCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var dataProvider = SystemDataRepository.Get <IDataProvider>(command.DataProviderIdentifier);
            var foreignKeyForDomainObject = GetForeignKeyForDomainObject(command.ForeignKeyForIdentifier);

            Specification.IsSatisfiedBy(() => CommonValidations.IsNotNull(dataProvider), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.DataProviderIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.IsNotNull(foreignKeyForDomainObject), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.IdentifierUnknownToSystem, command.ForeignKeyForIdentifier)))
            .IsSatisfiedBy(() => CommonValidations.HasValue(command.ForeignKeyValue), new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueMustBeGivenForProperty, "ForeignKeyValue")))
            .IsSatisfiedBy(() => CommonValidations.ContainsIllegalChar(command.ForeignKeyValue) == false, new IntranetBusinessException(Resource.GetExceptionMessage(ExceptionMessage.ValueForPropertyContainsIllegalChars, "ForeignKeyValue")))
            .Evaluate();

            // ReSharper disable PossibleInvalidOperationException
            var foreignKey = SystemDataRepository.Insert <IForeignKey>(new ForeignKey(dataProvider, foreignKeyForDomainObject.Identifier.Value, foreignKeyForDomainObject.GetType(), command.ForeignKeyValue));

            // ReSharper restore PossibleInvalidOperationException

            return(ObjectMapper.Map <IIdentifiable, ServiceReceiptResponse>(foreignKey));
        }