public async Task <IActionResult> PutConcerte([FromRoute] int id, [FromBody] Concerte concerte) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != concerte.ID) { return(BadRequest()); } _context.Entry(concerte).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(Accepted(concerte)); } catch (DbUpdateConcurrencyException) { if (!ConcerteExists(id)) { return(NotFound()); } else { throw; } } }
public async Task <IActionResult> PostConcerte([FromBody] Concerte concerte) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Concerts.Add(concerte); await _context.SaveChangesAsync(); return(CreatedAtAction("GetConcerte", new { id = concerte.ID }, concerte)); }
public static void Initialize(ConcerteContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Sellers.Any()) { return; // DB has been seeded } var sellers = new Seller[] { new Seller { BrandName = "Big Billet" }, new Seller { BrandName = "Afisha" }, new Seller { BrandName = "Ozone" } }; foreach (Seller s in sellers) { context.Sellers.Add(s); } context.SaveChanges(); var concertes = new Concerte[] { new Concerte { ArenaName = "Crocus City Hall", ArtistName = "Marilyn Manson", CityName = "Moscow", Date = DateTime.Parse("2015-09-01"), SellerID = 1, ShowName = "BigSHow", TicketsNumber = 1000, Price = 2000 }, new Concerte { ArenaName = "Brixton Academy", ArtistName = "Marilyn Manson", CityName = "London", Date = DateTime.Parse("2015-10-01"), SellerID = 2, ShowName = "Hello, London", TicketsNumber = 2000, Price = 4000 }, new Concerte { ArenaName = "Mercedes-Benz Arena", ArtistName = "Marilyn Manson", CityName = "Berlin", Date = DateTime.Parse("2015-11-01"), SellerID = 2, ShowName = "Hello, Berlin", TicketsNumber = 3000, Price = 6000 }, new Concerte { ArenaName = "Crocus City Hall", ArtistName = "Depeche mode", CityName = "Moscow", Date = DateTime.Parse("2016-09-01"), SellerID = 1, ShowName = "BigSHow", TicketsNumber = 1000, Price = 9000 }, new Concerte { ArenaName = "Brixton Academy", ArtistName = "Depeche mode", CityName = "London", Date = DateTime.Parse("2016-10-01"), SellerID = 2, ShowName = "Hello, Hello", TicketsNumber = 2000, Price = 11000 }, new Concerte { ArenaName = "Mercedes-Benz Arena", ArtistName = "Depeche mode", CityName = "Berlin", Date = DateTime.Parse("2016-11-01"), SellerID = 2, ShowName = "Hello, Berlin", TicketsNumber = 3000, Price = 1000 }, new Concerte { ArenaName = "Olimpiyskiy", ArtistName = "30 Seconds to Mars", CityName = "Moscow", Date = DateTime.Parse("2016-02-01"), SellerID = 1, ShowName = "BigGiG", TicketsNumber = 3000, Price = 22000 }, new Concerte { ArenaName = "Brixton Academy", ArtistName = "30 Seconds to Mars", CityName = "London", Date = DateTime.Parse("2016-03-01"), SellerID = 2, ShowName = "Hello,Good Bye", TicketsNumber = 5000, Price = 3100 }, new Concerte { ArenaName = "Mercedes-Benz Arena", ArtistName = "30 Seconds to Mars", CityName = "Berlin", Date = DateTime.Parse("2016-04-01"), SellerID = 2, ShowName = "Hello, WORLD", TicketsNumber = 6000, Price = 2400 }, new Concerte { ArenaName = "Vova Arena", ArtistName = "Frank Sinatra", CityName = "Moscow", Date = DateTime.Parse("2017-09-01"), SellerID = 3, ShowName = "VovaSHow", TicketsNumber = 1000, Price = 2600 }, new Concerte { ArenaName = "Vova Arena", ArtistName = "Frank Sinatra", CityName = "Moscow", Date = DateTime.Parse("2017-10-01"), SellerID = 3, ShowName = "VovaSHow2", TicketsNumber = 1000, Price = 3500 }, new Concerte { ArenaName = "Mercedes-Benz Arena", ArtistName = "30 Seconds to Mars", CityName = "Berlin", Date = DateTime.Parse("2016-04-01"), SellerID = 2, ShowName = "Hello, WORLD", TicketsNumber = 99000, Price = 44000 }, new Concerte { ArenaName = "Vova Arena", ArtistName = "Frank Sinatra", CityName = "Berlin", Date = DateTime.Parse("2017-09-01"), SellerID = 3, ShowName = "VovaSHow", TicketsNumber = 1000, Price = 4500 }, new Concerte { ArenaName = "Mercedes-Benz Arena", ArtistName = "Eminem", CityName = "Berlin", Date = DateTime.Parse("2017-09-01"), SellerID = 3, ShowName = "VovaSHow", TicketsNumber = 1000, Price = 3000 }, new Concerte { ArenaName = "Trash Arena", ArtistName = "Eminem", CityName = "Berlin", Date = DateTime.Parse("2017-09-01"), SellerID = 3, ShowName = "VovaSHow", TicketsNumber = 1000, Price = 8000 } }; foreach (Concerte c in concertes) { context.Concerts.Add(c); } context.SaveChanges(); }
public async Task <IActionResult> GetValidSecretConcertes() { var Bus = RabbitHutch.CreateBus("host=localhost"); ConcurrentStack <RabbitConcerteSeller> concertesellerCollection = new ConcurrentStack <RabbitConcerteSeller>(); Bus.Receive <RabbitConcerteSeller>("concerteseller", msg => { concertesellerCollection.Push(msg); }); Thread.Sleep(5000); foreach (RabbitConcerteSeller cs in concertesellerCollection) { Seller s = new Seller() { BrandName = cs.BrandName }; _context.Sellers.Add(s); } _context.SaveChanges(); foreach (RabbitConcerteSeller cs in concertesellerCollection) { int c_id = 0; foreach (Seller s in _context.Sellers) { if (cs.BrandName == s.BrandName) { c_id = s.ID; } } Concerte c = new Concerte() { ArenaName = cs.ArenaName, ArtistName = cs.ArtistName, CityName = cs.CityName, Date = cs.Date, Price = cs.Price, ShowName = cs.ShowName, TicketsNumber = cs.TicketsNumber, SellerID = c_id }; _context.Concerts.Add(c); } _context.SaveChanges(); var qry = _context.Concerts.OrderBy(p => p.ID); foreach (Concerte a in qry) { _context.Entry(a).Navigation("Seller").Load(); } //Проверить, что: // 1) кол-во билетов меньше, чем вместительность арены // 2) город существует и корректный // 3) арена существует и из этого города // 4) артист корректный // //Вытаскиваем все Арены // List <Arena> QryArenas = new List <Arena>(); var corrId = string.Format("{0}{1}", DateTime.Now.Ticks, Thread.CurrentThread.ManagedThreadId); string request; byte[] responseMessage; using (var client = new HttpClient()) { client.BaseAddress = new Uri(URLArenaService); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string requestString = "api/arenas"; HttpResponseMessage response = await client.GetAsync(requestString); request = "SERVICE: ArenaService \r\nGET: " + URLArenaService + "/" + requestString + "\r\n" + client.DefaultRequestHeaders.ToString(); string responseString = response.Headers.ToString() + "\nStatus: " + response.StatusCode.ToString(); if (response.IsSuccessStatusCode) { responseMessage = await response.Content.ReadAsByteArrayAsync(); var arenas = await response.Content.ReadAsStringAsync(); QryArenas = JsonConvert.DeserializeObject <List <Arena> >(arenas); } else { responseMessage = Encoding.UTF8.GetBytes(response.ReasonPhrase); } await LogQuery(request, responseString, responseMessage); } // //Вытаскиваем всех Артистов // List <Artist> QryArtists = new List <Artist>(); var corrId2 = string.Format("{0}{1}", DateTime.Now.Ticks, Thread.CurrentThread.ManagedThreadId); string request2; byte[] responseMessage2; using (var client = new HttpClient()) { client.BaseAddress = new Uri(URLArtistService); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string requestString2 = "api/artists"; HttpResponseMessage response2 = await client.GetAsync(requestString2); request2 = "SERVICE: ArenaService \r\nGET: " + URLArtistService + "/" + requestString2 + "\r\n" + client.DefaultRequestHeaders.ToString(); string responseString2 = response2.Headers.ToString() + "\nStatus: " + response2.StatusCode.ToString(); if (response2.IsSuccessStatusCode) { responseMessage2 = await response2.Content.ReadAsByteArrayAsync(); var artists = await response2.Content.ReadAsStringAsync(); QryArtists = JsonConvert.DeserializeObject <List <Artist> >(artists); } else { responseMessage2 = Encoding.UTF8.GetBytes(response2.ReasonPhrase); } await LogQuery(request2, responseString2, responseMessage2); } // //Проверить на валидность все концерты // List <Concerte> ValidConcertes = new List <Concerte>(); foreach (Concerte c in qry) { //находим название Арены с таким же, как в концерте Arena FindedArena; foreach (Arena a in QryArenas) { if (a.ArenaName == c.ArenaName) { FindedArena = a; if (a.Capacity >= c.TicketsNumber) { if (a.City.CityName == c.CityName) { Artist artist = QryArtists.Where(x => x.ArtistName == c.ArtistName).FirstOrDefault(); if (artist != null) { ValidConcertes.Add(c); } } } } } } return(Ok(ValidConcertes)); }