Exemple #1
0
        public ActionResult CSV(HttpPostedFileBase postedfile)
        {
            ST.Restart();
            string FilePath;

            if (postedfile != null)
            {
                string Path = Server.MapPath("~/Subidas/");
                if (!Directory.Exists(Path))
                {
                    Directory.CreateDirectory(Path);
                }
                FilePath = Path + System.IO.Path.GetFileName(postedfile.FileName);
                postedfile.SaveAs(FilePath);
                string csvData = System.IO.File.ReadAllText(FilePath);
                foreach (string row in csvData.Split('\n'))
                {
                    if (!string.IsNullOrEmpty(row))
                    {
                        try
                        {
                            var player = new PlayerModel
                            {
                                Name     = row.Split(',')[2],
                                LastName = row.Split(',')[1],
                                Club     = row.Split(',')[0],
                                Position = row.Split(',')[3],
                                Salary   = Convert.ToInt32(Convert.ToDouble(row.Split(',')[4])),
                            };
                            PlayerModel.C_Save(player);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            PlayerModel.Log(Convert.ToString(ST.ElapsedTicks), "Importación de datos a lista artesanal desde un CSV.");
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult Create(FormCollection collection)
        {
            // TODO: Add insert logic here
            ST.Restart();
            try
            {
                var player = new PlayerModel
                {
                    Name     = collection["Name"],
                    LastName = collection["LastName"],
                    Club     = collection["Club"],
                    Position = collection["Position"],
                    Salary   = int.Parse(collection["Salary"]),
                };

                PlayerModel.C_Save(player);
                PlayerModel.Log(Convert.ToString(ST.ElapsedTicks), "Creación manual de jugador.");
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }