public IHttpActionResult Post(PostFlightRootObject _model, string user, string pass) { if (!ApiSecurity.Login(user, pass)) { return(Unauthorized()); } try { using (SunExpressEntities context = new SunExpressEntities()) { var pFList = _model.PostFlightData.PostFlight; foreach (var item in pFList) { var postFlight = new Orm.PostFlight { AircraftRegistrationNo = item.AircraftRegistrationNo, Airline = item.Airline, ArrivalTime = item.ArrivalTime, DepartureTime = item.DepartureTime, DestinationAirport = item.DestinationAirport, FlightDate = DateToOLEFormat(item.FlightDate), FlightNum = item.FlightNum, OriginatingAirport = item.OriginatingAirport, PassengerCount = Convert.ToInt32(item.PassengerCount), }; context.PostFlight.Add(postFlight); context.SaveChanges(); int pFID = postFlight.PostFlightID; if (item.Crews.CrewId.Count > 0) { foreach (var crew in item.Crews.CrewId) { var postFlightCrew = new PostFlightCrew(); postFlightCrew.CrewID = crew; postFlightCrew.PostFlightID = pFID; context.PostFlightCrew.Add(postFlightCrew); } } context.SaveChanges(); } } return(Ok("Saved Successfully")); //return Json("SavedSuccesfully"); } catch (Exception ex) { return(BadRequest($" {ex.Message}, Error: Not Saved!")); } }
public IHttpActionResult Post(CrewDataRootObject _model, string user, string pass) { if (!ApiSecurity.Login(user, pass)) { return(Unauthorized()); } try { using (SunExpressEntities context = new SunExpressEntities()) { var crewDataList = _model.CrewData.Crew; if (crewDataList.Count > 0) { foreach (var flightCrew in crewDataList) { bool savedBefore = context.Crew.Any(x => x.CrewID.Equals(flightCrew.CrewId)); if (!savedBefore) { Orm.Crew newCrew = new Orm.Crew(); newCrew.CrewID = flightCrew.CrewId; newCrew.Airline = flightCrew.Airline; newCrew.Airport = flightCrew.Airport; newCrew.FirstName = flightCrew.FirstName; newCrew.LastName = flightCrew.LastName; newCrew.Title = flightCrew.Title; newCrew.StartDate = DateToOLEFormat(flightCrew.StartDate); newCrew.EndDate = DateToOLEFormat(flightCrew.EndDate); context.Crew.Add(newCrew); context.SaveChanges(); } } } return(Ok("Saved Succesfully")); } } catch (Exception) { return(BadRequest("Not Saved")); } }
public IHttpActionResult Post(FlightScheduleRootObject _model, string user, string pass) { if (!ApiSecurity.Login(user, pass)) { return(Unauthorized()); } try { using (SunExpressEntities context = new SunExpressEntities()) { var fSData = _model.FlightScheduleData.FlightSchedule; foreach (var item in fSData) { var flightSchedule = new Orm.FlightSchedule { FlightNum = item.FlightNum, Airline = item.Airline, OriginatingAirport = item.OriginatingAirport, DestinationAirport = item.DestinationAirport, TourOperator = Convert.ToBoolean(item.TourOperator), DepartureTime = TimeSpan.Parse(item.DepartureTime), ArrivalTime = TimeSpan.Parse(item.ArrivalTime), EffectiveEndDate = DateToOLEFormat(item.EffectiveEndDate), EffectiveStartDate = DateToOLEFormat(item.EffectiveStartDate), SectorLength = TimeSpan.Parse(item.SectorLength), }; context.FlightSchedule.Add(flightSchedule); context.SaveChanges(); int flightSchId = flightSchedule.FlightScheduleID; //Get ID for futher table inserts ///DayOfWeek Extraction Dictionary <string, Day> dayList = new Dictionary <string, Day>(); AddToList(item, dayList); foreach (var day in dayList) { if (day.Value != null) { var flightDayTableDetails = new FlightScheduleDayOfWeek(); flightDayTableDetails.FlightScheduleID = flightSchId; flightDayTableDetails.WeekDay = day.Key.ToString(); flightDayTableDetails.IsSchedule = Convert.ToBoolean(day.Value.IsScheduled); flightDayTableDetails.Currency = day.Value.Currency; flightDayTableDetails.IncentiveTarget = Convert.ToInt16(day.Value.IncentiveTarget); flightDayTableDetails.SpendPerHead = Convert.ToInt16(day.Value.SpendPerHead); context.FlightScheduleDayOfWeek.Add(flightDayTableDetails); } } context.SaveChanges(); } } return(Ok("Saved Successfully")); } catch (Exception ex) { return(BadRequest("Error! Not Added!")); } }