public ActionResult Create(Coach coach)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _repository.InsertCoach(coach);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    //error msg for failed insert in XML file
                    ModelState.AddModelError("", "Error creating record. " + ex.Message);
                }
            }

            return(View(coach));
        }
Beispiel #2
0
        //public ActionResult Create([Bind(Include = "name, imageLink, position, dateOfBirth, clubName")] Coach coach)
        public ActionResult Create(String name, HttpPostedFileBase file, String position, DateTime dateOfBirth, String clubName)
        {
            Coach coach = null;

            if (ModelState.IsValid)
            {
                if (file.ContentLength > 0)
                {
                    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.InsertCoach(coach);
                    return(RedirectToAction("Index"));
                }
            }

            return(View(coach));
        }
        public ServiceResponse <Coach> AddCoach(Coach coach)
        {
            var response = TryExecute(() =>
            {
                var newCoach = _coachRepository.InsertCoach(coach);

                return(ServiceResponse <Coach> .Success(newCoach));
            });

            if (!response.IsSuccess)
            {
                return(response);
            }

            var sendEventResponse = SendEvent(TrackingLogEventType.CoachAdded, response.ResponseDTO.Id, true);

            if (!sendEventResponse.IsSuccess)
            {
                return(sendEventResponse.AsGenericResponse <Coach>());
            }

            return(response);
        }