コード例 #1
0
        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="owner">
        /// The owner.
        /// </param>
        /// <param name="input">
        /// The input.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <int> Add(Guid owner, ParameterizationIn input)
        {
            if (owner == null || owner == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (!this.cacheProvider.Currencies.Select(x => x.Code).Contains(input.Currency))
            {
                throw new Exception("The currency " + input.Currency + " doesnt look valid.");
            }

            if ((input.FromAccount == null || input.FromAccount == Guid.Empty) && (input.Children != null && input.Children.Count >= 1))
            {
                throw new Exception("If FromAccount is null, no Children are allowed.");
            }

            // TODO More validations !!!

            return(await this.parameterizationsRepository.Add(owner, input));
        }
コード例 #2
0
        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="owner">
        /// The owner.
        /// </param>
        /// <param name="input">
        /// The input.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <int> Add(Guid owner, ParameterizationIn input)
        {
            var code = Guid.NewGuid();

            var parameterization = new ParameterizationEntity
            {
                Code   = code,
                Owner  = owner,
                Active = true,
                Parent = null,

                Description = input.Description,
                Cadence     = input.Cadence,
                Currency    = input.Currency,
                Day         = input.Day,
                Amount      = input.Amount,
                FromAccount = input.FromAccount,
                ToCard      = input.ToCard,
                SpecificDay = input.SpecificDay,
                ToAccount   = input.ToAccount
            };


            if (input.Children != null && input.Children.Count >= 1)
            {
                var totalAmount = decimal.Zero;

                foreach (var children in input.Children)
                {
                    var newChildren = new ParameterizationEntity
                    {
                        Code   = Guid.NewGuid(),
                        Owner  = owner,
                        Parent = code,
                        Active = true,

                        Cadence     = input.Cadence,
                        Currency    = input.Currency,
                        Day         = input.Day,
                        FromAccount = input.FromAccount,
                        SpecificDay = input.SpecificDay,

                        ToAccount   = children.ToAccount,
                        ToCard      = children.ToCard,
                        Amount      = children.Amount,
                        Description = children.Description,
                    };

                    this.context.Parameterizations.Add(newChildren);
                    totalAmount += children.Amount;
                }

                parameterization.Amount = totalAmount;
            }

            this.context.Parameterizations.Add(parameterization);

            var myint = await this.context.SaveChangesAsync();

            return(myint);
        }
コード例 #3
0
 public async Task <HttpResponseMessage> List(Guid owner, ParameterizationIn input)
 {
     return(await this.ProcessActionAsync(owner, input, this.parameterizationsService.Add));
 }