/// <summary>
        /// Obtiene los datos de la propuesta actual.
        /// </summary>
        /// <param name="devicePayment"></param>
        /// <param name="isCreated"></param>
        /// <param name="idUsuario"></param>
        /// <returns></returns>
        public ProposalData GetProposalData(string devicePayment, bool isCreated, int idUsuario)
        {
            var planesDefList       = GetCurrentDefinitivePlans();
            var mobileList          = GetConfirmedEquiposPymes();
            var subsidy             = GetSubsidy();
            var payback             = GetPayback(devicePayment);
            var clientModel         = GetCurrentClient();
            var client              = _mapper.Map <SuggestorClient>(clientModel);
            var suggestorList       = GetCurrentPlans();
            var devicePaymentDouble = Convert.ToDouble(devicePayment);
            var subsidioDouble      = Convert.ToDouble(subsidy);
            var paybackDouble       = Convert.ToDouble(payback);
            var planesDef           = _mapper.Map <List <OfertPlan> >(planesDefList);
            var mobileDevicesList   = _mapper.Map <List <DevicePymes> >(mobileList);

            ProposalData proposalData = new ProposalData()
            {
                Client            = client,
                SuggestorList     = suggestorList,
                PlanesDefList     = planesDef,
                DevicePayment     = devicePaymentDouble,
                Payback           = paybackDouble,
                Subsidio          = subsidioDouble,
                MobileDevicesList = mobileDevicesList,
                Finalizada        = isCreated,
                IdUsuario         = idUsuario,
                Activa            = true
            };

            return(proposalData);
        }
Exemple #2
0
        private List <Proposal> GetProposalData()
        {
            string filePath            = @$ "{Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName}/App_Data/Proposals.csv";
            var    proposalsListString = ProposalData.GetProposalDataFromFile(filePath);

            return(ProposalData.GetAllProposals(proposalsListString));
        }
        private TransactionProposalDTO GetTransactionProposal(ProposalData proposal)
        {
            ProposalDTO propuestaDTO = new ProposalDTO()
            {
                Id            = proposal.Id,
                Documento     = proposal.Client.Documento,
                Payback       = proposal.Payback,
                DevicePayment = proposal.DevicePayment,
                Subsidio      = proposal.Subsidio,
                CreatedDate   = DateTime.Now,
                Estado        = "Pendiente",
                IdUsuario     = proposal.IdUsuario,
                Activa        = proposal.Activa
            };


            if (proposal.Finalizada)
            {
                propuestaDTO.Estado = "Finalizada";
            }

            var lineasDTO = new List <ProposalLineDTO>();

            for (var i = 0; i < proposal.SuggestorList.Count; i++)
            {
                lineasDTO.Add(new ProposalLineDTO()
                {
                    NumeroLinea = proposal.SuggestorList[i].Movil.ToString(),
                    Plan        = proposal.PlanesDefList[i].Plan,
                    IdPropuesta = 0
                });
            }

            var equiposDTO = new List <ProposalDeviceDTO>();

            foreach (DevicePymes equipo in proposal.MobileDevicesList)
            {
                equiposDTO.Add(new ProposalDeviceDTO()
                {
                    IdPropuesta   = 0,
                    CODIGO_EQUIPO = equipo.CodigoEquipo
                });
            }

            var transactionProposalDto = new TransactionProposalDTO()
            {
                Proposal      = propuestaDTO,
                Lines         = lineasDTO,
                MobileDevices = equiposDTO
            };

            return(transactionProposalDto);
        }
        /// <summary>
        /// Metodo para actualiar toda la propuesta con sus planes y equipos
        /// </summary>
        public async Task <bool> UpdateTotalProposal(ProposalData proposal)
        {
            try
            {
                await _client.UpdateTotalProposalAsync(proposal);

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> UpdateTotalProposal([FromBody] ProposalData proposal)
        {
            try
            {
                var transactionProposal = GetTransactionProposal(proposal);

                await _ProposalLogic.UpdateTotalProposal(transactionProposal);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public async Task <ActionResult <Proposal> > AddProposal([FromBody] ProposalData proposal)
        {
            try
            {
                var transactionProposalDto = GetTransactionProposal(proposal);

                var proposalId = await _ProposalLogic.InsertProposal(transactionProposalDto);

                var proposalOffertLines = new List <ProposalLine>();

                foreach (var line in proposal.PlanesDefList)
                {
                    proposalOffertLines.Add(new ProposalLine()
                    {
                        Numero = "",
                        Plan   = line
                    });
                }

                var proposalRequest = new Proposal()
                {
                    Id            = proposalId,
                    RutCliente    = proposal.Client.Documento,
                    ClientName    = proposal.Client.Titular,
                    Lineas        = proposalOffertLines,
                    Equipos       = proposal.MobileDevicesList,
                    DevicePayment = proposal.DevicePayment,
                    Payback       = proposal.Payback,
                    Subsidio      = proposal.Subsidio,
                    Estado        = transactionProposalDto.Proposal.Estado,
                    CreatedDate   = transactionProposalDto.Proposal.CreatedDate,
                    IdUsuario     = proposal.IdUsuario.ToString(),
                    Activa        = true
                };

                return(proposalRequest);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public async Task <Proposal> AddProposal(ProposalData proposal)
 {
     try
     {
         Proposal proposalResult  = null;
         Proposal currentProposal = _CurrentProposal;
         if (proposal != null)
         {
             if (_CurrentProposal != null)
             {
                 await SaveProposal(proposal.DevicePayment.ToString(), proposal.Finalizada, proposal.IdUsuario);
             }
             else
             {
                 proposalResult = await _client.AddProposalAsync(proposal);
             }
         }
         return(proposalResult);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }