/// <summary>
        /// NewUserRegistration
        /// </summary>
        /// <param name="user"></param>
        public async Task <string> NewUserRegistration(CogniTweetsUser user)
        {
            try
            {
                string message  = string.Empty;
                var    validate = await this._cogniTweetsRepository.ValidateEmailId(user.EmailId);

                if (validate == null)
                {
                    user.Password = this.EncryptPassword(user.Password);
                    var result = await this._cogniTweetsRepository.NewUserRegistration(user);

                    if (result > 0)
                    {
                        message = "Successfully registerd";
                    }
                    else
                    {
                        message = "Registration failed";
                    }
                }
                else
                {
                    message = "EmailId is already used";
                }

                return(message);
            }
            catch (Exception ex)
            {
                this._logger.LogError(ex, $"Error occured while retrieving all tweets");
                throw;
            }
        }
        /// <summary>
        /// NewUserRegistration
        /// </summary>
        /// <param name="users"></param>
        /// <returns>int</returns>
        public async Task <int> NewUserRegistration(CogniTweetsUser newUser)
        {
            _dbcontext.Users.Add(newUser);
            var result = await _dbcontext.SaveChangesAsync();

            return(result);
        }
        /// <summary>
        /// Login
        /// </summary>
        /// <param name="emailId"></param>
        /// <param name="password"></param>
        /// <returns>either true or false</returns>
        public async Task <bool> Login(string emailId, string password)
        {
            CogniTweetsUser user = await _dbcontext.Users.SingleOrDefaultAsync(e => e.EmailId == emailId && e.Password == password);

            if (user != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Register([FromBody] CogniTweetsUser user)
        {
            try
            {
                var result = await this._cogniTweetstBusiness.NewUserRegistration(user);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                this._logger.LogError(ex, $"Error occured while registering user");
                throw;
            }
        }