Esempio n. 1
0
        public ActionResult Edit(String name, HttpPostedFileBase file, String position, DateTime dateOfBirth, String clubName)
        {
            Coach coach = null;

            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    var    fileName = Path.GetFileName(file.FileName);
                    String path     = Path.Combine(Server.MapPath("~/images"), fileName);
                    file.SaveAs(path);

                    String pathInXML = "/images/" + file.FileName;

                    coach = new Coach(name, pathInXML, position, dateOfBirth, clubName);

                    _repository.EditCoach(coach);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    coach = new Coach(name, position, dateOfBirth, clubName);

                    _repository.EditCoach(coach);
                    return(RedirectToAction("Index"));
                }
            }
            return(View(coach));
        }
Esempio n. 2
0
        public ActionResult Edit(Coach coach)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _repository.EditCoach(coach);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    //error msg for failed edit in XML file
                    ModelState.AddModelError("", "Error editing record. " + ex.Message);
                }
            }

            return(View(coach));
        }