コード例 #1
0
        /// <inheritdoc cref="IRecordBaseService{TBusinessModel,TBusinessModelId}.UpdateAsync(TBusinessModelId, TBusinessModel)"/>
        public virtual async Task <TBusinessModel> UpdateAsync(TBusinessModelId id, TBusinessModel model)
        {
            await Task.Run(() => ValidationHelperMethods <TBusinessModel, TValidator> .ValidateObject(model, Validator));

            var soughtForObject = await Repository.UpdateAsync(id, model);

            if (soughtForObject is null)
            {
                throw new NotFoundException($"{typeof(TBusinessModel).Name} object is not found.", null);
            }
            return(soughtForObject);
        }
コード例 #2
0
        /// <inheritdoc cref="IRecordBaseService{TBusinessModel,TBusinessModelId}.PatchRecordAsync(TBusinessModelId, string, TBusinessModel)"/>
        public virtual async Task <TBusinessModel> PatchRecordAsync(TBusinessModelId id, string property, TBusinessModel model)
        {
            await Task.Run(() => {
                ValidationHelperMethods <TBusinessModel, TValidator> .CheckPropertyForPatching(PatchFieldValidator, property);
                ValidationHelperMethods <TBusinessModel, TValidator> .ValidatePropertyForPatching(model, Validator, property);
            });

            var soughtForObject = await Repository.PatchRecordAsync(id, property, model);

            if (soughtForObject is null)
            {
                throw new NotFoundException($"{typeof(TBusinessModel).Name} object is not found.", null);
            }

            return(soughtForObject);
        }
コード例 #3
0
        /// <inheritdoc cref="IFlightsService.AddReturnAsync(long, Flight)"/>
        public async Task <int> AddReturnAsync(long directFlightId, Flight source)
        {
            ValidationHelperMethods <Flight, IValidator <Flight> > .ValidateObject(source, Validator, FlightValidator.ReturnFlightRules);

            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                int operationResult = 1;
                using (var conn = _conn.GetConnection())
                {
                    conn.Open();
                    if (source.IsNativeReturnFlight.Equals(true))
                    {
                        operationResult = await _returnFlightsRepository.UnsetNativeAsync(directFlightId, conn);

                        if (!operationResult.Equals(0))
                        {
                            source.Priority = 1;
                        }
                        else
                        {
                            throw new InternalServerException("Failed to unset native of return flights during the operation of binding flights.");
                        }
                    }
                    operationResult = await _returnFlightsRepository.RecalculatePriorityAsync(directFlightId, source.Priority, conn);

                    if (!operationResult.Equals(0))
                    {
                        operationResult = await _returnFlightsRepository.AddAsync(directFlightId, source, conn);
                    }
                    else
                    {
                        throw new InternalServerException("Failed to recalculate priorities of return flights during the operation of binding flights.");
                    }
                }
                if (!operationResult.Equals(0))
                {
                    transactionScope.Complete();
                    return(1);
                }
                else
                {
                    throw new InternalServerException("Failed to bind return flight to defined direct flight.");
                }
            }
        }
コード例 #4
0
        /// <inheritdoc cref="IRecordBaseService{TBusinessModel,TBusinessModelId}.AddAsync(TBusinessModel)"/>
        public virtual async Task <TBusinessModel> AddAsync(TBusinessModel model)
        {
            await Task.Run(() => ValidationHelperMethods <TBusinessModel, TValidator> .ValidateObject(model, Validator));

            return(await Repository.AddAsync(model));
        }