Esempio n. 1
0
        public async Task FileAllowedExtensionsAttributeShuldReturnTrueIfFileExtensionIsInAllowed()
        {
            IFormFile file   = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("dummy image")), 0, 10, "Data", "fake.jpg");
            var       result = await FormFileExtensions.GetBytesAsync(file);

            Assert.NotEmpty(result);
            Assert.Equal(10, result.Length);
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await this.userManager.GetUserAsync(this.User);

            if (user == null)
            {
                return(this.NotFound($"{UnableToLoadUser} '{this.userManager.GetUserId(this.User)}'."));
            }

            if (!this.ModelState.IsValid)
            {
                await this.LoadAsync(user);

                return(this.Page());
            }

            var phoneNumber = await this.userManager.GetPhoneNumberAsync(user);

            if (this.Input.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await this.userManager.SetPhoneNumberAsync(user, this.Input.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    this.StatusMessage = PhoneError;
                    return(this.RedirectToPage());
                }
            }

            var firstName    = user.FirstName;
            var lastName     = user.LastName;
            var education    = user.Education;
            var companyName  = user.CompanyName;
            var interests    = user.Interest;
            var contacts     = user.Contact;
            var websiteUrl   = user.WebsiteUrl;
            var githubUrl    = user.GithubUrl;
            var facebookUrl  = user.FacebookUrl;
            var instagramUrl = user.InstagramUrl;

            if (this.Input.FirstName != firstName)
            {
                user.FirstName = this.Input.FirstName;
            }

            if (this.Input.LastName != lastName)
            {
                user.LastName = this.Input.LastName;
            }

            if (this.Input.Education != education)
            {
                user.Education = this.Input.Education;
            }

            if (this.Input.ComponyName != companyName)
            {
                user.CompanyName = this.Input.ComponyName;
            }

            if (this.Input.Interest != interests)
            {
                user.Interest = this.Input.Interest;
            }

            if (this.Input.Contact != contacts)
            {
                user.Contact = this.Input.Contact;
            }

            if (this.Input.WebsiteUrl != websiteUrl)
            {
                user.WebsiteUrl = this.Input.WebsiteUrl;
            }

            if (this.Input.GithubUrl != githubUrl)
            {
                user.GithubUrl = this.Input.GithubUrl;
            }

            if (this.Input.FacebookUrl != facebookUrl)
            {
                user.FacebookUrl = this.Input.FacebookUrl;
            }

            if (this.Input.InstagramUrl != instagramUrl)
            {
                user.InstagramUrl = this.Input.InstagramUrl;
            }

            if (this.Input.UploadPicture != null)
            {
                string picturePath = $"{this.environment.WebRootPath}{ProfilePicturePath}";

                await this.profileServices.SetProfilePictureAsync(
                    user.Id,
                    await FormFileExtensions.GetBytesAsync(this.Input.UploadPicture),
                    Path.GetExtension(this.Input.UploadPicture.FileName),
                    picturePath);
            }

            await this.userManager.UpdateAsync(user);

            await this.signInManager.RefreshSignInAsync(user);

            this.StatusMessage = UpdatedSuccessfully;

            return(this.RedirectToPage());
        }