Ejemplo n.º 1
0
        public ActionResult ImportJSONGameData(ImportJSONGameDataModel model, int games)
        {
            model = PrepareImportJSONGameData(model);

            try
            {
                // Verify that the user selected a file
                if (model.file != null && model.file.ContentLength > 0)
                {
                    // extract only the filename
                    var fileName = Path.GetFileName(model.file.FileName);
                    // store the file inside ~/App_Data/uploads folder
                    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                    model.file.SaveAs(path);

                    if(model.importJSON)
                        ImportJSONGameDataFile(path, games);
                    else
                        ImportCSVGameDataFile(path, games);
                }

                model.Status = "Import Succeeded!";
            }
            catch (Exception ex)
            {
                model.Status = ex.Message + " " + ex.StackTrace;
            }

            return View(model);
        }
Ejemplo n.º 2
0
        private ImportJSONGameDataModel PrepareImportJSONGameData(ImportJSONGameDataModel model)
        {
            if(model == null)
                model = new ImportJSONGameDataModel();

            using (BalboaConstrictorsEntities entity = new BalboaConstrictorsEntities())
            {
                model.games = entity.Games.ToList();

                foreach (var p in model.games)
                {
                    model.gameSelect.Add(new SelectListItem()
                    {
                        Text = String.Join(" vs. ", p.GameTeams.Select(gt => gt.Team.TeamName).ToArray()) + " @ " + p.BeginTime.ToString("F"),
                        Value = p.Id.ToString()
                    });
                }
            }

            return model;
        }
Ejemplo n.º 3
0
        public ActionResult ImportJSONGameData()
        {
            ImportJSONGameDataModel model = new ImportJSONGameDataModel();

            model = PrepareImportJSONGameData(model);

            return View(model);
        }