Exemple #1
0
        public async Task <ResponseService <User> > Register(UserModel userModel)
        {
            try
            {
                _logger.LogInfo(Method.GetCurrentMethod().Name);
                User userExist = await _userRepositoty.GetByEmailAsync(userModel.Email);

                if (userExist != null)
                {
                    return(new ResponseService <User>("This mail is exist in system!"));
                }

                User user = _mapper.Map <UserModel, User>(userModel);
                user.Password  = HashMD5.HashStringMD5(user.Password);
                user.CreatedAt = DateTime.Now;
                user.UpdatedAt = DateTime.Now;
                user.Active    = true;
                var userInfo = await _userRepositoty.AddAsync(user);

                Profile profile = new Profile();
                profile.Status    = Constants.DEFAULT_STATUS_PROFILE;
                profile.UserId    = userInfo.Id;
                profile.CreatedAt = DateTime.Now;
                profile.UpdatedAt = DateTime.Now;
                profile.Active    = true;
                await _profileRepository.AddAsync(profile);

                return(new ResponseService <User>(user));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new ResponseService <User>(ex.Message));
            }
        }
        public async Task <ProfileResponse> SaveAsync(int cityId, int provinceId, Profile profile)
        {
            var existingProvince = await _provinceRepository.FindById(provinceId);

            var existingCity = await _cityRepository.FindById(cityId);

            if (existingProvince == null)
            {
                return(new ProfileResponse("Province not found, a profile needs a province to exist"));
            }
            if (existingCity == null)
            {
                return(new ProfileResponse("City not found, a profile needs a city to exist"));
            }
            if (existingCity.ProvinceId != provinceId)
            {
                return(new ProfileResponse("The City does not belong that province"));
            }
            try
            {
                profile.ProvinceId = provinceId;
                profile.CityId     = cityId;
                await _profileRepository.AddAsync(profile);

                await _unitOfWork.CompleteAsync();

                return(new ProfileResponse(profile));
            }
            catch (Exception ex)
            {
                return(new ProfileResponse($"An error ocurred while saving profile: {ex.Message}"));
            }
        }
        public async Task <IActionResult> Post([FromBody] dynamic data)
        {
            try
            {
                TestUserProfile profileToReturn = await _profileRepository.GetProfileByEmailAsync(data.email);

                return(Ok(profileToReturn));
            }
            catch
            {
                try
                {
                    TestUserProfile userProfileToAdd = new TestUserProfile();
                    userProfileToAdd.Name         = data.name;
                    userProfileToAdd.UserEmail    = data.email;
                    userProfileToAdd.UserPassword = data.password;
                    await _profileRepository.AddAsync(userProfileToAdd);

                    TestUserProfile profileToReturn = await _profileRepository.GetProfileByEmailAsync(userProfileToAdd.UserEmail);

                    await _rankingRepository.CreateListOfPlayerRanksByProfileId(profileToReturn.TestUserProfileId, _playerRepository, _rankingRepository);

                    return(Ok(profileToReturn));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Exemple #4
0
        public async Task <ProfileResponse> SaveAsync(Profile profile)
        {
            try
            {
                await _profileRepository.AddAsync(profile);

                await _unitOfWork.CompleteAsync();

                return(new ProfileResponse(profile));
            }
            catch (Exception ex)
            {
                return(new ProfileResponse($"An error ocurred while saving the profile: {ex.Message}"));
            }
        }
        public async Task <IResult <long> > AddAsync(ProfileModel model)
        {
            var validation = await new AddProfileModelValidator().ValidateAsync(model);

            if (validation.Failed)
            {
                return(Result <long> .Fail(validation.Message));
            }
            var user = await _userRepository.GetAsync(model.UserId);

            var profile = ProfileFactory.CreateProfile(model, user);
            await _profileRepository.AddAsync(profile);

            await _unitOfWork.SaveChangesAsync();

            return(Result <long> .Success(profile.Id));
        }
Exemple #6
0
        public async Task <ActionResult <UserDto> > Register(RegisterDto registerDto)
        {
            if (CheckEmailExistsAsync(registerDto.Email).Result.Value)
            {
                return(new BadRequestObjectResult(new ApiValidationErrorResponse {
                    Errors = new[] { "Email address is in use" }
                }));
            }

            var user = new AppUser
            {
                Email    = registerDto.Email,
                UserName = registerDto.Email
            };

            var profile = new Profile
            {
                UserEmail    = registerDto.Email,
                ContactEmail = registerDto.ContactEmail,
                Description  = registerDto.Description,
                // Birthday = registerDto.Birthday,
                FirstName = registerDto.FirstName,
                LastName  = registerDto.LastName,
                Phone     = registerDto.Phone,
                Location  = registerDto.Location
            };

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

            await _profileRepository.AddAsync(profile);

            if (!result.Succeeded)
            {
                return(BadRequest(new ApiResponse(400)));
            }

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

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

                if (_userManager.Options.SignIn.RequireConfirmedAccount)
                {
                    return(new UserDto
                    {
                        ConfirmEmail = true
                    });
                }
                else
                {
                    return(new UserDto
                    {
                        Token = _tokenService.CreateToken(user),
                        Email = user.Email
                    });
                }
            }

            return(null);
        }
 public async Task <Profile> AddProfileAsync(Profile newProfile)
 {
     return(await _profileRepository.AddAsync(newProfile));
 }