コード例 #1
0
        /// <summary>
        /// The create contract.
        /// </summary>
        /// <param name="contractStaticViewModel">
        ///     The contract view model.
        /// </param>
        /// <param name="loggedUser">Logged in user name</param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <BaseResult <ContractViewModel> > CreateContract(
            ContractStaticViewModel contractStaticViewModel,
            string loggedUser)
        {
            var result = new BaseResult <ContractViewModel>();

            var contract = new Contract();

            contract = DbMapperMasterdata.AutomapperContract(contractStaticViewModel, contract, loggedUser);

            contract.StatusID = 1;

            var insertResult = await this.iContract.InsertEntity(contract).ConfigureAwait(false);

            contractStaticViewModel.ContractId = (int)insertResult.Result;

            var insertResultHotelFields = await this.InsertTemplateFieldsToContractFieldsHotel(contractStaticViewModel)
                                          .ConfigureAwait(false);

            var insertResultRoomFields = await this.InsertTemplateFieldsToContractFieldsRoom(contractStaticViewModel)
                                         .ConfigureAwait(false);

            await this.SaveContractHotel(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            await this.SaveContractContact(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            //await this.SaveContractHotelTax(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            if (insertResult.IsError && insertResult.ExceptionMessage != null)
            {
                result.IsError          = insertResult.IsError;
                result.ExceptionMessage = insertResult.ExceptionMessage;
            }

            result.Result.Id = (int)insertResult.Result;
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// CreateContract
        /// </summary>
        /// <param name="contractStaticViewModel"></param>
        /// <param name="loggedUser"></param>
        /// <returns>Task<BaseResult<ContractStaticViewModel>></returns>
        public async Task <BaseResult <ContractStaticViewModel> > CreateContract(ContractStaticViewModel contractStaticViewModel, string loggedUser)
        {
            var result = new BaseResult <ContractStaticViewModel>()
            {
                Result = new ContractStaticViewModel()
            };
            var insertResult = new BaseResult <long>();
            var updateResult = new BaseResult <bool>();
            var contract     = this.iContract.GetEntity(id: contractStaticViewModel.ContractId).Result.Result;

            result.Result.Id = contractStaticViewModel.ContractId;
            contract         = DbMapperMasterdata.AutomapperContract(contractStaticViewModel, contract, loggedUser, contractStaticViewModel.ObjectState);

            if (contractStaticViewModel.ObjectState == ObjectState.Added)
            {
                contract.StatusID = 1;  /// draft
                insertResult      = await this.iContract.InsertEntity(contract).ConfigureAwait(false);

                contractStaticViewModel.ContractId = (int)insertResult.Result;
                result.Result.Id = (int)insertResult.Result;
            }
            if (contractStaticViewModel.ObjectState == ObjectState.Modified)
            {
                var contractModified = AutoMapper.Mapper.Map <Contract>(contractStaticViewModel);
                updateResult = await iContract.UpdateEntityByDapper(contractModified).ConfigureAwait(false);

                result.Result.Id = contractStaticViewModel.ContractId;
            }

            var insertResultHotelFields = await
                                          this.InsertTemplateFieldsToContractFieldsHotel(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            var insertResultRoomFields = await
                                         this.InsertTemplateFieldsToContractFieldsRoom(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            var insertContractClausesLibraryRelation = await
                                                       this.InsertTemplateClausesToContractClausesLibrary(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            await this.SaveContractHotel(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            await this.SaveContractContact(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            await this.SaveContractHotelTax(contractStaticViewModel, loggedUser).ConfigureAwait(false);

            await this.SaveContractPaymentMethod(contractStaticViewModel).ConfigureAwait(false);

            if (contractStaticViewModel.ObjectState == ObjectState.Added && insertResult.IsError && insertResult.ExceptionMessage != null)
            {
                result.IsError          = insertResult.IsError;
                result.ExceptionMessage = insertResult.ExceptionMessage;
                result.Result.Id        = (int)insertResult.Result;
                return(result);
            }
            if (contractStaticViewModel.ObjectState == ObjectState.Modified && updateResult.IsError && updateResult.ExceptionMessage != null)
            {
                result.IsError          = updateResult.IsError;
                result.ExceptionMessage = updateResult.ExceptionMessage;
                result.Result.Id        = contractStaticViewModel.ContractId;
                return(result);
            }

            return(result);
        }