Example #1
0
        public async Task<UserProfileDetails> LoginUser(UserProfile req, string IPAddress)
        {
            UserProfileDetails userPro = null;

            try
            {
                var profile = await _reposTohowDev.GetTbProfileByEmail(req.Email);
                if (profile != null)
                {
                    if (Crypter.CheckPassword(req.Password, profile.AspNetUser.PasswordHash))
                    {
                        userPro = profile.ConvertToUserProfile();
                        var session = await _reposTohowDev.GetSessionByProfileId(userPro.ProfileId);
                        if (session != null)
                        {
                            await _reposTohowDev.DeleteSessionAsync(session); //delete the previous session
                        }

                        await _reposTohowDev.CreateNewSession(userPro, IPAddress);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error login user", ex);
            }

            return userPro;
        }
        public async Task<tbProfile> CreateNewUser(UserProfile user)
        {
            tbProfile profile = new tbProfile();

            try
            {
                UserProfileDetails userProfile = new UserProfileDetails();
                userProfile.UserId = Guid.NewGuid();
                userProfile.Email = user.Email;
                userProfile.Password = user.Password;
                userProfile.CreatedTime = DateTime.UtcNow;
                userProfile.IsDeleted = false;
                userProfile.Credits = 0;

                profile = userProfile.ConvertToTbProfile();

                _db.tbProfiles.Add(profile);
                await _db.SaveChangesAsync();
            }
            catch (DataException dex)
            {
                throw new ApplicationException("Data error!", dex);
            }

            return profile;
        }
Example #3
0
        public async Task<UserProfileDetails> CreateNewUserProfile(UserProfile req)
        {
            UserProfileDetails userPro = new UserProfileDetails();

            try
            {
                var user = await _reposTohowDev.CreateNewUser(req);
                userPro = user.ConvertToUserProfile();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error register new user", ex);
            }

            return userPro;
        }