コード例 #1
0
        public async Task <IActionResult> InsertFlightRequestHistory([FromBody] List <FlightRequestHistoryModel> flightRequestHistory)
        {
            var success = await _flightRequestHistoryRepo.InsertFlightRequestHistory(flightRequestHistory);

            return(Ok(success));
        }
コード例 #2
0
        public async Task SendRequest(List <PositionAssign> positionAssigns)
        {
            if (Config.AutomaticFlightRequest != true)
            {
                return;
            }

            foreach (var positionAssign in positionAssigns)
            {
                if (positionAssign == null)
                {
                    Logger.Warning(
                        "Position assign is null, aborting send request to f2w");

                    continue;
                }

                if (positionAssign.Accept != "Accepted")
                {
                    Logger.Info("Not accepted position should not be sent to f2w, aborting send request to f2w successfully",
                                new { positionAssign });

                    continue;
                }

                var position = await _positionRepo.GetPositionFromMPLID(positionAssign.MPLID);

                if (position == null)
                {
                    Logger.Warning("Could not find position with mplid, aborting send request to f2w", new { positionAssign });

                    continue;
                }

                if (!string.IsNullOrEmpty(position.JobTitle) && position.JobTitle.ToLower().Contains("trainee"))
                {
                    Logger.Info("Trainee should not be sent to f2w, aborting send request to f2w successfully",
                                new { positionAssign });

                    continue;
                }

                var staff = _staffRepo.GetByStaffId(positionAssign.StaffID);

                if (staff == null)
                {
                    Logger.Warning("Could not find staff with staffId, aborting send request to f2w",
                                   new { positionAssign, position });

                    continue;
                }

                if (staff.PositionType == "Local")
                {
                    Logger.Info("Should not send local position to f2w, aborting send request to f2w successfully",
                                new { positionAssign, position, staff });

                    continue;
                }

                DateTime?dateOfBirth = null;
                DateTime d2;
                bool     success = DateTime.TryParse(staff.DateOfBirth, out d2);
                if (success)
                {
                    dateOfBirth = d2;
                }

                if (positionAssign.StartDate == null || positionAssign.EndDate == null)
                {
                    Logger.Warning("Could not parse position assign start or en date, aborting send request to f2w",
                                   new { positionAssign, staff, position });

                    continue;
                }

                string direction    = "Arriving";
                string typeOfFlight = "Start of season";

                bool alreadySent = await AlreadySent(positionAssign.Id, direction, position.Destination,
                                                     positionAssign.StartDate.Value, positionAssign.EndDate.Value, typeOfFlight);

                if (alreadySent)
                {
                    Logger.Info("Request is already sent, aborting send request to f2w successfully", new { positionAssign, staff, position });

                    continue;
                }

                SendModel send = new SendModel
                {
                    Id               = staff.StaffID,
                    FirstName        = staff.FirstName,
                    LastName         = staff.LastName,
                    LastName2        = staff.LastName2,
                    DateOfBirth      = dateOfBirth,
                    SourceMarket     = staff.SourceMarket,
                    PositionStart    = positionAssign.StartDate.Value,
                    Destination      = position.Destination,
                    Gender           = staff.Title,
                    Phone            = staff.PhoneHome,
                    JobTitle         = position.JobTitle,
                    Direction        = direction,
                    IataCode         = position.IataCode,
                    PositionAssignId = positionAssign.Id,
                    TypeOfFlight     = typeOfFlight,
                    Season           = position.Season
                };

                var flightRequestHistory = new FlightRequestHistoryModel
                {
                    Direction        = direction,
                    PositionAssignId = positionAssign.Id,
                    Destination      = position.Destination,
                    StartDate        = positionAssign.StartDate.Value,
                    EndDate          = positionAssign.EndDate.Value,
                    MPLPositionType  = staff.PositionType,
                    TypeOfFlight     = typeOfFlight
                };

                var flightRequestHistoryResult =
                    await _flightRequestHistoryRepo.InsertFlightRequestHistory(
                        new List <FlightRequestHistoryModel> {
                    flightRequestHistory
                });

                if (flightRequestHistoryResult == false)
                {
                    Logger.Warning("Something went wrong when trying to insert new flight request history",
                                   new { flightRequestHistory, send });

                    continue;
                }

                Logger.Info("Position assign was accepted, sending request to F2W", new { send });

                var sendRes = await SendBasic(send);

                if (sendRes != null && sendRes.Ok)
                {
                    Logger.Info("Position assign has been sent to F2W", new { send, sendRes });
                }
                else
                {
                    Logger.Warning("Could not send position assign to F2W", new { send, sendRes });
                }
            }
        }