Exemplo n.º 1
0
        public async Task <IActionResult> Edit(EditProfileInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            if (input.Name == null)
            {
                input.Name = this.profilesService.GetName(input.Id);
            }

            var user = await this.userManager.GetUserAsync(this.User);

            if (input.Images != null)
            {
                var result = await CloudinaryExtentsion.UploadAsync(this.cloudinary, input.Images);

                await this.profilesService.UpdateAsync(input.Id, input, user.Id, result);
            }

            await this.profilesService.UpdateAsync(input.Id, input, user.Id);

            return(this.Redirect($"/Profiles/Index?petId={input.Id}"));
        }
        public async Task <IActionResult> Create(CreateCourseInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var resultUrl = await CloudinaryExtentsion.UploadAsync(this.cloudinary, inputModel.Thumbnail);

            var url         = resultUrl;
            var userId      = this.userManager.GetUserId(this.User);
            var newCourseId = await this.coursesService.AddCourseAsync(inputModel, url, userId);

            return(this.Redirect($"/Courses/GetCourse/{newCourseId}"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Add(AddPetInputModel input, int specieId)
        {
            if (!this.ModelState.IsValid)
            {
                input.Breeds = this.breedsService.GetAllAsKeyValuePairs(specieId);
                input.Cities = this.citiesService.GetAllAsKeyValuePairs();
                return(this.View(input));
            }

            ApplicationUser user = await this.userManager.GetUserAsync(this.User);

            var result = await CloudinaryExtentsion.UploadAsync(this.cloudinary, input.Images);

            await this.petsService.AddAsync(input, specieId, user.Id, result);

            return(this.Redirect($"/Users/MyPets?addedByUserId={user.Id}"));
        }
        public async Task <IActionResult> Add(CreateProductViewModelImages input)
        {
            if (!this.ModelState.IsValid)
            {
                input.CategoriesItems = this._categoriesService.GetAllAsKeyValuePairs();

                return(this.View(input));
            }

            var imageResult = await CloudinaryExtentsion.UploadAsync(this.cloudinary, input.Images);

            var user = await this._userManager.GetUserAsync(this.User);

            await this._productService.CreateAsync(input, imageResult, user.Id);

            return(this.RedirectToAction("Add"));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl           = returnUrl ?? this.Url.Content("~/");
            this.ExternalLogins = (await this._signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (this.ModelState.IsValid)
            {
                var profilePicture = new ProfilePicture {
                    Url = DefaultProfilePicturePath
                };
                if (this.Input.ProfilePicture != null)
                {
                    var resultUrl = await CloudinaryExtentsion.UploadAsync(this.cloudinary, this.Input.ProfilePicture);

                    profilePicture.Url = resultUrl;
                }

                var user = new ApplicationUser
                {
                    UserName       = this.Input.Email,
                    Email          = this.Input.Email,
                    FirstName      = this.Input.FirstName,
                    LastName       = this.Input.LastName,
                    BirthDate      = this.Input.BirthDate,
                    Gender         = this.Input.Gender,
                    UserType       = this.Input.UserType,
                    ProfilePicture = profilePicture,
                };
                if (user.UserType == UserTypeEnum.Lecturer)
                {
                    user.Lecturer = new Lecturer {
                        UserId = user.Id
                    };
                }
                else if (user.UserType == UserTypeEnum.Student)
                {
                    user.Student = new Student {
                        UserId = user.Id
                    };
                }

                var result = await this._userManager.CreateAsync(user, this.Input.Password);

                if (result.Succeeded)
                {
                    switch (user.UserType)
                    {
                    case UserTypeEnum.Lecturer:
                        await this._userManager.AddToRoleAsync(user, LecturerRoleName);

                        break;

                    default:
                        await this._userManager.AddToRoleAsync(user, StudentRoleName);

                        break;
                    }

                    this._logger.LogInformation("User created a new account with password.");

                    var code = await this._userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = this.Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: this.Request.Scheme);

                    await this._emailSender.SendEmailAsync(this.Input.Email, "Confirm your email",
                                                           $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (this._userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(this.RedirectToPage("RegisterConfirmation", new { email = this.Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await this._signInManager.SignInAsync(user, isPersistent : false);

                        return(this.LocalRedirect(returnUrl));
                    }
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.Page());
        }