コード例 #1
0
        public async Task <UserLoginResponse> ReVerifySignUp(SignUpRequestModel ObjSignUpRequestModel)
        {
            UserLoginResponse ObjUserLoginResponse = new UserLoginResponse();

            try
            {
                using (RCS_dbContext context = new RCS_dbContext())
                {
                    UserLogin userLogin = await context.UserLogins.FirstOrDefaultAsync(x => x.UserName.ToUpper().Equals(ObjSignUpRequestModel.UserName.ToUpper()));

                    if (userLogin != null)
                    {
                        userLogin.Status = UserLoginStatus.Verified;
                        if (userLogin.Id > 0)
                        {
                            UserOtp userOtp = await context.UserOtps.FirstOrDefaultAsync(x => x.UserLoginId == userLogin.Id && x.IsExpired == false);

                            if (userOtp != null)
                            {
                                //string OTP = Guid.NewGuid().ToString("n").Substring(0, 8) + "@DCL";
                                UserOtp _userOtp = new UserOtp();
                                userOtp.IsExpired = true;

                                userLogin.Password = GlobalProperties.RandomOTP;
                                //Add new UserOtp
                                _userOtp.UserLoginId        = userLogin.Id;
                                _userOtp.Otp                = userLogin.Password;
                                _userOtp.IsExpired          = false;
                                _userOtp.CreatedByIpaddress = ObjSignUpRequestModel.ActionByIPAddress;
                                _userOtp.CreatedBy          = ObjSignUpRequestModel.ActionByUserID;
                                var UserOTP_EntityEntry = await context.AddAsync(_userOtp);

                                int Response = await context.SaveChangesAsync();

                                if (Response > 0)
                                {
                                    MailOperations mailOperations = new MailOperations();
                                    string         name           = userLogin.FirstName + " " + userLogin.LastName.ToUpper();
                                    if (mailOperations.SendSignUpEmail(new System.Net.Mail.MailAddress(userLogin.UserName, name), _userOtp.Otp))
                                    {
                                        ObjUserLoginResponse.ResponseCode = ResponseCode.Success;
                                    }
                                }
                                else
                                {
                                    ObjUserLoginResponse.ResponseCode = ResponseCode.Inserted;
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ObjUserLoginResponse.ResponseCode = ResponseCode.Exception;
                ObjUserLoginResponse.Exception    = ex;
            }
            return(ObjUserLoginResponse);
        }
コード例 #2
0
        public async Task <UserLoginResponse> SignUp(SignUpRequestModel ObjSignUpRequestModel)
        {
            UserLoginResponse ObjUserLoginResponse = new UserLoginResponse();

            try
            {
                using (RCS_dbContext context = new RCS_dbContext())
                {
                    UserLogin userLogin = new UserLogin();
                    userLogin.UserName           = ObjSignUpRequestModel.UserName;
                    userLogin.Password           = GlobalProperties.RandomOTP;
                    userLogin.FirstName          = ObjSignUpRequestModel.FirstName;
                    userLogin.LastName           = ObjSignUpRequestModel.LastName;
                    userLogin.Mobile             = ObjSignUpRequestModel.Mobile;
                    userLogin.Type               = ObjSignUpRequestModel.Type;
                    userLogin.CreatedByIpaddress = ObjSignUpRequestModel.ActionByIPAddress;
                    userLogin.CreatedBy          = ObjSignUpRequestModel.ActionByUserID;

                    var UserLogins_EntityEntry = await context.UserLogins.AddAsync(userLogin);

                    int UserLogins_Response = await context.SaveChangesAsync();

                    if (UserLogins_Response > 0)
                    {
                        ObjUserLoginResponse.UserLogin = await context.UserLogins.AsNoTracking().FirstOrDefaultAsync(a => a.Id == userLogin.Id);

                        UserOtp userOtp = new UserOtp();
                        userOtp.UserLoginId        = ObjUserLoginResponse.UserLogin.Id;
                        userOtp.Otp                = userLogin.Password;
                        userOtp.CreatedByIpaddress = ObjSignUpRequestModel.ActionByIPAddress;
                        userOtp.CreatedBy          = ObjSignUpRequestModel.ActionByUserID;

                        var UserOTP_EntityEntry = await context.AddAsync(userOtp);

                        int UserOTP_Response = await context.SaveChangesAsync();

                        if (UserOTP_Response > 0)
                        {
                            ObjUserLoginResponse.ResponseCode = ResponseCode.Inserted;
                            MailOperations mailOperations = new MailOperations();
                            string         name           = userLogin.FirstName + " " + userLogin.LastName.ToUpper();
                            if (mailOperations.SendSignUpEmail(new System.Net.Mail.MailAddress(userLogin.UserName, name), userOtp.Otp))
                            {
                                ObjUserLoginResponse.ResponseCode = ResponseCode.Success;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ObjUserLoginResponse.ResponseCode = ResponseCode.Exception;
                ObjUserLoginResponse.Exception    = ex;
            }
            return(ObjUserLoginResponse);
        }