Example #1
0
        public void AddUserProfile(IFormFile file, UserProfileCreateViewModel userProfileViewModel, string userId)
        {
            imageService.UploadImage(file);

            UserProfile userProfile = mapper.Map <UserProfile>(userProfileViewModel);

            userProfile.ImagePath = file.FileName;
            userProfile.AppUserId = userId;
            userProfile.Age       = CalculateAge(userProfileViewModel.Birthday);

            context.UserProfiles.Add(userProfile);
            context.SaveChanges();
        }
        // GET: UserProfiles/Create
        public IActionResult Create()
        {
            var currentUser = User.Identity.Name;

            foreach (UserProfile u in _context.UserProfile)
            {
                if (u.Email == currentUser)
                {
                    return(RedirectToAction(nameof(Index), "Recommendations"));
                }
            }
            UserProfileCreateViewModel userProfileCreateViewModel = new UserProfileCreateViewModel(_context);

            return(View(userProfileCreateViewModel));
        }
Example #3
0
        public IActionResult Create(IFormFile file, UserProfileCreateViewModel userProfileViewModel)        
        {
            if (ModelState.IsValid && file != null)
            {
                string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                userProfileRepository.AddUserProfile(file, userProfileViewModel, userId);

                flashMessage.Confirmation("Profil został utworzony");
                return RedirectToAction(nameof(AdvertController.List), nameof(AdvertController).Replace("Controller", ""));

            }
            else
            {
                if (file == null)
                    ModelState.AddModelError("No image", "Proszę dodać zdjęcie");
                return View(userProfileViewModel);
            }
        }