Esempio n. 1
0
        /// <summary>
        /// The save contract hotel.
        /// </summary>
        /// <param name="contractStaticViewModel">
        /// The contract static view model.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task <BaseResult <ContractHotel> > SaveContractHotel(ContractStaticViewModel contractStaticViewModel, string loggedUser)
        {
            var result = new BaseResult <ContractHotel>();

            var contractHotelViewModel = new ContractHotelViewModel
            {
                HotelDetailsViewModel =
                    contractStaticViewModel
                    .HotelDetailsViewModel,
                ContractId = contractStaticViewModel.ContractId
            };

            var mappedModel = DbMapperMasterdata.AutomapperContractHotel(contractHotelViewModel.HotelDetailsViewModel, loggedUser);

            mappedModel.ContractId = contractStaticViewModel.ContractId;
            var u = this.iHotel.GetEntity(mappedModel.HotelId).Result.Result;

            mappedModel.NameItemId             = u.NameItemId;
            mappedModel.ShortDescriptionItemId = u.ShortDescriptionItemId;

            var insertResult = await this.iContractHotel.InsertEntity(mappedModel).ConfigureAwait(false);

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

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// SaveContractHotel
        /// </summary>
        /// <param name="contractStaticViewModel"/>
        /// <param name="loggedUser"></param>
        /// <returns>Task<BaseResult<ContractHotel>></returns>
        private async Task <BaseResult <ContractHotel> > SaveContractHotel(ContractStaticViewModel contractStaticViewModel, string loggedUser)
        {
            var result = new BaseResult <ContractHotel>()
            {
                Result = new ContractHotel()
            };
            var hotel = this.iHotel.GetEntity(contractStaticViewModel.HotelDetailsViewModel.HotelId).Result.Result;

            if (contractStaticViewModel.HotelDetailsViewModel.ObjectState == ObjectState.Added)
            {
                var model       = new ContractHotel();
                var mappedModel = DbMapperMasterdata.AutomapperContractHotel(contractStaticViewModel, model, hotel, loggedUser, contractStaticViewModel.HotelDetailsViewModel.ObjectState);

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

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

                var insertResult = await this.iContractHotel.InsertEntity(mappedModel).ConfigureAwait(false);

                if (insertResult.IsError && insertResult.ExceptionMessage != null)
                {
                    result.IsError          = insertResult.IsError;
                    result.ExceptionMessage = insertResult.ExceptionMessage;
                }
                else if (insertResult == null)
                {
                    result = null;
                    return(result);
                }
                result.Result.Id = (int)insertResult.Result;
            }
            if (contractStaticViewModel.HotelDetailsViewModel.ObjectState == ObjectState.Modified)
            {
                var model1 = await this.iContractHotel.GetEntity(contractStaticViewModel.ContractId).ConfigureAwait(false);

                var model = await iContractHotel.GetListByPredicate(p => p.HotelId == contractStaticViewModel.HotelDetailsViewModel.HotelId && p.ContractId == contractStaticViewModel.ContractId).ConfigureAwait(false);

                var mappedModel  = DbMapperMasterdata.AutomapperContractHotel(contractStaticViewModel, model.Result[0], hotel, loggedUser, contractStaticViewModel.HotelDetailsViewModel.ObjectState);
                var updateResult = await this.iContractHotel.UpdateEntityByDapper(mappedModel).ConfigureAwait(false);

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

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

                if (updateResult.IsError && updateResult.ExceptionMessage != null)
                {
                    result.IsError          = updateResult.IsError;
                    result.ExceptionMessage = updateResult.ExceptionMessage;
                }
                else if (updateResult == null)
                {
                    result = null;
                    return(result);
                }
                if (updateResult.Result == true)
                {
                    result.Result.ContractId = contractStaticViewModel.ContractId;
                }
            }
            return(result);
        }