jeudi 28 novembre 2019

Checking multiple validations using if statement

I'm trying to work on ForgotPassword section, not in advance but normally by checking conditions. Here trying to check if the user input values Username, Mail Id, Usertype are correct otherwise, show error messages such as username or mailid or type doesn't match. But here am failing to show error messages such that the else part isn't working.

controller

public ActionResult Forgotpassword1( FormCollection collection)
        {
                string username = collection["username"];
                string mail = collection["mail"];
                string type = collection["type"].ToString();
                Random rand = new Random();
                var password = rand.Next().ToString();
                var getrandomkey = password.Substring(0, 5);
                var lgn = db.tb_log.Where(ob => (ob.username == username) && (ob.usertype == type)).FirstOrDefault();
                string userid = lgn.username;
                if (lgn != null)
                {
                    if (lgn.usertype == ("User"))
                {
                    Session["username"] = lgn.username;
                    Session["type"] = lgn.usertype;
                    userid = lgn.username;
                    var useraccount = db.tb_reg.Where(i => i.gmail == mail && i.usertype == type && i.username == username).FirstOrDefault();
                    if (useraccount != null)
                    {
                        tb_log login = db.tb_log.Where(i => i.username == username && i.usertype == type).FirstOrDefault();
                        if (login != null)
                        {
                         login.code = getrandomkey;
                            db.tb_log.Add(login);
                            int i = db.SaveChanges();
                            if (i > 0)
                            {
                                ViewBag.s = "Verification Code has been send to your registered mail id";
                            }
                            else
                            {
                                ViewBag.f = "Something went wrong";
                            }
                        }
                        else
                        {
                            ViewBag.f = "Username or type not match";
                        }
                    }
                    else
                    {
                        ViewBag.f = "Username or Mail not match";
                    }}

Aucun commentaire:

Enregistrer un commentaire