public IActionResult Create() { VM_Game Model = new VM_Game(); Model.FilePath = GlobalConfig.getKeyValue("DeployPathRoot"); return(View(Model)); }
public IActionResult Create(VM_Game Model) { //on invalid model just kick back to form if (!ModelState.IsValid) { return(View(Model)); } try { //map our game vModel to Game Model (for JSON serialization) Game GameData = new Game(); GameData.FilePath = Model.FilePath; GameData.Name = Model.Name; if (Model.UploadedZipFile != null) { //copy uploaded file to temp zip file location string FileName_Temp = GlobalConfig.getKeyValue("ZIPDumpsPath") + Guid.NewGuid().ToString() + ".zip"; FileStream fs = new FileStream(FileName_Temp, FileMode.Create); Model.UploadedZipFile.CopyTo(fs); fs.Close(); //extract temp file on target ZipFile.ExtractToDirectory(FileName_Temp, Model.FilePath); //cleanup the temp zip file System.IO.File.Delete(FileName_Temp); } //save the new game to our json file var modified_game_list = dm.LoadGameList(); modified_game_list.Add(GameData); dm.SaveGameList(modified_game_list); return(RedirectToAction("Index")); } catch (Exception ex) { //todo: cleanup this logging process ViewData["ServerMessage"] = ex.Message; } return(View(Model)); }