コード例 #1
0
        public async Task <IActionResult> CreateProfile(CreateProfileInputModel inputModel)
        {
            var userId = this.userManager.GetUserId(this.User);

            // TODO: To edit error messagies in the ViewModel;
            if (!this.ModelState.IsValid)
            {
                inputModel.PhotoUrl = this.usersService.GetUserById <CreateProfileInputModel>(userId).PhotoUrl;

                var allCategories = new AllCategoriesViewModel
                {
                    Categories = this.categoriesService.GetAll <CategoryListViewModel>(),
                };

                inputModel.AllCategories = allCategories;

                return(this.View(inputModel));
            }

            if (inputModel.NewPhoto != null)
            {
                inputModel.PhotoUrl = await this.cloudinaryService.UploadPhotoAsync(inputModel.NewPhoto, "User", "Users");
            }

            await this.usersService.CreateAProfileAsync(userId, inputModel.UserName, inputModel.PhotoUrl, inputModel.Email, inputModel.Summary, inputModel.PhoneNumber);

            await this.categoryUsersServices.CreateAsync(userId, inputModel.CategoriesId);

            return(this.RedirectToAction(nameof(this.Profile), new { id = userId }));
        }
コード例 #2
0
        public async Task <ActionResult> Create(CreateProfileInputModel inputModel)
        {
            var profile = new Profile
            {
                UserId          = inputModel.UserId,
                Username        = inputModel.Username,
                Description     = inputModel.Description,
                Image           = inputModel.Image,
                BirthDate       = inputModel.BirthDate,
                ProfileTrophies = new List <ProfileTrophy>(),
            };

            await this.profiles.Save(profile);

            return(this.Ok());
        }