public bool GenerateAndSendOTP(int userID)
        {
            _context = new MIDASGBXEntities();
            Repository.User user = _context.Users.Where(u => u.id == userID).FirstOrDefault();
            int             defaultAdminUserID = Convert.ToInt32(Common.Utility.GetConfigValue("DefaultAdminUserID"));
            bool            result             = false;

            try
            {
                if (user != null)
                {
                    var existingOTP = _context.OTPs.Where(p => p.UserID == userID).ToList();
                    existingOTP.ForEach(a => { a.IsDeleted = true; a.UpdateDate = DateTime.UtcNow; a.UpdateByUserID = defaultAdminUserID; });
                }

                OTP otp = new OTP();
                otp.OTPCode        = Common.Utility.GenerateRandomNumber(6);
                otp.Pin            = Common.Utility.GenerateRandomNo();
                otp.UserID         = user.id;
                otp.CreateDate     = DateTime.UtcNow;
                otp.CreateByUserID = Convert.ToInt32(defaultAdminUserID);
                otp.IsDeleted      = false;

                _context.OTPs.Add(otp);
                _context.SaveChanges();

                string Message = "Dear " + user.FirstName
                                 + ",<br><br>As per your request, a One Time Password (OTP) has been generated and the same is <i><b>" + otp.OTPCode.ToString()
                                 + "</b></i><br><br>Please use this OTP to complete the Login. Reference number is " + otp.Pin.ToString()
                                 + " <br><br>*** This is an auto-generated email. Please do not reply to this email.*** <br><br>Thanks"
                                 + " <br><br>MIDAS Administrator";

                Common.Email mail = new Common.Email();
                mail.ToEmail = user.UserName;
                mail.Subject = "OTP Alert Message From GBX MIDAS";
                mail.Body    = Message;

                mail.SendMail();
                result = true;
            }
            catch
            {
                result = false;
            }
            return(result);
        }
        public bool VerifyOTP(int userId, int otpCode)
        {
            _context = new MIDASGBXEntities();
            bool result = false;

            var otp = _context.OTPs
                      .Where(u => u.UserID == userId && u.OTPCode == otpCode && u.IsDeleted == false).FirstOrDefault();

            if (otp != null)
            {
                otp.IsDeleted      = true;
                otp.UpdateByUserID = userId;
                otp.UpdateDate     = DateTime.UtcNow;
                _context.SaveChanges();

                result = true;
            }
            return(result);
        }