//One color for each category public async Task <ChartDTO> TakeByMultiple(int n, Continents continent, Func <CoronaCountryState, string> namer, params Expression <Func <CoronaCountryState, int> >[] expressions) { var state = await State(continent); var orderer = expressions.First().Compile(); T [] Scalar <T>(Func <CoronaCountryState, T> func) => state.OrderByDescending(orderer) .Select(func) .Take(n) .ToArray(); DataSetDTO GetDataSetFromExpression((Expression <Func <CoronaCountryState, int> > expr, string color) tupla) { var prop = (MemberExpression)tupla.expr.Body; var name = prop.Member.Name; var selector = tupla.expr.Compile(); return(new DataSetDTO(name, Scalar(selector), tupla.color)); } var datasets = expressions.Zip(LazyService.AllColors.Value).Select(GetDataSetFromExpression).ToArray(); return(new ChartDTO(Scalar(namer), datasets)); }
public async Task <IActionResult> PutContinents(Guid id, Continents continents) { if (id != continents.Id) { return(BadRequest()); } _context.Entry(continents).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContinentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("ContinentId,Name,Area")] Continents continents) { if (id != continents.ContinentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(continents); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContinentsExists(continents.ContinentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(continents)); }
public async Task <IActionResult> Edit(int id, [Bind("ContinentId,Name,Area")] Continents continents) { bool duplicate = await _context.Continents.AnyAsync(l => l.Name.Equals(continents.Name) && !l.ContinentId.Equals(continents.ContinentId)); if (duplicate) { ModelState.AddModelError("Name", "Такий континент вже доданий"); } if (id != continents.ContinentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(continents); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContinentsExists(continents.ContinentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(continents)); }
public List <Territory> GetAllTerritories() { List <Territory> allTerritories = new List <Territory>(); Continents.ForEach(c => c.ForEach(t => allTerritories.Add(t))); return(allTerritories); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name")] Continents continents) { if (id != continents.Id) { return(NotFound()); } if (ModelState.IsValid) { try { //WebAPI Call var json = JsonConvert.SerializeObject(continents); var data = new StringContent(json, Encoding.UTF8, "application/json"); using var client = new HttpClient(); var response = await client.PutAsync("http://localhost:61038/api/Continent/" + continents.Id.ToString(), data); string result = response.Content.ReadAsStringAsync().Result; } catch (Exception) { } return(RedirectToAction(nameof(Index))); } return(View(continents)); }
public PageStartData() { InitializeComponent(); Continent continentAll = new Continent("100", "All continents"); cbContinent.Items.Add(continentAll); foreach (Continent continent in Continents.GetContinents()) { cbContinent.Items.Add(continent); } foreach (Region region in Regions.GetAllRegions()) { cbRegion.Items.Add(region); } for (int i = 1960; i < 2014; i++) { cbYear.Items.Insert(0, i); } cbYear.SelectedIndex = 0; cbDifficulty.ItemsSource = DifficultyLevels.GetDifficultyLevels(); foreach (Airline.AirlineFocus focus in Enum.GetValues(typeof(Airline.AirlineFocus))) { cbFocus.Items.Add(focus); } }
public IHttpActionResult PostContinents(Continents continents) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Continents.Add(continents); try { db.SaveChanges(); } catch (DbUpdateException) { if (ContinentsExists(continents.Name)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = continents.Name }, continents)); }
Tab GetTab(string name, List <Chart> charts, Continents continent, bool active = false) { var groups = charts.Select((x, i) => new { Index = i, Value = x }) .GroupBy(x => x.Index / 2); var tab = new Tab(name, continent); tab.IsActive = active; foreach (var group in groups) { var elements = group.ToList(); if (elements.Count == 1) { tab.Rows.Add(new RowChart(elements.ElementAt(0).Value, null)); } else { tab.Rows.Add(new RowChart(elements.ElementAt(0).Value, elements.ElementAt(1).Value)); } } return(tab); }
// GET: Continent/Details/5 public async Task <IActionResult> Details(Guid?id) { if (id == null) { return(NotFound()); } //WebAPI Call Continents continents = null; using (HttpClient httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(webAPIURL + id.ToString())) { string jsonResponse = await response.Content.ReadAsStringAsync(); continents = JsonConvert.DeserializeObject <Continents>(jsonResponse); } } if (continents == null) { return(NotFound()); } return(View(continents)); }
public IHttpActionResult PutContinents(string id, Continents continents) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != continents.Name) { return(BadRequest()); } db.Entry(continents).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContinentsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private TurnStarted StartTurn(Player player) { var countries = Countries.Count(c => c.Owner == player); var deploy = (Math.Max(3, countries / 3)); deploy += Continents.Where(c => c.Owner == player).Sum(c => c.Bonus); return(new TurnStarted(Deployments: player.Army(deploy))); }
public Country(string name, Continents continent, double area, long population, DateTime independenceDay = default) { Name = name; Continents = continent; Area = area; Population = population; IndependenceDay = independenceDay; }
public async Task OnUpdate(DateTime now) { if ((now - LastUpdate).Seconds < 30) { return; } LastUpdate = now; await Task.WhenAll(Continents.Select(c => c.OnUpdate(now))); }
public async Task <IActionResult> Create([Bind("ContinentId,Name,Area")] Continents continents) { if (ModelState.IsValid) { _context.Add(continents); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(continents)); }
public void CreateEntity(IList <string> entityCharacteristics) { var continent = new Continents() { Name = entityCharacteristics[0], PlanetId = int.Parse(entityCharacteristics[1]) }; this.DbContext.Continents.Add(continent); this.DbContext.SaveChanges(); }
public IHttpActionResult GetContinents(string id) { Continents continents = db.Continents.Find(id); if (continents == null) { return(NotFound()); } return(Ok(continents)); }
public void AddContinents() { Continents.Add("Whole World"); Continents.Add("Africa"); Continents.Add("Antarctica"); Continents.Add("Asia"); Continents.Add("Australia"); Continents.Add("Europe"); Continents.Add("North America"); Continents.Add("South America"); }
private void LinkContinentsToCountries(IEnumerable <ContinentInitialized> continents) { foreach (var data in continents.Select((c, id) => new { Continent = ContinentId.Create(id), Countries = c.Territories })) { var continent = Continents.ById(data.Continent); foreach (var id in data.Countries) { var country = Countries.ById(id); country.Continent = continent; } } }
public IHttpActionResult DeleteContinents(string id) { Continents continents = db.Continents.Find(id); if (continents == null) { return(NotFound()); } db.Continents.Remove(continents); db.SaveChanges(); return(Ok(continents)); }
public ActionResult <IList <GameViewModel> > GetAll(string continent) { if (string.IsNullOrWhiteSpace(continent)) { return(this.BadRequest()); } if (!Continents.Contains(continent)) { return(this.BadRequest()); } var countries = this.service.GetAllCountriesByContinent(continent); return(countries); }
public static void ClearDictionaries() { States.Clear(); Continents.Clear(); PopTypes.Clear(); Goods.Clear(); CountryTags.Clear(); Religions.Clear(); Cultures.Clear(); CultureGroups.Clear(); Ideologies.Clear(); Buildings.Clear(); PolicyGroups.Clear(); SubPolicies.Clear(); Schools.Clear(); Techs.Clear(); Inventions.Clear(); Units.Clear(); Governments.Clear(); Crimes.Clear(); EventModifiers.Clear(); NationalValues.Clear(); Terrain.Clear(); States = null; Continents = null; PopTypes = null; Goods = null; CountryTags = null; Religions = null; Cultures = null; CultureGroups = null; Ideologies = null; Buildings = null; PolicyGroups = null; SubPolicies = null; Schools = null; Techs = null; Inventions = null; Units = null; Governments = null; Crimes = null; EventModifiers = null; NationalValues = null; Terrain = null; }
public async Task <IActionResult> Create([Bind("ContinentId,Name,Area")] Continents continents) { bool duplicate = await _context.Continents.AnyAsync(l => l.Name.Equals(continents.Name)); if (duplicate) { ModelState.AddModelError("Name", "Такий континент вже доданий"); } if (ModelState.IsValid) { _context.Add(continents); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(continents)); }
public void OnGet() { Continents = _locationRepo.GetContinents() .Select(x => new SelectListItem() { Value = x, Text = x }) .ToList(); SelectedContinent = Continents.First().Value; Countries = _locationRepo.GetCountries(SelectedContinent) .Select(x => new SelectListItem() { Value = x, Text = x }) .ToList(); SelectedCountry = Countries.First().Value; }
private async Task <bool> CheckContinent(IServiceProvider services) { if (Continents != null && Continents.Any()) { var locationInfo = await GetGeoLocation(services); if (locationInfo == null) { return(Continents.Contains("unknown")); } else { return(Continents.Contains(locationInfo.ContinentCode)); } } return(true); }
async Task <List <CoronaCountryState> > State(Continents continent) { switch (continent) { case Continents.All: return(await GlobalState); case Continents.Asia: return((await GlobalState) .Where(c => LazyService.Asia.Value.Contains(c.Country)) .ToList()); case Continents.Africa: return((await GlobalState) .Where(c => LazyService.Africa.Value.Contains(c.Country)) .ToList()); case Continents.Europe: return((await GlobalState) .Where(c => LazyService.Europe.Value.Contains(c.Country)) .ToList()); case Continents.North_America: return((await GlobalState) .Where(c => LazyService.North_America.Value.Contains(c.Country)) .ToList()); case Continents.South_America: return((await GlobalState) .Where(c => LazyService.South_America.Value.Contains(c.Country)) .ToList()); case Continents.Oceania: return((await GlobalState) .Where(c => LazyService.Oceania.Value.Contains(c.Country)) .ToList()); default: return(await GlobalState); } }
public async Task <ActionResult <Continents> > PostContinents(Continents continents) { _context.Continents.Add(continents); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ContinentsExists(continents.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetContinents", new { id = continents.Id }, continents)); }
//One Color for each dataset public async Task <ChartDTO> TakeBy(int n, Continents continent, Func <CoronaCountryState, string> namer, Expression <Func <CoronaCountryState, int> > expression) { var state = await State(continent); var prop = (MemberExpression)expression.Body; var name = prop.Member.Name; var selector = expression.Compile(); var countries = state.OrderByDescending(selector) .Take(n); T [] Scalar <T>(Func <CoronaCountryState, T> func) => countries.Select(func).ToArray(); var datasets = new [] { new DataSetDTO(name, Scalar(selector), LazyService.AllColors.Value.Take(n).ToArray()), }; return(new ChartDTO(Scalar(namer), datasets)); }
static void Main(string[] args) { Continents visited = 0; string[] linesArray = File.ReadAllLines("travels.txt"); foreach (string line in linesArray) { Continents ct; if (Enum.TryParse <Continents>(line, out ct)) { visited |= ct; } else { Console.WriteLine("Ignoring invalid value " + line); } } // Console.WriteLine("You visited: " + visited); // Console.ReadKey(); }
public async Task <IActionResult> Create([Bind("Id,Name")] Continents continents) { if (continents != null) { continents.Id = Guid.NewGuid(); } if (ModelState.IsValid) { string json = JsonConvert.SerializeObject(continents); var data = new StringContent(json, Encoding.UTF8, "application/json"); using var client = new HttpClient(); var response = await client.PostAsync("http://localhost:61038/api/Continent/", data); string result = response.Content.ReadAsStringAsync().Result; return(RedirectToAction(nameof(Index))); } return(View(continents)); }