/// <summary>
 /// This will throw an exception if the cud type doesn't fit the entity style
 /// </summary>
 /// <param name="cudType">either create, update or delete</param>
 public void CheckCanDoOperation(CrudTypes cudType)
 {
     if (EntityStyle == EntityStyles.HasNoKey || (EntityStyle == EntityStyles.ReadOnly && cudType != CrudTypes.Delete))
     {
         throw new InvalidOperationException($"The class {EntityType.Name} of style {EntityStyle} cannot be used in {cudType}.");
     }
 }
예제 #2
0
        /// <summary>
        /// This checks if any name was given in the command, or the perDtoConfig specifies a name
        /// </summary>
        /// <param name="nameGivenInCommand"></param>
        /// <param name="createOrUpdate"></param>
        /// <returns></returns>
        public DecodeName GetSpecifiedName(string nameGivenInCommand, CrudTypes createOrUpdate)
        {
            var result = new DecodeName(nameGivenInCommand);

            if (result.NameType != DecodedNameTypes.NoNameGiven)
            {
                return(result);
            }

            switch (createOrUpdate)
            {
            case CrudTypes.Create:
                return(new DecodeName(_perDtoConfig?.CreateMethod));

            case CrudTypes.Update:
                return(new DecodeName(_perDtoConfig?.UpdateMethod));

            default:
                throw new ArgumentException("You should only use Create or Update here", nameof(createOrUpdate));
            }
        }