// GET: AdminMatchTechnicalInfos/Create
        public async Task <IActionResult> Create(int matchID)
        {
            var matchTechnicalInfos = new MatchTechnicalInfos()
            {
                MatchID        = matchID,
                GameServerPort = 2302,
                VoipServerPort = 9987
            };

            await LoadInformations(matchTechnicalInfos);

            return(View(matchTechnicalInfos));
        }
        public async Task <IActionResult> Create(MatchTechnicalInfos matchTechnicalInfos, IFormFile modpack)
        {
            if (ModelState.IsValid)
            {
                await ProcessModpack(matchTechnicalInfos, modpack);

                _context.Add(matchTechnicalInfos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminMatchsController.Details), ControllersName.AdminMatchs, new { id = matchTechnicalInfos.MatchID }));
            }
            await LoadInformations(matchTechnicalInfos);

            return(View(matchTechnicalInfos));
        }
 private async Task <bool> ProcessModpack(MatchTechnicalInfos matchTechnicalInfos, IFormFile modpack)
 {
     if (modpack != null)
     {
         using (var reader = new StreamReader(modpack.OpenReadStream(), Encoding.UTF8))
         {
             matchTechnicalInfos.ModsDefinition = await reader.ReadToEndAsync();
         }
         matchTechnicalInfos.ModsLastChange = DateTime.Now;
         var doc = XDocument.Parse(matchTechnicalInfos.ModsDefinition);
         matchTechnicalInfos.ModsCount = doc.Descendants("tr").Attributes("data-type").Where(a => a.Value == "ModContainer").Count();
         return(true);
     }
     return(false);
 }
        public async Task <IActionResult> Edit(int id, MatchTechnicalInfos matchTechnicalInfos, IFormFile modpack)
        {
            if (id != matchTechnicalInfos.MatchTechnicalInfosID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!await ProcessModpack(matchTechnicalInfos, modpack))
                    {
                        var existing = await _context.MatchTechnicalInfos.AsNoTracking().FirstAsync(i => i.MatchTechnicalInfosID == matchTechnicalInfos.MatchTechnicalInfosID);

                        matchTechnicalInfos.ModsCount      = existing.ModsCount;
                        matchTechnicalInfos.ModsDefinition = existing.ModsDefinition;
                        matchTechnicalInfos.ModsLastChange = existing.ModsLastChange;
                    }

                    _context.Update(matchTechnicalInfos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MatchTechnicalInfosExists(matchTechnicalInfos.MatchTechnicalInfosID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(AdminMatchsController.Details), ControllersName.AdminMatchs, new { id = matchTechnicalInfos.MatchID }));
            }
            await LoadInformations(matchTechnicalInfos);

            return(View(matchTechnicalInfos));
        }
 private async Task LoadInformations(MatchTechnicalInfos matchTechnicalInfos)
 {
     matchTechnicalInfos.Match = await _context.Matchs.FindAsync(matchTechnicalInfos.MatchID);
 }