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);
        }
        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);
        }
        public async Task <UserLoginResponse> VerifySignUp(string OTP, string EmailAddress)
        {
            UserLoginResponse ObjUserLoginResponse = new UserLoginResponse();

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

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

                            if (userOtp != null)
                            {
                                userOtp.IsExpired = true;
                                context.SaveChanges();

                                if (userOtp.CreatedDateTime > DateTime.Now.AddMinutes(int.Parse("-" + GlobalProperties.OTPExpiryMinutes)))
                                {
                                    userLogin.Status = UserLoginStatus.ApprovalInProcess;
                                    ObjUserLoginResponse.UserLogin = userLogin;

                                    MailOperations mailOperations = new MailOperations();
                                    string         name           = userLogin.FirstName + " " + userLogin.LastName.ToUpper();
                                    if (mailOperations.SendVerificationEmail(new System.Net.Mail.MailAddress(userLogin.UserName, name), userOtp.Otp))
                                    {
                                        ObjUserLoginResponse.ResponseCode = ResponseCode.Success;
                                    }
                                }
                                else
                                {
                                    ObjUserLoginResponse.ResponseCode = ResponseCode.Expired;
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ObjUserLoginResponse.ResponseCode = ResponseCode.Exception;
                ObjUserLoginResponse.Exception    = ex;
            }
            return(ObjUserLoginResponse);
        }
        public async Task <UserLoginResponse> UserInsert(UserLogin userLogin)
        {
            UserLoginResponse ObjUserLoginResponse = new UserLoginResponse();

            try
            {
                using (RCS_dbContext context = new RCS_dbContext())
                {
                    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 = userLogin.CreatedByIpaddress;
                        userOtp.CreatedBy          = userLogin.CreatedBy;

                        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.SendCreateUserEmail(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);
        }
示例#5
0
        public string SaveUserOTP(string loginId)
        {
            /*   var ConfirmUser = _repository.Single(c => c.LoginId == loginId);
             *
             * var id = ConfirmUser.EmployeeId.Value;*/
            var data = _unitOfWork.DealerInformation.GetDealerUsers(loginId);

            if (data != null)
            {
                int validMin = 10;
                var otp      = new Random().Next(100000, 999999).ToString();
                var otpMsg   = new OtpMessageDto();
                otpMsg.DealerId     = data.DealerId;
                otpMsg.OTP          = otp;
                otpMsg.UserId       = data.UserId;
                otpMsg.GenerateTime = DateTime.Now;
                //  otpMsg.GenerateTime = DateTime.Now;
                var exOtp   = _unitOfWork.UserOtp.Get(s => s.UserId == data.UserId && s.IsUsedToken == null).FirstOrDefault();
                var usetOtp = new UserOtp();
                if (exOtp != null && exOtp.UserOtpId > 0)
                {
                    usetOtp             = exOtp;
                    usetOtp.ValidToDate = DateTime.Now.AddMinutes(validMin);
                    usetOtp.Password    = otp;

                    //if (exOtp.ValidToDate > DateTime.Now)
                    //{


                    //}
                }
                else
                {
                    usetOtp.UserId       = data.UserId;
                    usetOtp.Email        = data.EmailAddress;
                    usetOtp.Password     = otp;
                    usetOtp.GenerateTime = otpMsg.GenerateTime;
                    usetOtp.ValidToDate  = otpMsg.GenerateTime.AddMinutes(validMin);
                    usetOtp.MobileNo     = data.MobileNo;
                    otpMsg.ValidMinutes  = validMin;
                    usetOtp.IsUsedToken  = false;
                    usetOtp = _unitOfWork.UserOtp.Save(usetOtp);
                }

                if (usetOtp.UserOtpId > 0)
                {
                    otpMsg.UserName  = data.DealerName;
                    otpMsg.UserOtpId = usetOtp.UserOtpId;

                    if (_userNotificationService.SentOtp(otpMsg))
                    {
                        usetOtp.SendingStatus = true;
                        usetOtp.SendingTime   = DateTime.Now;
                        _unitOfWork.UserOtp.Update(usetOtp);
                        _unitOfWork.Commit();

                        return("Sucess");
                    }
                    else
                    {
                        return("Failed");
                    }
                }
            }
            return(null);
        }