コード例 #1
0
        public List <ErrorDTO> RegisterUser(UserDTO usr, string imagePath)
        {
            List <ErrorDTO> errorList = null;
            UserDTO         user      = new UserDTO
            {
                EmailId       = usr.EmailId,
                FirstName     = usr.FirstName,
                LastName      = usr.LastName,
                ContactNumber = usr.ContactNumber,
                Country       = usr.Country,
                Password      = usr.Password,
                ImagePath     = imagePath
            };
            ExitTestValidationResult validationResult = Validator <UserValidator, UserDTO> .Validate(user, ruleSet : "User Registration");

            if (validationResult.IsValid)
            {
                //int tweetId = this._usrRepo.AddNewUser(user);
                this._userRepo.RegisterUser(user);
            }
            else
            {
                errorList = new List <ErrorDTO>();
                ErrorDTO errorDTO = null;
                foreach (var item in validationResult.Errors)
                {
                    errorDTO = new ErrorDTO();
                    errorDTO.ErrorMessage = item.ErrorMessage;
                    errorDTO.PropertyName = item.PropertyName;
                    errorList.Add(errorDTO);
                }
            }

            return(errorList);
        }
コード例 #2
0
        /// <summary>
        /// Forward Data From TweetRepo's
        /// AddNewTweet provided Tweet Data
        /// and user who posted
        /// </summary>
        /// <param name="newTweet"></param>
        /// <returns></returns>
        public List <ErrorDTO> AddNewTweet(string content, int userId)
        {
            //manipulations
            List <ErrorDTO> errorList = null;

            List <string> hash = new List <string>();

            for (int i = 0; i < content.Length; i++)
            {
                if (content[i] == '#')
                {
                    string temp = "";
                    int    j;
                    for (j = i + 1; j < content.Length; j++)
                    {
                        if (content[j] == ' ')
                        {
                            break;
                        }
                        temp = temp + content[j];
                    }
                    hash.Add(temp);
                    i = j;
                }
            }

            TweetDTO tweet = new TweetDTO
            {
                Content      = content,
                PostDate     = DateTime.Now,
                UserId       = userId,           //Alert
                LikeCount    = 0,
                DislikeCount = 0,
                UpdateDate   = DateTime.Now
            };
            ExitTestValidationResult validationResult = Validator <TweetValidator, TweetDTO> .Validate(tweet, ruleSet : "Compose Tweet");

            if (validationResult.IsValid)
            {
                int tweetId = this._tweetRepo.AddNewTweet(tweet);
                this._hashRepo.AddNewTweetHash(hash, tweetId);
            }
            else
            {
                errorList = new List <ErrorDTO>();
                ErrorDTO errorDTO = new ErrorDTO();
                foreach (var item in validationResult.Errors)
                {
                    errorDTO.ErrorMessage = item.ErrorMessage;
                    errorDTO.PropertyName = item.PropertyName;
                    errorList.Add(errorDTO);
                }
            }

            return(errorList);
        }
コード例 #3
0
        public LoginDTO Login(string emailId, string password)
        {
            LoginDTO        loginDTO  = new LoginDTO();
            List <ErrorDTO> errorList = null;

            UserDTO usr = new UserDTO
            {
                EmailId  = emailId,
                Password = password
            };
            ExitTestValidationResult validationResult = Validator <UserValidator, UserDTO> .Validate(usr, ruleSet : "User Login");

            if (validationResult.IsValid)
            {
                loginDTO.UserDTO = this._userRepo.Login(emailId, password);
                if (loginDTO.UserDTO == null)
                {
                    errorList = new List <ErrorDTO>();
                    ErrorDTO errorDTO = new ErrorDTO
                    {
                        ErrorMessage = "Email id and password do not match",
                        PropertyName = "Invalid Credentials"
                    };
                    errorList.Add(errorDTO);
                    //loginDTO.ErrorDTOList = errorList;
                }
            }
            else
            {
                errorList = new List <ErrorDTO>();
                ErrorDTO errorDTO = null;
                foreach (var item in validationResult.Errors)
                {
                    errorDTO = new ErrorDTO();
                    errorDTO.ErrorMessage = item.ErrorMessage;
                    errorDTO.PropertyName = item.PropertyName;
                    errorList.Add(errorDTO);
                }
                //loginDTO.ErrorDTOList = errorList;
            }
            loginDTO.ErrorDTOList = errorList;
            return(loginDTO);
        }