Ejemplo n.º 1
0
        /// <summary>
        /// Updates Cancellation Policy
        /// </summary>
        /// <param name="cancellationPolicyViewModel"></param>
        /// <returns>updated cancellation policy id</returns>
        private async Task <BaseResult <CancellationPolicy> > UpdateCancellationPolicy(CancellationPolicyViewModel cancellationPolicyViewModel)
        {
            var result = new BaseResult <CancellationPolicy>();

            result.Result = new CancellationPolicy();
            if (cancellationPolicyViewModel.ObjectState == ObjectState.Modified)
            {
                var cancellationPolicyDbList = await this.iCancellationPolicyConnectionLibrary.GetListByPredicate(p => p.HotelId == cancellationPolicyViewModel.HotelId && p.IsDeleted == false).ConfigureAwait(false);

                var cancellationPolicyDb = cancellationPolicyDbList.Result.FirstOrDefault(p => p.Id == cancellationPolicyViewModel.CancellationPolicyId);
                if (cancellationPolicyDb != null)
                {
                    var cancellationPolicy =
                        DbMapperMasterdata.AutomapperCancellationPolicy(cancellationPolicyViewModel,
                                                                        cancellationPolicyDb);
                    if (cancellationPolicy.CancellationPolicyTypeId != cancellationPolicyDb.CancellationPolicyTypeId &&
                        cancellationPolicyDb.CancellationPolicyTypeId == 2)
                    {
                        var clausesList = await iCancellationPolicyClausesConnectionLibrary
                                          .GetListByPredicate(p =>
                                                              p.CancellationPolicyId == cancellationPolicyDb.Id && p.IsDeleted == false)
                                          .ConfigureAwait(false);

                        foreach (var item in clausesList.Result)
                        {
                            item.IsDeleted = true;
                        }
                        await iCancellationPolicyClausesConnectionLibrary.UpdateEntityList(clausesList.Result)
                        .ConfigureAwait(false);
                    }
                    var updateResult = await iCancellationPolicyConnectionLibrary.UpdateEntityByDapper(cancellationPolicy).ConfigureAwait(false);

                    if (updateResult.IsError || updateResult.ExceptionMessage != null)
                    {
                        result.IsError          = true;
                        result.ExceptionMessage = updateResult.ExceptionMessage;
                        return(result);
                    }
                    if (updateResult == null)
                    {
                        result = null;
                    }
                    return(result);
                }
                else
                {
                    return(result);
                }
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create Cancellation Policy
        /// </summary>
        /// <param name="cancellationPolicyViewModel"></param>
        /// <returns>returns the Id of the newly created cancellation policy</returns>
        private async Task <BaseResult <CancellationPolicy> > CreateCancellationPolicy(CancellationPolicyViewModel cancellationPolicyViewModel)
        {
            var result = new BaseResult <CancellationPolicy>();

            result.Result = new CancellationPolicy();

            var policy = DbMapperMasterdata.AutomapperCancellationPolicy(cancellationPolicyViewModel);

            var insertResult = await this.iCancellationPolicyConnectionLibrary.InsertEntity(policy).ConfigureAwait(false);

            if (insertResult.IsError || insertResult.ExceptionMessage != null)
            {
                result.IsError          = true;
                result.ExceptionMessage = insertResult.ExceptionMessage;
                return(result);
            }
            if (insertResult == null)
            {
                result = null;
            }
            result.Result.Id = (int)insertResult.Result;
            return(result);
        }