public LegInstance UpdateLegInstance(int id, LegInstance legInstance) { if (id <= 0) { throw new ArgumentOutOfRangeException(ErrorMessages.INVALID_ID); } if (legInstance == null) { throw new ArgumentNullException(ErrorMessages.ENTITY_CANNOT_BE_NULL); } var legInstanceToUpdate = this.legInstances.GetById(id); if (legInstanceToUpdate != null) { legInstanceToUpdate.DepartureDateTime = legInstance.DepartureDateTime; legInstanceToUpdate.ArrivalDateTime = legInstance.ArrivalDateTime; legInstanceToUpdate.IsDeleted = legInstance.IsDeleted; legInstanceToUpdate.FlightLegId = legInstance.FlightLegId; legInstanceToUpdate.FlightStatusId = legInstance.FlightStatusId; legInstanceToUpdate.AircraftId = legInstance.AircraftId; this.legInstances.SaveChanges(); } return(legInstanceToUpdate); }
public async Task <IActionResult> PutLegInstance(string id, LegInstance legInstance) { if (id != legInstance.Date) { return(BadRequest()); } _context.Entry(legInstance).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LegInstanceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { if (this.Booking == null || (this.Booking != null && this.Booking.LegInstanceId == 0 || this.Booking.TravelClassId == 0)) { this.Response.Redirect(Pages.HOME); } else { LegInstance selectedLegInstance = this.LegInstancesServices.GetLegInstance(this.Booking.LegInstanceId); this.FromAirportLabel.Text = selectedLegInstance.FlightLeg.Route.Origin.Name; this.ToAirportLabel.Text = selectedLegInstance.FlightLeg.Route.Destination.Name; this.SelectedTravelClassLabel.Text = selectedLegInstance.Aircraft.TravelClasses .FirstOrDefault(t => t.Id == this.Booking.TravelClassId) .Type .ToString(); if (this.Booking.Row != 0 && !string.IsNullOrEmpty(this.Booking.SeatNumber)) { this.SelectedRowAndSeatLabel.Text = "Seat: " + this.Booking.Row + this.Booking.SeatNumber; this.SelectedRowHiddenField.Value = this.Booking.Row.ToString(); this.SelectedSeatHiddenField.Value = this.Booking.SeatNumber; } else { this.SelectedRowAndSeatLabel.Text = "Seat: No seat selected!"; } } } }
public int AddLegInstance(LegInstance legInstance) { if (legInstance == null) { throw new ArgumentNullException(ErrorMessages.ENTITY_CANNOT_BE_NULL); } this.legInstances.Add(legInstance); this.legInstances.SaveChanges(); return(legInstance.Id); }
private void SendMailToSubscribedUsers(LegInstance legInstance) { var userEmails = this.GetSubscribedUsersToReceiveEmail(); StringBuilder messageBody = new StringBuilder(); messageBody.Append("Hello, Passenger,"); messageBody.Append("<br/><br/>" + this.GetContent(legInstance)); messageBody.Append("<br/><br/><small>If you don't want to receive emails for new flights, go to your account settings and " + "uncheck <strong>'Receive email when there is a new flight'</strong> option!</small>"); var mailSender = MailSender.Instance; mailSender.SendMail(userEmails[0], "Added a new flight!", messageBody.ToString(), userEmails); }
private string GetContent(LegInstance legInstance) { var flightLeg = this.GetFlightLeg(legInstance.FlightLegId); string origin = this.GetAirport(flightLeg.DepartureAirportId); string destination = this.GetAirport(flightLeg.ArrivalAirportId); string date = legInstance.DepartureDateTime.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture); string time = legInstance.DepartureDateTime.ToString("HH:mm", CultureInfo.InvariantCulture); return(string.Format( @"Added a new flight ""{0}, from {1} to {2}, departure on {3} at {4}""!", flightLeg.Flight.Number, origin, destination, date, time)); }
private void ShowFlightInfo(int flightId, FormView flightDetails, Repeater travelClasses) { this.ContinueBookingBtn.Enabled = true; LegInstance legInstance = this.LegInstancesServices.GetLegInstance(flightId); this.LegInstance = legInstance; flightDetails.DataSource = new List <LegInstance>() { legInstance }; flightDetails.DataBind(); travelClasses.DataSource = legInstance.Aircraft.TravelClasses.ToList(); travelClasses.DataBind(); }
private int AddNotification(LegInstance legInstance) { StringBuilder content = new StringBuilder(); content.Append(this.GetContent(legInstance)); content.Append("<br/><small>If you don't want to receive notifications for new flights, go to your account settings and " + "uncheck <strong>'Receive notification when there is a new flight'</strong> option!</small>"); var addedNewNewsNotification = new Notification() { Content = content.ToString(), DateCreated = DateTime.Now, Type = NotificationType.AddedNewNews }; this.notificationsServices.AddNotification(addedNewNewsNotification); return(addedNewNewsNotification.Id); }
private void AddDaysWithNoFlightToSlider(List <LegInstance> legInstances) { int daysInMonth = DateTime.DaysInMonth(this.DepartureDate.Year, this.DepartureDate.Month); for (int day = 1; day <= daysInMonth; day++) { var flight = legInstances.FirstOrDefault(l => l.DepartureDateTime.Day == day); if (flight == null) { int indexToInsert = day - 1; LegInstance noFlightForThisDay = new LegInstance() { DepartureDateTime = new DateTime(this.DepartureDate.Year, this.DepartureDate.Month, day) }; legInstances.Insert(indexToInsert, noFlightForThisDay); } } }
public async Task <ActionResult <LegInstance> > PostLegInstance(LegInstance legInstance) { _context.LegInstance.Add(legInstance); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (LegInstanceExists(legInstance.Date)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetLegInstance", new { id = legInstance.Date }, legInstance)); }
private void View_OnLegInstancesAddItem(object sender, LegInstancesManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(LegInstancesManagementEventArgs)); } decimal price = this.faresServices.GetFare(e.FareId).Price; var legInstance = new LegInstance() { DepartureDateTime = e.DepartureDateTime, ArrivalDateTime = e.ArrivalDateTime, Price = price, FlightLegId = e.FlightLegId, FlightStatusId = e.FlightStatusId, AircraftId = e.AircraftId }; e.Id = this.legInstancesServices.AddLegInstance(legInstance); }
private void SetSelectedFlightToItinerary( Data.Models.Booking booking, ref decimal totalCost, Literal flightNumberLiteral, Literal dateTimeLiteral, Literal flightPriceLiteral, Literal travelClassPriceLiteral, Literal travelClassLiteral) { LegInstance selectedLegInstance = this.LegInstancesServices.GetLegInstance(booking.LegInstanceId); flightNumberLiteral.Text = "Flight № " + selectedLegInstance.FlightLeg.Flight.Number; dateTimeLiteral.Text = selectedLegInstance.DepartureDateTime.ToString("MMMM dd, yyyy hh:mm", CultureInfo.InvariantCulture); flightPriceLiteral.Text = "€ " + string.Format("{0:0.00}", selectedLegInstance.Price); decimal travelClassPrice = this.TravelClassesServices.GetTravelClass(booking.TravelClassId).Price; travelClassPriceLiteral.Text = "€ " + string.Format("{0:0.00}", travelClassPrice); totalCost += selectedLegInstance.Price + travelClassPrice; travelClassLiteral.Text = this.TravelClassesServices.GetTravelClass(booking.TravelClassId).Type.ToString() + " class"; }