Esempio n. 1
0
        public static async Task <IActionResult> PostProposal(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "proposals")] ProposalDto proposal,
            HttpRequest req, TraceWriter log)
        {
            try
            {
                if (!proposal.IsValid())
                {
                    return(new BadRequestResult());
                }

                var authToken = req.Headers.ContainsKey(AuthTokenHeader) ? req.Headers[AuthTokenHeader][0] : string.Empty;

                var service = new BidMyTripService(log, new WorkBenchService());

                var newProposal = await service.PostProposal(authToken, proposal);

                return(new OkObjectResult(newProposal));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);

                throw;
            }
        }
Esempio n. 2
0
        private static IEnumerable <PassengerViewModel> BuildPassengers(ProposalDto proposalDto)
        {
            var passengers = new List <PassengerViewModel>();

            if (proposalDto.Passenger1 != null)
            {
                passengers.Add(BuildPassenger(proposalDto.Passenger1));
            }

            if (proposalDto.Passenger2 != null)
            {
                passengers.Add(BuildPassenger(proposalDto.Passenger2));
            }

            if (proposalDto.Passenger3 != null)
            {
                passengers.Add(BuildPassenger(proposalDto.Passenger3));
            }

            if (proposalDto.Passenger4 != null)
            {
                passengers.Add(BuildPassenger(proposalDto.Passenger4));
            }

            return(passengers);
        }
Esempio n. 3
0
        public Task <int> Add(ProposalDto proposalDto)
        {
            var entity = ConferenceAdapter.FromProposalDtoToProposal(proposalDto);

            _dbContext.Proposals.Add(entity);
            return(_dbContext.SaveChangesAsync());
        }
        public async Task <Tuple <Proposal, string> > CreateProposal(ProposalDto proposalDto)
        {
            var proposal = _mapper.Map <Proposal>(proposalDto);

            var stageTuple = await GetStage(proposalDto.StageId, proposalDto.Stage);

            if (stageTuple?.Item2 != null)
            {
                return(new Tuple <Proposal, string>(null, stageTuple.Item2));
            }
            else if (stageTuple?.Item1 != null)
            {
                proposal.Stage = stageTuple.Item1;
            }

            var deadlineTuple = await GetDeadline(proposalDto.DeadlineId, proposalDto.Deadline);

            if (deadlineTuple?.Item2 != null)
            {
                return(new Tuple <Proposal, string>(null, deadlineTuple.Item2));
            }
            else if (deadlineTuple?.Item1 != null)
            {
                proposal.Deadline = deadlineTuple.Item1;
            }

            _dbContext.Proposals.Add(proposal);
            await _dbContext.SaveChangesAsync();

            return(new Tuple <Proposal, string>(proposal, null));
        }
 public async Task <IActionResult> AddProposal(ProposalDto proposalDto)
 {
     if (ModelState.IsValid)
     {
         await _proposalRepository.Add(proposalDto);
     }
     return(RedirectToAction("Index", new { conferenceId = proposalDto.ConferenceId }));
 }
Esempio n. 6
0
 public ActionResult AddProposal(ProposalModel model)
 {
     if (ModelState.IsValid)
     {
         ProposalDto modelDto = _mapper.Map <ProposalDto>(model);
         var         data     = new ApiClient().PostData($"api/concept/PostProposal", modelDto);
         return(RedirectToAction("Index", "Home"));
     }
     return(View(model));
 }
 public static Proposal FromProposalDtoToProposal(ProposalDto proposalDto)
 {
     return(new Proposal
     {
         ConferenceId = proposalDto.ConferenceId,
         Speaker = proposalDto.Speaker,
         Title = proposalDto.Title,
         Approved = proposalDto.Approved
     });
 }
Esempio n. 8
0
        internal async Task RecordConfirm(string authToken, ProposalDto proposal)
        {
            InitializeGatewayInstance(authToken);

            var contract = await GetContract();

            var workFlow = await GetWorkFlow();

            var workFlowInfoId = await GetNextWorkflowInfoId(workFlow.Id.ToString());

            var action = BuildConfirmationAction(workFlowInfoId, proposal);

            var result = await _apiGateway.PostWorkflowActionAsync(action,
                                                                   contract.ContractCodeId.ToString());
        }
Esempio n. 9
0
 private static ActionInformation BuildAcceptanceAction(long workFlowInfoId, ProposalDto proposal)
 {
     return(new ActionInformation()
     {
         WorkflowFunctionId = workFlowInfoId,
         WorkflowActionParameters = new List <WorkflowActionParameter>()
         {
             new WorkflowActionParameter()
             {
                 Name = "offerCode",
                 Value = proposal.Offers.First().OfferCode
             }
         }
     });
 }
Esempio n. 10
0
        internal async Task <long> RecordNewProposal(string authToken, ProposalDto proposal)
        {
            InitializeGatewayInstance(authToken);

            var contract = await GetContract();

            var workFlow = await GetWorkFlow();

            var workFlowInfoId = await GetNextWorkflowInfoId(workFlow.Id.ToString());

            var action = BuildNewProposalAction(workFlowInfoId, proposal);

            var result = await _apiGateway.CreateNewContractAsync(action,
                                                                  workFlow.Id.ToString(),
                                                                  contract.ContractCodeId.ToString(),
                                                                  contract.LedgerId.ToString());

            return(workFlowInfoId);
        }
Esempio n. 11
0
        private static bool BuildIsAcceptable(ProposalDto proposalDto, ConfigurationProvider configuration)
        {
            if (proposalDto.Price < configuration.MinimumAcceptablePrice)
            {
                return(false);
            }

            if (configuration.UnnaceptableOrigins.Any(uo => uo == proposalDto.Origin))
            {
                return(false);
            }

            if (configuration.UnnaceptableDestinations.Any(ud => ud == proposalDto.Destiny))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 12
0
 public static ProposalViewModel Map(ProposalDto proposalDto, ConfigurationProvider configuration)
 {
     return(new ProposalViewModel
     {
         ProposalId = proposalDto.ProposalId,
         ArrivalCity = proposalDto.Destiny,
         DepartureCity = proposalDto.Origin,
         DepartureDate = proposalDto.OutboundDate,
         ReturnDate = proposalDto.InboundDate,
         ExpirationDate = proposalDto.TimeToLive,
         Price = proposalDto.Price,
         IsAcceptable = BuildIsAcceptable(proposalDto, configuration),
         IsInteresting = BuildIsInteresting(proposalDto, configuration),
         Passengers = BuildPassengers(proposalDto),
         Offers = proposalDto.Offers.Select(OfferViewModelMapper.Map),
         Status = proposalDto.Status,
         AirlineLogo = configuration.AirlineLogo
     });
 }
Esempio n. 13
0
        internal async Task <ProposalDto> PostProposal(string authToken, ProposalDto proposal)
        {
            proposal.CreationDate = DateTime.UtcNow;
            proposal.Status       = Proposed;

            var fullDb = await CacheService.GetFullDb();

            fullDb.Add(proposal);

            await CacheService.UpdataDb(fullDb);

            if (useWorkBench)
            {
                proposal.WorkFlowInfoId = await _workBenchService.RecordNewProposal(authToken, proposal);
            }

            await CacheService.UpdataDb(fullDb);

            return(proposal);
        }
        public async Task <IActionResult> PostProposals(ProposalDto proposalDto)
        {
            if (proposalDto.Id == 0)
            {
                var proposalTuple = await _proposalService.CreateProposal(proposalDto);

                if (proposalTuple.Item2 != null)
                {
                    return(new JsonResult(new { errors = proposalTuple.Item2 }));
                }
                if (proposalTuple.Item1 == null)
                {
                    return(Forbid());
                }
                return(CreatedAtAction("GetProposals", new { id = proposalTuple.Item1.Id }, _mapper.Map <ProposalInfoDto>(proposalTuple.Item1)));
            }
            else
            {
                return(await PutProposals(proposalDto.Id, proposalDto));
            }
        }
Esempio n. 15
0
 private static ActionInformation BuildNewProposalAction(long workFlowInfoId, ProposalDto proposal)
 {
     return(new ActionInformation()
     {
         WorkflowFunctionId = workFlowInfoId,
         WorkflowActionParameters = new List <WorkflowActionParameter>()
         {
             new WorkflowActionParameter()
             {
                 Name = "departureCity",
                 Value = proposal.Origin
             },
             new WorkflowActionParameter()
             {
                 Name = "arrivalCity",
                 Value = proposal.Destiny
             },
             new WorkflowActionParameter()
             {
                 Name = "departureDate",
                 Value = proposal.OutboundDate.ToString("MM/dd/yyyy")
             },
             new WorkflowActionParameter()
             {
                 Name = "arrivalDate",
                 Value = proposal.InboundDate.HasValue ? string.Empty : proposal.InboundDate.Value.ToString("MM/dd/yyyy")
             },
             new WorkflowActionParameter()
             {
                 Name = "price",
                 Value = proposal.Price.ToString()
             },
             new WorkflowActionParameter()
             {
                 Name = "timeToLive",
                 Value = ((int)Math.Ceiling((proposal.TimeToLive - DateTime.UtcNow).TotalHours)).ToString()
             }
         }
     });
 }
        public async Task <IActionResult> PutProposals(int id, ProposalDto proposalDto)
        {
            if (proposalDto.Id == 0)
            {
                proposalDto.Id = id;
            }
            if (id != proposalDto.Id)
            {
                return(BadRequest());
            }

            var proposalTuple = await _proposalService.UpdateProposal(proposalDto);

            if (proposalTuple.Item2 != null)
            {
                return(new JsonResult(new { errors = proposalTuple.Item2 }));
            }
            if (proposalTuple.Item1 == null)
            {
                return(NotFound());
            }

            return(RedirectToAction("GetProposals", new { id = proposalDto.Id }));
        }
        public async Task <Tuple <Proposal, string> > UpdateProposal(ProposalDto proposalDto)
        {
            var proposal = await _dbContext.Proposals.FirstOrDefaultAsync(_ => _.Id == proposalDto.Id);

            if (proposal != null)
            {
                _mapper.Map <ProposalDto, Proposal>(proposalDto, proposal);

                var stageTuple = await GetStage(proposalDto.StageId, proposalDto.Stage);

                if (stageTuple?.Item2 != null)
                {
                    return(new Tuple <Proposal, string>(null, stageTuple.Item2));
                }
                else if (stageTuple?.Item1 != null)
                {
                    proposal.Stage = stageTuple.Item1;
                }

                var deadlineTuple = await GetDeadline(proposalDto.DeadlineId, proposalDto.Deadline);

                if (deadlineTuple?.Item2 != null)
                {
                    return(new Tuple <Proposal, string>(null, deadlineTuple.Item2));
                }
                else if (deadlineTuple?.Item1 != null)
                {
                    proposal.Deadline = deadlineTuple.Item1;
                }

                _dbContext.Entry(proposal).State = EntityState.Modified;

                await _dbContext.SaveChangesAsync();
            }
            return(new Tuple <Proposal, string>(proposal, null));
        }
Esempio n. 18
0
 private static ActionInformation BuildConfirmationAction(long workFlowInfoId, ProposalDto proposal)
 {
     return(new ActionInformation()
     {
         WorkflowFunctionId = workFlowInfoId,
         WorkflowActionParameters = new List <WorkflowActionParameter>()
         {
         }
     });
 }
Esempio n. 19
0
 private bool IsEqualOrBetter(ProposalDto proposal, OfferDto offer)
 {
     return(offer.OutboundDate == proposal.OutboundDate &&
            offer.InboundDate == proposal.InboundDate &&
            offer.Price <= proposal.Price);
 }
Esempio n. 20
0
 public IHttpActionResult PostProposal([FromBody] ProposalDto proposal)
 {
     return(Json(_proposalService.AddProposal(proposal)));
 }
Esempio n. 21
0
 private static bool BuildIsInteresting(ProposalDto proposalDto, ConfigurationProvider configuration)
 {
     return(proposalDto.Price >= configuration.MinimumInterestingPrice);
 }
Esempio n. 22
0
        public int AddProposal(ProposalDto proposal)
        {
            var data = _mapper.Map <Proposal>(proposal);

            return(_proposalRepository.InsertOrUpdate(data));
        }
 public int InsertProposal(ProposalDto ProposalDto)
 {
     throw new System.NotImplementedException();
 }