public ActionResult Create(Team team)
        {
            if (ModelState.IsValid)
            {
                int id = db.TeamSet.OrderByDescending(e => e.Id).Select(e => e.Id).FirstOrDefault() + 1;

                string folder = Path.Combine(Server.MapPath("~/Images/Teams"), id.ToString());
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                //TeamImage
                ManageTeamImage(folder);

                //DriverImage
                ManageDriverImage(folder);

                //CoDriverImage
                ManageCoDriverImage(folder);

                team.TeamImageUrl = "~/Images/Teams/" + id.ToString() + "/team";
                team.DriverImageUrl = "~/Images/Teams/" + id.ToString() + "/driver";
                team.CoDriverImageUrl = "~/Images/Teams/" + id.ToString() + "/coDriver";

                db.TeamSet.Add(team);
                db.SaveChanges();

                DeleteTempFiles();
                SendMessage(MessageType.Success, "The team successfully created!");
                return RedirectToAction("Index");
            }

            SendMessage(MessageType.Error, "Something went wrong! :( Try it again");
            return View(team);
        }
        public ActionResult Create(Team team)
        {
            if (ModelState.IsValid)
            {
                int id;
                try
                {
                    id = db.TeamSet.OrderByDescending(e => e.Id).Select(e => e.Id).First() + 1;
                }
                catch (Exception)
                {
                    id = 0;
                }

                string folder = Path.Combine(Server.MapPath("~/Images/Teams"), id.ToString());
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                //TeamImage
                {
                    string tempTeamImage = Path.Combine(Server.MapPath("~/Images"), "tempTeam");
                    string teamImage = Path.Combine(folder, "team");
                    if (!System.IO.File.Exists(tempTeamImage))
                        tempTeamImage = Path.Combine(Server.MapPath("~/Images"), "no_image.jpg");
                    if (System.IO.File.Exists(teamImage))
                        System.IO.File.Delete(teamImage);
                    System.IO.File.Copy(tempTeamImage, teamImage);
                }

                //DriverImage
                {
                    string tempDriverImage = Path.Combine(Server.MapPath("~/Images"), "tempDriver");
                    string driverImage = Path.Combine(folder, "driver");
                    if (!System.IO.File.Exists(tempDriverImage))
                        tempDriverImage = Path.Combine(Server.MapPath("~/Images"), "no_image.jpg");
                    if (System.IO.File.Exists(driverImage))
                        System.IO.File.Delete(driverImage);
                    System.IO.File.Copy(tempDriverImage, driverImage);
                }

                //CoDriverImage
                {
                    string tempCoDriverImage = Path.Combine(Server.MapPath("~/Images"), "tempCoDriver");
                    string coDriverImage = Path.Combine(folder, "coDriver");
                    if (!System.IO.File.Exists(tempCoDriverImage))
                        tempCoDriverImage = Path.Combine(Server.MapPath("~/Images"), "no_image.jpg");
                    if (System.IO.File.Exists(coDriverImage))
                        System.IO.File.Delete(coDriverImage);
                    System.IO.File.Copy(tempCoDriverImage, coDriverImage);
                }

                team.TeamImageUrl = "~/Images/Teams/" + id.ToString() + "/team";
                team.DriverImageUrl = "~/Images/Teams/" + id.ToString() + "/driver";
                team.CoDriverImageUrl = "~/Images/Teams/" + id.ToString() + "/coDriver";

                db.TeamSet.Add(team);
                db.SaveChanges();

                DeleteTempFiles();
                SendMessage(MessageType.Success, "The team successfully created!");
                return RedirectToAction("Index");
            }

            SendMessage(MessageType.Error, "Something went wrong! :( Try it again");
            return View(team);
        }
        public ActionResult Edit(Team team)
        {
            if (ModelState.IsValid)
            {
                int id = team.Id;

                string folder = Path.Combine(Server.MapPath("~/Images/Teams"), id.ToString());
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                //TeamImage
                {
                    string tempTeamImage = Path.Combine(Server.MapPath("~/Images"), "tempTeam");
                    string teamImage = Path.Combine(folder, "team");
                    if (System.IO.File.Exists(tempTeamImage))
                    {
                        if (System.IO.File.Exists(teamImage))
                            System.IO.File.Delete(teamImage);
                        System.IO.File.Move(tempTeamImage, teamImage);
                    }
                }

                //DriverImage
                {
                    string tempDriverImage = Path.Combine(Server.MapPath("~/Images"), "tempDriver");
                    string driverImage = Path.Combine(folder, "driver");
                    if (System.IO.File.Exists(tempDriverImage))
                    {
                        if (System.IO.File.Exists(driverImage))
                            System.IO.File.Delete(driverImage);
                        System.IO.File.Move(tempDriverImage, driverImage);
                    }
                }

                //CoDriverImage
                {
                    string tempCoDriverImage = Path.Combine(Server.MapPath("~/Images"), "tempCoDriver");
                    string coDriverImage = Path.Combine(folder, "coDriver");
                    if (System.IO.File.Exists(tempCoDriverImage))
                    {
                        if (System.IO.File.Exists(coDriverImage))
                            System.IO.File.Delete(coDriverImage);
                        System.IO.File.Move(tempCoDriverImage, coDriverImage);
                    }
                }

                db.Entry(team).State = EntityState.Modified;
                db.SaveChanges();

                DeleteTempFiles();
                SendMessage(MessageType.Success, "The team successfully modified!");
                return RedirectToAction("Index");
            }
            SendMessage(MessageType.Error, "Something went wrong! :( Try it again");
            return View(team);
        }
        public ActionResult Edit(Team team)
        {
            if (ModelState.IsValid)
            {
                int id = team.Id;

                string folder = Path.Combine(Server.MapPath("~/Images/Teams"), id.ToString());
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                //TeamImage
                OverwriteTeamImage(folder);

                //DriverImage
                OverwriteDriverImage(folder);

                //CoDriverImage
                OverwriteCoDriverImage(folder);

                db.Entry(team).State = EntityState.Modified;
                db.SaveChanges();

                DeleteTempFiles();
                SendMessage(MessageType.Success, "The team successfully modified!");
                return RedirectToAction("Index");
            }
            SendMessage(MessageType.Error, "Something went wrong! :( Try it again");
            return View(team);
        }