コード例 #1
0
 public SignUpInViewModel(IList<Navigation.BreadcrumbNavItem> breadcrumb, IEnumerable<SelectListItem> stateListing, SignUpEnteredData signupModel)
 {
     Breadcrumb = breadcrumb;
     StateListing = stateListing;
     SelectedState = string.Empty;
     SignUpUserEntered = signupModel;
 }
コード例 #2
0
        public async Task<IActionResult> SignUp(SignUpEnteredData model, IFormFile UserProfilePicture)
        {
            //do we have a valid model?
            if (ModelState.IsValid)
            {
                UserAccounts userRegisterAttempt = null;

                try
                {
                    //let's try to add this user to the system
                    userRegisterAttempt = await SecurityDataProvider.RegisterUser(DbContext, model);

                    //successful. go add the image if they have one
                    if (UserProfilePicture != null)
                    {
                        var tryToGetFileExtension = UserProfilePicture.ContentType.Split('/')[1];

                        await UserProfilePicture.SaveAsAsync(Path.Combine(Configuration.Value.UserImageSavePath, userRegisterAttempt.UserId.ToString() + "." + tryToGetFileExtension));

                        //go invalidate the user cache
                        CacheFactory.RemoveCacheItem(CacheKeyNames.UserImageFinder, Cache);
                    }
                }
                catch (Exception ex)
                {
                    var sqlException = ToracLibrary.Core.Exceptions.ExceptionUtilities.RetrieveExceptionType<SqlException>(ex);

                    //do we have a sql exception/* PK/UKC violation */
                    if (sqlException != null && sqlException.Errors.OfType<SqlError>().Any(x => x.Number == UniqueConstraintId))
                    {
                        // it's a dupe... do something about it
                        ModelState.AddModelError(string.Empty, "E-mail address is already registered.");
                    }
                    else
                    {
                        // it's something else...
                        throw;
                    }
                }

                //did we find a user?
                if (userRegisterAttempt != null)
                {
                    //go log the user in
                    await LogUserIn(userRegisterAttempt);

                    //go send them to the main page
                    return RedirectToAction("Index", "Home");
                }

                //if we don't have a duplicate email error, then just add a generic register error
                if (ModelState.ErrorCount == 0)
                {
                    //can't find the user, add an error
                    ModelState.AddModelError(string.Empty, "Invalid register attempt.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(new SignUpInViewModel(BuildSignUpBreadcrumb(),
                                             CacheFactory.GetCacheItem<IEnumerable<SelectListItem>>(CacheKeyNames.StateListing, Cache),
                                             model));
        }