예제 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            bool isAddNew = false;

            if (Competition.result == null)
            {
                Competition.result = new List <Result>();
            }
            var keys     = HttpContext.Request.Form.Keys;
            var keyNames = keys.Where(e => e.Contains("point#")).ToArray();

            for (int i = 0; i < keyNames.Length; i++)
            {
                var formValue  = HttpContext.Request.Form[keyNames[i]];
                var playerName = keyNames[i].Split("#", StringSplitOptions.RemoveEmptyEntries);
                Console.WriteLine(formValue[0]);
                Competition.result.Add(new Result
                {
                    name  = playerName[1],
                    point = Convert.ToDouble(formValue[0])
                });
                isAddNew = true;
            }
            if (isAddNew)
            {
                BlobStorageService blobService = new BlobStorageService(_configuration.GetValue <string>("BlobStorageConnectionString"));
                await blobService.InitializeAsync(BlobConatiner);

                var fileName = Path.Combine(Directory.GetCurrentDirectory(), "data" + DateTime.Now.ToString("HHmmsss") + ".json");
                await blobService.DownloadAsync("data.json", fileName);

                string         json       = System.IO.File.ReadAllText(fileName);
                UnderlordTable collection = JsonConvert.DeserializeObject <UnderlordTable>(json);
                collection.competition.Add(Competition);
                string output = JsonConvert.SerializeObject(collection);
                System.IO.File.WriteAllText(fileName, output);
                await blobService.UploadFileAsync(fileName, "data.json");

                System.IO.File.Delete(fileName);
                return(RedirectToPage("./Index"));
            }
            else
            {
                return(Page());
            }
        }
예제 #2
0
        public async Task OnGetAsync()
        {
            BlobStorageService blobService = new BlobStorageService(_configuration.GetValue <string>("BlobStorageConnectionString"));
            await blobService.InitializeAsync(BlobConatiner);

            var fileName = Path.Combine(Directory.GetCurrentDirectory(), "data" + DateTime.Now.ToString("HHmmsss") + ".json");
            await blobService.DownloadAsync("data.json", fileName);

            string json = System.IO.File.ReadAllText(fileName);

            if (!string.IsNullOrEmpty(json))
            {
                UnderlordTable collection = JsonConvert.DeserializeObject <UnderlordTable>(json);

                foreach (var round in collection.competition)
                {
                    foreach (var match in round.result)
                    {
                        var player = collection.player.Where(e => e.name == match.name).FirstOrDefault();
                        if (player != null)
                        {
                            player.point += match.point;
                            if (player.form == null)
                            {
                                player.form = new List <ResultRound>();
                            }
                            player.form.Add(new ResultRound
                            {
                                round = round.round,
                                point = match.point
                            });
                        }
                    }
                }
                ListPlayer = collection.player.AsEnumerable().OrderByDescending(e => e.point)
                             .Select((row, index) => new Player {
                    name = row.name, point = row.point, form = row.form, position = index + 1
                })
                             .ToList();
            }
            System.IO.File.Delete(fileName);
        }
예제 #3
0
        public async Task OnGetAsync()
        {
            BlobStorageService blobService = new BlobStorageService(_configuration.GetValue <string>("BlobStorageConnectionString"));
            await blobService.InitializeAsync(BlobConatiner);

            var fileName = Path.Combine(Directory.GetCurrentDirectory(), "data" + DateTime.Now.ToString("HHmmsss") + ".json");
            await blobService.DownloadAsync("data.json", fileName);

            string json = System.IO.File.ReadAllText(fileName);

            if (!string.IsNullOrEmpty(json))
            {
                UnderlordTable collection = JsonConvert.DeserializeObject <UnderlordTable>(json);
                Players            = collection.player;
                Competition        = new Competition();
                Competition.round  = collection.competition.Max(e => e.round) + 1;
                Competition.result = new List <Result>();
            }
            System.IO.File.Delete(fileName);
        }