예제 #1
0
        public ActionResult Add(AttendeeEditModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Agencies = _agencyService.GetAgencies(1, 50);
                return(View(model));
            }

            // Ensure attendee doesn't already exist
            if (_attendeeService.Exists(model.FirstName, model.LastName, model.MiddleName))
            {
                ModelState.AddModelError("", "An attendee with that name already exists.");
                model.Agencies = _agencyService.GetAgencies(1, 50);
                return(View(model));
            }

            // Add attendee to db
            _attendeeService.Add(model, User.Identity.Name);

            return(RedirectToAction(nameof(Index)));
        }