Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created MVC Action and it gives compile time error as 'Not all code path returns value.'

What I have tried:

public ActionResult Submit(User u)
{
    List<User> uList = gc.Users.Include(p => p.Role).Where(p => p.UserName == u.UserName && p.UserPwd == u.UserPwd).ToList();
    List<User_Log> uUserLog = gc.User_Logs.Include(p => p.User).Where(p => p.UserName == u.UserName
       && p.Failed_DateTime.Value.Year == DateTime.Now.Year
                    && p.Failed_DateTime.Value.Month == DateTime.Now.Month
                    && p.Failed_DateTime.Value.Day == DateTime.Now.Day).ToList();

    if (uList.Count > 0 && uUserLog.Count < 3)
    {
        uList[0].IP = Request.UserHostAddress.ToString();
        if (uList[0].IsEnabled == true)
        {
            uList[0].Status = true;
            ub.UserLog(uList[0]);
            if (uList[0].PwUpdateDate == null)
            {
                return View("ChangePassword");
            }
            if (uList[0].UUpdateDate == null)
            {
                return View("UserDetails");
            }
        }
        else if (uList[0].IsEnabled == false)
        {
            uList[0].Status = false;
            ub.UserLog(uList[0]);
            ViewBag.Message("YOUR ACCOUNT IS DISABLED.");
            return View("Login");
        }
    }
    else if(uUserLog.Count<3)
    {
        u.IP= Request.UserHostAddress.ToString();
        u.Status = false;
        //uList[0].Status = false;
        ub.UserLog(u);
        ViewBag.Message="Invalid User Name Or Password. Your account will be locked out after three incorrect password attempts. \nTo avoid such situation, kindly click on FORGOT PASSWORD option for your user details.!";
        return View("Login");
    }
    else
    {
        ViewBag.Message="Your account is locked.To unlock send email to GEEM.SupplierReg@ge.com; ge.energy@datamatics.com";
        return View("Login");
    }

    //List<User> uList = uc.Users.ToList<User>().Where(p=>p.UserName==c.UserName && p.UserPwd==c.UserPwd);

}
Posted
Updated 21-Nov-17 22:25pm

1 solution

Please see my in-code comments:

C#
            if (uList.Count > 0 && uUserLog.Count < 3)
            {
                uList[0].IP = Request.UserHostAddress.ToString();
                if (uList[0].IsEnabled == true)
                {
                    uList[0].Status = true;
                    ub.UserLog(uList[0]);
                    if (uList[0].PwUpdateDate == null)
                    {
                        return View("ChangePassword");
                    }
                    if (uList[0].UUpdateDate == null)
                    {
                        return View("UserDetails");
                    }
//                  else
//                  {
//   Here is an else-branch that you skipped
//   in which case your code would return nothing
//                  }
                }
                else if (uList[0].IsEnabled == false)
                {
                    uList[0].Status = false;
                    ub.UserLog(uList[0]);
                    ViewBag.Message("YOUR ACCOUNT IS DISABLED.");
                    return View("Login");
                }
//              else
//              {
//    Here is an else-branch that you skipped
//    in which case your code would return nothing
//              } 
            }
            else if(uUserLog.Count<3)
            {
                u.IP= Request.UserHostAddress.ToString();
                u.Status = false;
                //uList[0].Status = false;
                ub.UserLog(u);
                ViewBag.Message="Invalid User Name Or Password. Your account will be locked out after three incorrect password attempts. \nTo avoid such situation, kindly click on FORGOT PASSWORD option for your user details.!";
                return View("Login");
            }
            else 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900