예제 #1
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,DateOfBirth,IdNumber,Gender,Email,Pais,Address,PhoneNumber,JobTitle,Education,HireDate")] Consultant consultant)
        {
            // Create user
            //var consultantUser = new ApplicationUser {
            //    UserName = UserName,
            //    Email = Email
            //};
            //var CreateConsultantUser = UserManager.Create(consultantUser, Password);

            if (ModelState.IsValid)
            {
                try
                {
                    consultantRepo.InsertConsultant(consultant);
                    consultantRepo.Save();
                    return(RedirectToAction("Index"));
                }

                /*If the record already exists (using ID validation), as per the constraint Unique validation
                 * implemented in the model, the debugger will run to the CATCH where the ViewBag.Message will
                 * display a message to the View.
                 */
                catch (DbUpdateException sqlExc)
                {
                    var sqlException = sqlExc.GetBaseException() as SqlException;
                    if (sqlException != null)
                    {
                        ViewBag.Message = "Record already exists.";
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(RedirectToAction("Index"));
        }