sunil mali Ответов: 1

Mvc не весь путь кода возвращает значение


Я создал действие MVC, и оно выдает ошибку времени компиляции как "не весь путь кода возвращает значение".

Что я уже пробовал:

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);

}

1 Ответов

Рейтинг:
8

Sascha Lefèvre

Пожалуйста, смотрите мои комментарии в коде:

            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