Example #1
0
        public static CancellationPolicyClauses AutomapperCancellationPolicyClause(CancellationPolicyClausesViewModel viewModel, CancellationPolicyClauses model)
        {
            var modelMapped = AutoMapper.Mapper.Map <CancellationPolicyClauses>(viewModel);

            ResolveRemainingParamters(modelMapped, model);
            return(modelMapped);
        }
Example #2
0
        /// <summary>
        /// Get Cancellation Policies by hotel id
        /// </summary>
        /// <param name="hotelId"></param>
        /// <returns>list of cancellation policy</returns>
        public BaseResult <List <CancellationPolicyViewModel> > GetCancellationPolicies(int hotelId)
        {
            BaseResult <List <CancellationPolicy> > policies = this.iCancellationPolicyConnectionLibrary.GetListByPredicate(p => p.HotelId == hotelId && p.IsDeleted == false).Result;
            var cancellationPolicyTypes = this.iCancellationPolicyTypeConnectionLibrary.GetListByPredicate(p => p.IsActive == true && p.IsDeleted == false);
            var cancellationCharges     = this.iCancellationChargesConnectionLibrary.GetListByPredicate(p => p.IsActive == true && p.IsDeleted == false);
            BaseResult <List <CancellationPolicyViewModel> > modelList = new BaseResult <List <CancellationPolicyViewModel> >();

            modelList.Result = new List <CancellationPolicyViewModel>();
            Func <int?, string> GetCancellationChargesName = (id) =>
                                                             cancellationCharges.Result.Result.Where(p => p.Id == id).FirstOrDefault().Name;
            Func <int, string> GetCancellationPolicyTypeName = (id) =>
                                                               cancellationPolicyTypes.Result.Result.Where(p => p.Id == id).FirstOrDefault().Name;

            foreach (var item in policies.Result)
            {
                CancellationPolicyViewModel model = new CancellationPolicyViewModel()
                {
                    CancellationPolicyId = item.Id,
                    HotelId = item.HotelId,
                    CancellationPolicyTypeId    = item.CancellationPolicyTypeId,
                    CancellationPolicyTypeName  = GetCancellationPolicyTypeName(item.CancellationPolicyTypeId),
                    IsNoShowCharges             = item.IsNoShowCharges,
                    NoShowCancellationChargesId = item.NoShowCancellationChargesId,
                    CancellationChargesName     = (item.NoShowCancellationChargesId != null)? GetCancellationChargesName(item.NoShowCancellationChargesId):String.Empty,
                    Name     = item.Name,
                    IsActive = item.IsActive
                };
                BaseResult <List <CancellationPolicyClauses> > policyClauses = this.iCancellationPolicyClausesConnectionLibrary.GetListByPredicate(p => p.CancellationPolicyId == item.Id && p.IsDeleted == false).Result;
                model.CancellationPolicyClausesViewModelList = new List <CancellationPolicyClausesViewModel>();
                foreach (var clause in policyClauses.Result)
                {
                    CancellationPolicyClausesViewModel clauseModel = new CancellationPolicyClausesViewModel()
                    {
                        CancellationChargesId       = clause.CancellationChargesId,
                        CancellationPolicyClausesId = clause.Id,
                        CancellationPolicyId        = clause.CancellationPolicyId,
                        DaysBeforeArrival           = clause.DaysBeforeArrival,
                        PercentageCharge            = clause.PercentageCharge
                    };
                    model.CancellationPolicyClausesViewModelList.Add(clauseModel);
                }
                modelList.Result.Add(model);
            }
            return(modelList);
        }
Example #3
0
        /// <summary>
        /// Create CancellationPolicyClauses
        /// </summary>
        /// <param name="clauseViewModel"></param>
        /// <returns>returns the cancellation policy clauses id</returns>
        public async Task <BaseResult <CancellationPolicy> > CreateCancellationPolicyClauses(CancellationPolicyClausesViewModel clauseViewModel)
        {
            var result = new BaseResult <CancellationPolicy> {
                Result = new CancellationPolicy()
            };
            CancellationPolicyClauses clause = new CancellationPolicyClauses()
            {
                DaysBeforeArrival     = clauseViewModel.DaysBeforeArrival,
                PercentageCharge      = clauseViewModel.PercentageCharge,
                CancellationChargesId = clauseViewModel.CancellationChargesId,
                CancellationPolicyId  = (int)clauseViewModel.CancellationPolicyId
            };
            ////this.ValidatePolicyClause(cancellationPolicyClauses);
            var insertResult = await this.iCancellationPolicyClausesConnectionLibrary.InsertEntity(clause).ConfigureAwait(false);

            if (insertResult.IsError || insertResult.ExceptionMessage != null)
            {
                result.IsError          = true;
                result.ExceptionMessage = insertResult.ExceptionMessage;
                return(result);
            }
            result.Result.Id = (int)insertResult.Result;
            return(result);
        }
Example #4
0
        /// <summary>
        /// Updates CancellationClauses
        /// </summary>
        /// <param name="cancellationPolicyViewModel"></param>
        /// <returns></returns>
        private async Task <BaseResult <CancellationPolicy> > UpdateCancellationClauses(CancellationPolicyClausesViewModel clauseViewModel)
        {
            BaseResult <CancellationPolicy> result = new BaseResult <CancellationPolicy>();

            result.Result = new CancellationPolicy();
            var updateResult = new BaseResult <bool>();


            var clauseDb = this.iCancellationPolicyClausesConnectionLibrary.GetListByPredicate(p => p.Id == clauseViewModel.CancellationPolicyClausesId).Result.Result.FirstOrDefault();

            if (clauseViewModel.ObjectState == ObjectState.Modified)
            {
                var updatedModel = DbMapperMasterdata.AutomapperCancellationPolicyClause(clauseViewModel, clauseDb);
                ////this.ValidatePolicyClause(updatedModel);
                updateResult = await iCancellationPolicyClausesConnectionLibrary.UpdateEntityByDapper(updatedModel).ConfigureAwait(false);
            }
            if (clauseViewModel.ObjectState == ObjectState.Added)
            {
                return(await CreateCancellationPolicyClauses(clauseViewModel).ConfigureAwait(false));
            }

            if (updateResult.IsError || updateResult.ExceptionMessage != null)
            {
                result.IsError          = true;
                result.ExceptionMessage = updateResult.ExceptionMessage;
                return(result);
            }

            if (updateResult.Result == true)
            {
                result.Result.Id = clauseViewModel.CancellationPolicyId;
            }
            return(result);
        }