async Task ConcertsTresholdReached() { if (IsBusy) { return; } IsBusy = true; try { pageNumber++; if (pageNumber > pagesCount) { ConcertTreshold = -1; return; } var concerts = await concertService.GetAllConcerts(pageNumber); Concerts.AddRange(concerts); FilteredConcerts.AddRange(concerts); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Date,LocationId")] Concerts concerts) { if (id != concerts.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(concerts); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConcertsExists(concerts.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["LocationId"] = new SelectList(_context.Locations, "Id", "Name", concerts.LocationId); return(View(concerts)); }
public Concerts Post([FromBody] Concerts concert) { Concerts returnConcert = null; using (SqlConnection conn = new SqlConnection(_dbOptions.Value.ConnectionString)) { try { conn.Open(); string insertSql = "INSERT INTO Concerts(ArtistId, VenueId, CalendarDate, Price)" + "VALUES(@ArtistId, @VenueId, @CalendarDate, @Price);"; conn.Execute(insertSql, concert); } catch (SqlException exc) { Console.WriteLine(exc.Message); } string selectSql = "SELECT * FROM Concerts WHERE ArtistId = @ArtistId AND VenueId = @VenueId AND CalendarDate = @CalendarDate;"; Concerts indexConcert = conn.Query <Concerts>(selectSql, concert).FirstOrDefault(); returnConcert = indexConcert; if (indexConcert != null) { _client.IndexDocument(indexConcert); string mainIndexSql = "SELECT * FROM ConcertIndexView WHERE ConcertId = @concertId;"; IndexObject mainIndex = conn.Query <IndexObject>(mainIndexSql, new { indexConcert.ConcertId }).FirstOrDefault(); _client.IndexDocument(mainIndex); } } return(returnConcert); }
async Task ExecuteLoadConcertsCommand() { if (IsBusy) { return; } IsBusy = true; try { var concertsCount = await concertService.ConcertsCount(); pagesCount = (int)Math.Ceiling((double)concertsCount / AppConstants.PAGE_SIZE); ConcertTreshold = 4; Concerts.Clear(); var concerts = await concertService.GetAllConcerts(); Concerts.AddRange(concerts); FilteredConcerts.AddRange(concerts); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public string Purchase(int id, [FromBody] Customers customer) { Concerts concert = null; using (SqlConnection conn = new SqlConnection(_dbOptions.Value.ConnectionString)) { try { conn.Open(); string concertSelect = "SELECT * FROM Concerts WHERE ConcertId = @concertId;"; concert = conn.Query <Concerts>(concertSelect, new { concertId = id }).FirstOrDefault <Concerts>(); string customerSelect = "SELECT * FROM Customers WHERE CustomerId = @customerId;"; customer = conn.Query <Customers>(customerSelect, new { customerId = customer.CustomerId }).FirstOrDefault <Customers>(); } catch (SqlException exc) { Console.WriteLine(exc.Message); } } if (concert.Price > customer.Currency) { return("poor"); } else { using (SqlConnection conn = new SqlConnection(_dbOptions.Value.ConnectionString)) { try { conn.Open(); conn.Execute("SP_Purchase", new { concertId = concert.ConcertId, customerId = customer.CustomerId }, commandType: CommandType.StoredProcedure); } catch (SqlException exc) { Console.WriteLine(exc.Message); } string selectSql = "SELECT * FROM Concerts WHERE ArtistId = @ArtistId AND VenueId = @VenueId AND CalendarDate = @CalendarDate;"; Concerts indexConcert = conn.Query <Concerts>(selectSql, concert).FirstOrDefault(); string selectIndexSql = "SELECT * FROM ConcertIndexView WHERE ConcertId = @ConcertId;"; IndexObject indexObject = conn.Query <IndexObject>(selectIndexSql, new { indexConcert.ConcertId }).FirstOrDefault(); string selectCustomerSql = "SELECT * FROM Customers WHERE CustomerId = @CustomerId;"; Customers indexCustomer = conn.Query <Customers>(selectCustomerSql, new { customer.CustomerId }).FirstOrDefault(); if (indexConcert != null) { _client.IndexDocument <Concerts>(indexConcert); _client.IndexDocument <Customers>(indexCustomer); _client.IndexDocument <IndexObject>(indexObject); } } return("done"); } }
public void CreateOrUpdate(ConcertDTO concertDTO) { Concerts concert = concertRepository.Get(concertDTO.Id); concert = mapper.Map <ConcertDTO, Concerts>(concertDTO); concertRepository.CreateOrUpdate(concert); concertRepository.SaveChanges(); }
public ConcertDTO Delete(ConcertDTO concertDTO) { Concerts concertToRemove = concertRepository.Get(concertDTO.Id); concertRepository.Delete(concertToRemove); concertRepository.SaveChanges(); return(concertDTO); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Date,LocationId")] Concerts concerts) { if (ModelState.IsValid) { _context.Add(concerts); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LocationId"] = new SelectList(_context.Locations, "Id", "Name", concerts.LocationId); return(View(concerts)); }
private void CreateConcert() { if (validation.ValidateFields(new Control[] { concertPlaceNameComboBox, concertArtistNameComboBox, concertDateInput, concertBaseTicketPriceInput, concertVipTicketPriceInput, concertRemainingCapacityInput }) && validation.ValidateCapacity(concertRemainingCapacityInput.Text, context.Places .Where(u => u.PlaceName.ToString().Equals(concertPlaceNameComboBox.SelectedValue.ToString())) .Select(u => u.Capacity) .FirstOrDefault())) { placeCapacity = context.Places .Where(u => u.PlaceName.ToString().Equals(concertPlaceNameComboBox.SelectedValue.ToString())) .Select(u => u.Capacity) .FirstOrDefault(); var newConcert = new Concerts() { PlaceID = context.Places .Where(u => u.PlaceName.ToString().Equals(concertPlaceNameComboBox.SelectedValue.ToString())) .Select(u => u.PlaceID) .FirstOrDefault(), ArtistID = context.Artists .Where(u => u.ArtistName.ToString().Equals(concertArtistNameComboBox.SelectedValue.ToString())) .Select(u => u.ArtistID) .FirstOrDefault(), EventDate = concertDateInput.SelectedDate.Value, BaseTicketPrice = Convert.ToDecimal(concertBaseTicketPriceInput.Text), VIPTicketPrice = Convert.ToDecimal(concertVipTicketPriceInput.Text), RemainingCapacity = Convert.ToInt32(concertRemainingCapacityInput.Text) }; context.Concerts.Add(newConcert); context.SaveChanges(); this.NavigationService.Navigate(new Uri("Windows/ConcertsList.xaml", UriKind.Relative)); } else { emptyArtistText.Visibility = Visibility.Visible; emptyPlaceText.Visibility = Visibility.Visible; emptyDateText.Visibility = Visibility.Visible; emptyBaseTicketText.Visibility = Visibility.Visible; emptyVipTextText.Visibility = Visibility.Visible; emptyCapacityText.Text = "This field cannot be empty"; emptyCapacityText.Visibility = Visibility.Visible; } if (!String.IsNullOrWhiteSpace(concertRemainingCapacityInput.Text)) { if (!validation.ValidateCapacity(concertRemainingCapacityInput.Text, placeCapacity)) { emptyCapacityText.Text = "Cannot enter value higher than max capacity!"; emptyCapacityText.Visibility = Visibility.Visible; } } }
public Concerts Cancel(int id) { Concerts returnConcert = null; IndexObject indexObject = null; using (SqlConnection conn = new SqlConnection(_dbOptions.Value.ConnectionString)) { try { conn.Open(); conn.Execute("SP_CancelConcert", new { concertId = id }, commandType: CommandType.StoredProcedure); string selectSql = "SELECT * FROM Concerts WHERE ConcertId = @ConcertId;"; returnConcert = conn.Query <Concerts>(selectSql, new { ConcertId = id }).FirstOrDefault(); string selectIndexSql = "SELECT * FROM ConcertIndexView WHERE ConcertId = @ConcertId;"; indexObject = conn.Query <IndexObject>(selectIndexSql, new { concertId = id }).FirstOrDefault(); } catch (SqlException exc) { Console.WriteLine(exc.Message); } } if (returnConcert != null) { _client.IndexDocument <Concerts>(returnConcert); _client.IndexDocument <IndexObject>(indexObject); _client.Indices.Delete("customers"); using (SqlConnection conn = new SqlConnection(_dbOptions.Value.ConnectionString)) { try { conn.Open(); var customers = conn.Query <Customers>("SELECT * FROM Customers WHERE IsActive = 1;"); _client.Bulk(request => request .Index("customers") .IndexMany <Customers>(customers)); } catch (SqlException exc) { Console.WriteLine(exc.Message); } } } return(returnConcert); }
public void GroupBy_Concert_Limit_Person_Id() { PersonIdentifierGroupComparer comparer = new PersonIdentifierGroupComparer(); var concertGroups = Concerts.ConcertGroup(comparer); foreach (IGrouping <int, Concert> concertGroup in concertGroups) { Debug.WriteLine($"Concerts of person id {(comparer.IsInLimit(concertGroup.Key) ? "under 3" : "3 and over")} : "); foreach (Concert concert in concertGroup) { Debug.WriteLine($"Number of concerts: {concert.ConcertCount}, in the year of {concert.Year} by singer {concert.PersonId}."); } } }
public Concerts Get(int id) { Concerts concert = null; using (SqlConnection conn = new SqlConnection(_dbOptions.Value.ConnectionString)) { try { conn.Open(); string sql = "SELECT * FROM Concerts WHERE ConcertId = @concertId;"; concert = conn.Query(sql, new { concertId = id }).FirstOrDefault(); } catch (SqlException exc) { Console.WriteLine(exc.Message); } } return(concert); }
private async void SearchButton_Click(object sender, RoutedEventArgs e) { if (tbSearch.Text == string.Empty) { return; } if (CurrentView == typeof(Band)) { Bands = await Communication.GetFilteredBands($"filter=contains(Name,'{tbSearch.Text}')"); } else if (CurrentView == typeof(Venue)) { Venues = await Communication.GetFilteredVenues($"filter=contains(Name,'{tbSearch.Text}')"); //TODO } else if (CurrentView == typeof(Concert)) { Concerts = Concerts.Where(c => c.Bands.Any(b => b.Name.Contains(tbSearch.Text))).ToList(); } SetListSource(); }
public List <Concerts> Search(Concerts concert) { List <Concerts> allResult = new List <Concerts>(); var doc = XDocument.Load(@"D:\Програмування\C#\LabXml\LabXml\Concerts.xml"); var result = from obj in doc.Descendants("Concert") where ( (obj.Attribute("Artist").Value.Equals(concert.Artist) || concert.Artist.Equals(String.Empty)) && (obj.Attribute("Date").Value.Equals(concert.Date) || concert.Date.Equals(String.Empty)) && (isPriceRange(obj.Attribute("PriceRange").Value, concert.PriceRange) || concert.PriceRange.Equals(String.Empty)) && (obj.Attribute("Location").Value.Contains(concert.Location) || concert.Location.Equals(String.Empty)) && (obj.Attribute("Style").Value.Equals(concert.Style) || concert.Style.Equals(String.Empty)) && (obj.Attribute("ArtistBand").Value.Equals(concert.ArtistBand) || concert.ArtistBand.Equals(String.Empty)) ) select new { artist = (string)obj.Attribute("Artist"), date = (string)obj.Attribute("Date"), priceRange = (string)obj.Attribute("PriceRange"), location = (string)obj.Attribute("Location"), style = (string)obj.Attribute("Style"), artistBand = (string)obj.Attribute("ArtistBand") }; foreach (var n in result) { Concerts myConcert = new Concerts(); myConcert.Artist = n.artist; myConcert.Date = n.date; myConcert.PriceRange = n.priceRange; myConcert.Location = n.location; myConcert.Style = n.style; myConcert.ArtistBand = n.artistBand; allResult.Add(myConcert); } return(allResult); }
private void buttonDeleteConcerts_Click(object sender, EventArgs e) { try { Concerts con = (Concerts)dataGridViewConcerts.CurrentRow.DataBoundItem; var b = (from c in ctx.Tickets where (c.Ticket_Concert_ID == con.Concert_ID) select c).Any(); if (b) { MessageBox.Show("Видалення неможливе\n До концерту прив'язані елементи"); } else { concertsBindingSource.RemoveCurrent(); ctx.SaveChanges(); } } catch (Exception) { MessageBox.Show("Помилка видалення концерту"); throw; } }
//Get list of concerts of the users favourite artists public (List <string> Url, List <string> Name) GetConcerts(List <string> Artists) { string url1 = string.Format("https://app.ticketmaster.com/discovery/v2/events.json?countryCode=IE&city=Dublin&classificationName=music&apikey=ZgYSxFmoUdl5nqXPzxFJ7OWpqG0ZLX2W&size=200"); Concerts concerts = TicketmasterService <Concerts>(url1); List <string> Url = new List <string>(); List <string> Name = new List <string>(); foreach (var musician in Artists) { if (musician == null) { continue; } foreach (var item in concerts.Listings.Events) { //For every event returned by the ticketmaster API check if it matches the users artists bool isStringContainedInList = item.Name.Contains(musician); if (isStringContainedInList == false || musician == "And") { continue; } //If the strings match add to list of concerts Name.Add(item.Name); Url.Add(item.Link); } } List <string> distinctname = Name.Distinct().ToList(); List <string> distincturl = Url.Distinct().ToList(); return(distincturl, distinctname); //Return the list of strings }
private void DeleteContentByTitle() { ShowAllContent(); bool continueToRun = true; while (continueToRun) { Console.Clear(); Console.WriteLine("Enter the number of the option you'd like to select:\n" + "1. Find Bowling Events by name\n" + "2. Find Concert Events by name\n" + "3. Find Golf Events by name\n" + "4. Find Amusement Park Events by name\n" + "5. Exit"); string input = Console.ReadLine(); switch (input) { case "1": Console.ReadKey(); Console.WriteLine("Enter the car's name for the car you would like to delete."); string titleToDeleteBowling = Console.ReadLine(); Bowling contentToDeleteBowling = _bowlingRepo.GetContentByTitle(titleToDeleteBowling); bool wasDeletedBowling = _bowlingRepo.DeleteExistingContent(contentToDeleteBowling); if (wasDeletedBowling) { Console.WriteLine("This content was successfully deleted."); } else { Console.WriteLine("Content could not be deleted"); } break; case "2": Console.ReadKey(); Console.WriteLine("Enter the car's name for the car you would like to delete."); string titleToDeleteConcerts = Console.ReadLine(); Concerts contentToDeleteConcert = _concertsRepo.GetContentByTitle(titleToDeleteConcerts); bool wasDeletedConcert = _concertsRepo.DeleteExistingContent(contentToDeleteConcert); if (wasDeletedConcert) { Console.WriteLine("This content was successfully deleted."); } else { Console.WriteLine("Content could not be deleted"); } break; case "3": Console.ReadKey(); Console.WriteLine("Enter the car's name for the car you would like to delete."); string titleToDeleteGolf = Console.ReadLine(); Golf contentToDeleteGolf = _golfRepo.GetContentByTitle(titleToDeleteGolf); bool wasDeletedGolf = _golfRepo.DeleteExistingContent(contentToDeleteGolf); if (wasDeletedGolf) { Console.WriteLine("This content was successfully deleted."); } else { Console.WriteLine("Content could not be deleted"); } break; case "4": Console.ReadKey(); Console.WriteLine("Enter the car's name for the car you would like to delete."); string titleToDeleteAmusement = Console.ReadLine(); AmusementParks contentToDeleteAmusement = _amusementRepo.GetContentByTitle(titleToDeleteAmusement); bool wasDeletedAmusement = _amusementRepo.DeleteExistingContent(contentToDeleteAmusement); if (wasDeletedAmusement) { Console.WriteLine("This content was successfully deleted."); } else { Console.WriteLine("Content could not be deleted"); } break; case "5": continueToRun = false; break; default: Console.WriteLine("Please choose a valid option"); Console.ReadKey(); break; } } }
public Search(IAnalizatorXMLStrategy analizator, Concerts conc) { Strategy = analizator; concert = conc; }
public List <Concerts> Search(Concerts concert) { List <Concerts> result = new List <Concerts>(); XmlDocument doc = new XmlDocument(); doc.Load(@"D:\Програмування\C#\LabXml\LabXml\Concerts.xml"); XmlNode node = doc.DocumentElement; foreach (XmlNode nod in node.ChildNodes) { string Artist = ""; string Date = ""; string PriceRange = ""; string Location = ""; string Style = ""; string ArtistBand = ""; foreach (XmlAttribute attribute in nod.Attributes) { if (attribute.Name.Equals("Artist") && (attribute.Value.Equals(concert.Artist) || concert.Artist.Equals(String.Empty))) { Artist = attribute.Value; } if (attribute.Name.Equals("Date") && (attribute.Value.Equals(concert.Date) || concert.Date.Equals(String.Empty))) { Date = attribute.Value; } if (attribute.Name.Equals("PriceRange") && (isPriceRange(attribute.Value, concert.PriceRange) || concert.PriceRange.Equals(String.Empty))) { PriceRange = attribute.Value; } if (attribute.Name.Equals("Location") && (attribute.Value.Contains(concert.Location) || concert.Location.Equals(String.Empty))) { Location = attribute.Value; } if (attribute.Name.Equals("Style") && (attribute.Value.Equals(concert.Style) || concert.Style.Equals(String.Empty))) { Style = attribute.Value; } if (attribute.Name.Equals("ArtistBand") && (attribute.Value.Equals(concert.ArtistBand) || concert.ArtistBand.Equals(String.Empty))) { ArtistBand = attribute.Value; } } if (Artist != "" && Date != "" && PriceRange != "" && Location != "" && Style != "" && ArtistBand != "") { Concerts myConcert = new Concerts(); myConcert.Artist = Artist; myConcert.Date = Date; myConcert.PriceRange = PriceRange; myConcert.Location = Location; myConcert.Style = Style; myConcert.ArtistBand = ArtistBand; result.Add(myConcert); } } return(result); }
private void search() { Results.Text = ""; Concerts concert = new Concerts(); if (checkArtist.Checked) { concert.Artist = comboBoxArtist.SelectedItem.ToString(); } if (checkDate.Checked) { concert.Date = comboBoxDate.SelectedItem.ToString(); } if (checkPriceRange.Checked) { concert.PriceRange = comboBoxPriceRange.SelectedItem.ToString(); } if (checkLocation.Checked) { concert.Location = comboBoxLocation.SelectedItem.ToString(); } if (checkStyle.Checked) { concert.Style = comboBoxStyle.SelectedItem.ToString(); } if (checkArtistBand.Checked) { concert.ArtistBand = comboBoxArtistBand.SelectedItem.ToString(); } IAnalizatorXMLStrategy analizator = new AnalizatorXMLDOMStrategy(); // по замовчуванню if (radioButtonDOM.Checked) { analizator = new AnalizatorXMLDOMStrategy(); } if (radioButtonSAX.Checked) { analizator = new AnalizatorXMLSAXStrategy(); } if (radioButtonLINQ.Checked) { analizator = new AnalizatorXMLLINQStrategy(); } Search search = new Search(analizator, concert); List <Concerts> results = search.SearchAlgorithm(); foreach (Concerts conc in results) { Results.Text += "Артист: " + conc.Artist + "\n"; Results.Text += "Дата: " + conc.Date + "\n"; Results.Text += "Цінова категорія: " + conc.PriceRange + "\n"; Results.Text += "Місце проведення: " + conc.Location + "\n"; Results.Text += "Жанр музики: " + conc.Style + "\n"; Results.Text += "Артист чи група: " + conc.ArtistBand + "\n"; Results.Text += "\n\n\n"; } }
public List <Concerts> Search(Concerts concert) { List <Concerts> AllResult = new List <Concerts>(); var xmlReader = new XmlTextReader(@"D:\Програмування\C#\LabXml\LabXml\Concerts.xml"); while (xmlReader.Read()) { if (xmlReader.HasAttributes) { while (xmlReader.MoveToNextAttribute()) { string Artist = ""; string Date = ""; string PriceRange = ""; string Location = ""; string Style = ""; string ArtistBand = ""; if (xmlReader.Name.Equals("Artist") && (xmlReader.Value.Equals(concert.Artist) || concert.Artist.Equals(String.Empty))) { Artist = xmlReader.Value; xmlReader.MoveToNextAttribute(); if (xmlReader.Name.Equals("Date") && (xmlReader.Value.Equals(concert.Date) || concert.Date.Equals(String.Empty))) { Date = xmlReader.Value; xmlReader.MoveToNextAttribute(); if (xmlReader.Name.Equals("PriceRange") && ((isPriceRange(xmlReader.Value, concert.PriceRange) || concert.PriceRange.Equals(String.Empty)))) { PriceRange = xmlReader.Value; xmlReader.MoveToNextAttribute(); if (xmlReader.Name.Equals("Location") && (xmlReader.Value.Contains(concert.Location)) || concert.Location.Equals(String.Empty)) { Location = xmlReader.Value; xmlReader.MoveToNextAttribute(); if (xmlReader.Name.Equals("Style") && (xmlReader.Value.Equals(concert.Style) || concert.Style.Equals(String.Empty))) { Style = xmlReader.Value; xmlReader.MoveToNextAttribute(); if (xmlReader.Name.Equals("ArtistBand") && (xmlReader.Value.Equals(concert.ArtistBand) || concert.ArtistBand.Equals(String.Empty))) { ArtistBand = xmlReader.Value; } } } } } } if (Artist != "" && Date != "" && PriceRange != "" && Location != "" && Style != "" && ArtistBand != "") { Concerts myConcert = new Concerts(); myConcert.Artist = Artist; myConcert.Date = Date; myConcert.PriceRange = PriceRange; myConcert.Location = Location; myConcert.Style = Style; myConcert.ArtistBand = ArtistBand; AllResult.Add(myConcert); } } } } xmlReader.Close(); return(AllResult); }
public ConcertDTO Get(int id) { Concerts c = concertRepository.Get(id); return(mapper.Map <Concerts, ConcertDTO>(c)); }
/** * Rendezzük a listákat - koncerteket dátum szerint, együtteseket és helyszíneket névsor szerint */ public void SortLists() { Concerts = Concerts.OrderBy(c => c.Date).ToList(); Bands = Bands.OrderBy(b => b.Name).ToList(); Venues = Venues.OrderBy(v => v.Name).ToList(); }
public InfoBandPageViewModel(Concerts selectedConcert, ObservableCollection <Concerts> concertList) { this.selectedConcert = selectedConcert; this.concertList = concertList; }
private void ShowContentByTitle() { bool continueToRun = true; while (continueToRun) { Console.Clear(); Console.WriteLine("Enter the number of the option you'd like to select:\n" + "1. Find Bowling Events by name\n" + "2. Find Concert Events by name\n" + "3. Find Golf Events by name\n" + "4. Find Amusement Park Events by name\n" + "5. Exit"); string input = Console.ReadLine(); switch (input) { case "1": Console.Clear(); Console.WriteLine("Enter the title of the content you'd like to see."); string titleBowling = Console.ReadLine(); Bowling contentBowling = _bowlingRepo.GetContentByTitle(titleBowling); if (contentBowling != null) { DisplayContent(contentBowling); } else { Console.WriteLine("That title doesn't exist."); } Console.ReadKey(); break; case "2": Console.Clear(); Console.WriteLine("Enter the title of the content you'd like to see."); string titleConcerts = Console.ReadLine(); Concerts contentConcerts = _concertsRepo.GetContentByTitle(titleConcerts); if (contentConcerts != null) { DisplayContent(contentConcerts); } else { Console.WriteLine("That title doesn't exist."); } Console.ReadKey(); break; case "3": Console.Clear(); Console.WriteLine("Enter the title of the content you'd like to see."); string titleGolf = Console.ReadLine(); Golf contentGolf = _golfRepo.GetContentByTitle(titleGolf); if (contentGolf != null) { DisplayContent(contentGolf); } else { Console.WriteLine("That title doesn't exist."); } Console.ReadKey(); break; case "4": Console.Clear(); Console.WriteLine("Enter the title of the content you'd like to see."); string titleAmusement = Console.ReadLine(); AmusementParks contentAmusement = _amusementRepo.GetContentByTitle(titleAmusement); if (contentAmusement != null) { DisplayContent(contentAmusement); } else { Console.WriteLine("That title doesn't exist."); } Console.ReadKey(); break; case "5": continueToRun = false; break; default: Console.WriteLine("Please choose a valid option"); Console.ReadKey(); break; } } }
public ActionResult MakeReport() { using (var stream = new MemoryStream()) { using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document, true)) { MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); { ParagraphProperties pp = new ParagraphProperties(); Justification j1 = new Justification() { Val = JustificationValues.Center }; pp.Append(j1); Paragraph title = body.AppendChild(new Paragraph(pp)); title.Append(new Run(new Text("Звіт"))); Paragraph par = body.AppendChild(new Paragraph()); par.Append(new Run(new Text($"Звіт створено: {DateTime.UtcNow.ToLongDateString()} {DateTime.UtcNow.ToShortTimeString()} (UTC+0)"))); par = body.AppendChild(new Paragraph()); //par.Append(new Run(new Break())); } { List <Tuple <string, string> > amounts = new List <Tuple <string, string> >(); amounts.Add(new Tuple <string, string>("Виконавці", $"{_context.Artists.Count()}")); amounts.Add(new Tuple <string, string>("Виконавці / Жанри", $"{_context.ArtistsGenres.Count()}")); amounts.Add(new Tuple <string, string>("Міста", $"{_context.Cities.Count()}")); amounts.Add(new Tuple <string, string>("Клієнти", $"{_context.Clients.Count()}")); amounts.Add(new Tuple <string, string>("Концерти", $"{_context.Concerts.Count()}")); amounts.Add(new Tuple <string, string>("Концерти / Виконавці", $"{_context.ConcertsArtists.Count()}")); amounts.Add(new Tuple <string, string>("Країни", $"{_context.Countries.Count()}")); amounts.Add(new Tuple <string, string>("Жанри", $"{_context.Genres.Count()}")); amounts.Add(new Tuple <string, string>("Місця", $"{_context.Locations.Count()}")); amounts.Add(new Tuple <string, string>("Сектори", $"{_context.Sectors.Count()}")); amounts.Add(new Tuple <string, string>("Квитки", $"{_context.Tickets.Count()}")); Paragraph t = body.AppendChild(new Paragraph()); t.Append(new Run(new Text("Кількість записів в БД:"))); foreach (Tuple <string, string> amount in amounts) { Paragraph par = body.AppendChild(new Paragraph()); par.ParagraphProperties = new ParagraphProperties(new Tabs(new TabStop() { Val = TabStopValues.Right, Position = 9000, Leader = TabStopLeaderCharValues.Dot })); par.Append(new Run(new Text(amount.Item1))); par.Append(new Run(new TabChar())); par.Append(new Run(new Text(amount.Item2))); } } { Paragraph par = body.AppendChild(new Paragraph()); decimal sum = 0; var t = _context.Tickets.Include(t => t.Sector); foreach (Tickets ticket in t) { sum += ticket.Sector.Price; } par = body.AppendChild(new Paragraph()); par.Append(new Run(new Text($"Загальна вартість квитків - {sum.ToString("F2")} грн"))); par = body.AppendChild(new Paragraph()); par.Append(new Run(new Text($"Середня вартість квитка - {(sum/(decimal)_context.Tickets.Count()).ToString("F2")} грн"))); if (_context.Concerts.Count() > 0) { int maxTickets = 0; Concerts maxConcert = null; foreach (Concerts c in _context.Concerts) { int count = _context.Tickets.Count(t => t.Sector.ConcertId == c.Id); if (count > maxTickets) { maxTickets = count; maxConcert = c; } } par = body.AppendChild(new Paragraph()); par.Append(new Run(new Text($"Найпопулярніший концерт - {maxConcert.Name} (Квитки: {maxTickets})"))); } } mainPart.Document.Save(); wordDocument.Close(); stream.Flush(); return(new FileContentResult(stream.ToArray(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { FileDownloadName = $"report_{DateTime.UtcNow.ToShortDateString()}.docx" }); } } }
private void CreateNewContent() { bool continueToRun = true; while (continueToRun) { Console.Clear(); Console.WriteLine("Enter the number of the option you'd like to select:\n" + "1. Create new Bowling Event\n" + "2. Create new Concert Event\n" + "3. Create new Golf Event\n" + "4. Create new Amusement Park Event\n" + "5. Exit"); string input = Console.ReadLine(); switch (input) { case "1": Console.Clear(); Bowling newContentBowling = new Bowling(); Console.WriteLine("Please enter a name for this event."); string nameBowlingAsString = Console.ReadLine(); newContentBowling.NameOfEvent = nameBowlingAsString; Console.WriteLine("Please enter the number of people attending the event."); string numberOfPeopleAsString = Console.ReadLine(); int numberOfPeopleAsInt = int.Parse(numberOfPeopleAsString); newContentBowling.NumberOfPeople = numberOfPeopleAsInt; Console.WriteLine("Please enter a cost per person for this event."); string costPerPersonAsString = Console.ReadLine(); double costPerPersonAsInt = double.Parse(costPerPersonAsString); newContentBowling.CostPerPerson = costPerPersonAsInt; Console.WriteLine("Please enter a total cost for the entire event."); string costOfEntireEventAsString = Console.ReadLine(); double costOfEntireEventAsDouble = int.Parse(costOfEntireEventAsString); newContentBowling.CostOfEntireEvent = costOfEntireEventAsDouble; Console.WriteLine("Please enter a date for this event."); string dateAsString = Console.ReadLine(); DateTime dateAsDate = DateTime.Parse(dateAsString); newContentBowling.Date = dateAsDate; bool wasAddedRepo = _bowlingRepo.AddContentToDirectory(newContentBowling); if (wasAddedRepo == true) { Console.WriteLine("Your content was succesfully added."); } else { Console.WriteLine("Oops something went wrong. Your content was not added."); } break; case "2": Console.Clear(); Concerts newContentConcerts = new Concerts(); Console.WriteLine("Please enter a name for this event."); string nameConcertAsString = Console.ReadLine(); newContentConcerts.NameOfEvent = nameConcertAsString; Console.WriteLine("Please enter the number of people attending the event."); string numberOfPeopleConcertsAsString = Console.ReadLine(); int numberOfPeopleConcertsAsInt = int.Parse(numberOfPeopleConcertsAsString); newContentConcerts.NumberOfPeople = numberOfPeopleConcertsAsInt; Console.WriteLine("Please enter a cost per person for this event."); string costPerPersonConcertsAsString = Console.ReadLine(); double costPerPersonConcertsAsInt = double.Parse(costPerPersonConcertsAsString); newContentConcerts.CostPerPerson = costPerPersonConcertsAsInt; Console.WriteLine("Please enter a total cost for the entire event."); string costOfEntireEventConcertsAsString = Console.ReadLine(); double costOfEntireEventConcertsAsDouble = int.Parse(costOfEntireEventConcertsAsString); newContentConcerts.CostOfEntireEvent = costOfEntireEventConcertsAsDouble; Console.WriteLine("Please enter a date for this event."); string dateConcertsAsString = Console.ReadLine(); DateTime dateConcertsAsDate = DateTime.Parse(dateConcertsAsString); newContentConcerts.Date = dateConcertsAsDate; bool wasAddedRepoConcerts = _concertsRepo.AddContentToDirectory(newContentConcerts); if (wasAddedRepoConcerts == true) { Console.WriteLine("Your content was succesfully added."); } else { Console.WriteLine("Oops something went wrong. Your content was not added."); } break; case "3": Console.Clear(); Golf newContentGolf = new Golf(); Console.WriteLine("Please enter a name for this event."); string nameGolfAsString = Console.ReadLine(); newContentGolf.NameOfEvent = nameGolfAsString; Console.WriteLine("Please enter the number of people attending the event."); string numberOfPeopleGolfAsString = Console.ReadLine(); int numberOfPeopleGolfAsInt = int.Parse(numberOfPeopleGolfAsString); newContentGolf.NumberOfPeople = numberOfPeopleGolfAsInt; Console.WriteLine("Please enter a cost per person for this event."); string costPerPersonGolfAsString = Console.ReadLine(); double costPerPersonGolfAsInt = double.Parse(costPerPersonGolfAsString); newContentGolf.CostPerPerson = costPerPersonGolfAsInt; Console.WriteLine("Please enter a total cost for the entire event."); string costOfEntireEventGolfAsString = Console.ReadLine(); double costOfEntireEventGolfAsDouble = int.Parse(costOfEntireEventGolfAsString); newContentGolf.CostOfEntireEvent = costOfEntireEventGolfAsDouble; Console.WriteLine("Please enter a date for this event."); string dateGolfAsString = Console.ReadLine(); DateTime dateGolfAsDate = DateTime.Parse(dateGolfAsString); newContentGolf.Date = dateGolfAsDate; bool wasAddedRepoGolf = _golfRepo.AddContentToDirectory(newContentGolf); if (wasAddedRepoGolf == true) { Console.WriteLine("Your content was succesfully added."); } else { Console.WriteLine("Oops something went wrong. Your content was not added."); } break; case "4": Console.Clear(); AmusementParks newContentAmusement = new AmusementParks(); Console.WriteLine("Please enter a name for this event."); string nameAmusementAsString = Console.ReadLine(); newContentAmusement.NameOfEvent = nameAmusementAsString; Console.WriteLine("Please enter the number of people attending the event."); string numberOfPeopleAmusementAsString = Console.ReadLine(); int numberOfPeopleAmusementAsInt = int.Parse(numberOfPeopleAmusementAsString); newContentAmusement.NumberOfPeople = numberOfPeopleAmusementAsInt; Console.WriteLine("Please enter a cost per person for this event."); string costPerPersonAmusementAsString = Console.ReadLine(); double costPerPersonAmusementAsInt = double.Parse(costPerPersonAmusementAsString); newContentAmusement.CostPerPerson = costPerPersonAmusementAsInt; Console.WriteLine("Please enter a total cost for the entire event."); string costOfEntireEventAmusementAsString = Console.ReadLine(); double costOfEntireEventAmusementAsDouble = int.Parse(costOfEntireEventAmusementAsString); newContentAmusement.CostOfEntireEvent = costOfEntireEventAmusementAsDouble; Console.WriteLine("Please enter a date for this event."); string dateAmusementAsString = Console.ReadLine(); DateTime dateAmusementAsDate = DateTime.Parse(dateAmusementAsString); newContentAmusement.Date = dateAmusementAsDate; bool wasAddedRepoAmusement = _amusementRepo.AddContentToDirectory(newContentAmusement); if (wasAddedRepoAmusement == true) { Console.WriteLine("Your content was succesfully added."); } else { Console.WriteLine("Oops something went wrong. Your content was not added."); } break; case "5": continueToRun = false; break; default: Console.WriteLine("Please choose a valid option"); Console.ReadKey(); break; } } }