public ActionResult Upload(VerifyModel model, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { try { DirectoryInfo dir = new DirectoryInfo(ServerConfig.SAVE_OLD_GAMES_FOLDER); if (!dir.Exists) dir.Create(); string finalFile = Path.Combine(ServerConfig.SAVE_OLD_GAMES_FOLDER, "CompletedGame" + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + ".xml"); file.SaveAs(finalFile); var game = GameViewModel.deserializeGame(finalFile); if (game != null) { GameServerViewModel.saveGameToDb(game); try { FileInfo f3 = new FileInfo(finalFile); //I want to keep a few uploaded games. //if (f3.Exists) // f3.Delete(); } catch { } return Redirect("~/game/manage/" + game.IdForOnlineManagementUse.ToString().Replace("-", "") + "/" + game.GameId.ToString().Replace("-", "")); } else { model.Message = "No Game was uploaded. Please make sure this file was generated from the RDNation Scoreboard."; model.IsSuccessful = false; return View(model); } } catch (Exception e) { Library.Classes.Error.ErrorDatabaseManager.AddException(e, e.GetType(), ErrorGroupEnum.Database); string filePath = Path.Combine(ServerConfig.SAVE_OLD_GAMES_FOLDER, Path.GetFileName(file.FileName)); DirectoryInfo dir = new DirectoryInfo(ServerConfig.SAVE_OLD_GAMES_FOLDER); if (!dir.Exists) dir.Create(); file.SaveAs(filePath); } } model.Message = "Something happened with the intake of the game. Please try again later."; model.IsSuccessful = false; return View(model); }
public ActionResult Upload() { VerifyModel model = new VerifyModel(); model.IsSuccessful = true; return View(model); }