Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Label")] Modset modset, IFormFile data)
        {
            await _service.ParseArma3Modset(modset, data);

            if (ModelState.IsValid)
            {
                modset.GameType    = GameServerType.Arma3;
                modset.AccessToken = GameServerService.GenerateToken();
                modset.Label       = modset.Label ?? modset.Name;
                _context.Add(modset);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(modset));
        }
        private async Task HandleFiles(GameServerConfiguration gsc, IFormFile modsetFile, IFormFile missionFile)
        {
            if (missionFile != null)
            {
                gsc.ServerMission = _service.UploadMissionFile(missionFile, gsc.GameServer);
            }

            if (modsetFile != null)
            {
                var modset = new Modset();
                var errors = await _service.ParseArma3Modset(modset, modsetFile);

                if (!string.IsNullOrEmpty(errors))
                {
                    ModelState.AddModelError("ModsetID", errors);
                    return;
                }
                await GetOrCreateModset(gsc, modset);
            }

            if (gsc.ModsetID != null)
            {
                var actualModset = await _context.Modsets.FindAsync(gsc.ModsetID.Value);

                var errors = _service.ValidateModsetOnServer(actualModset, gsc.GameServer);
                if (!string.IsNullOrEmpty(errors))
                {
                    ModelState.AddModelError("ModsetID", errors);
                    return;
                }
            }
        }