public ActionResult LogIn(FormCollection collection, string ReturnUrl)
        {
            try
            {
                //GetRealIpAddress();
                //int roleId = Convert.ToInt32(collection["RoleId"]);

                User   user     = new User();
                string userName = collection["userName"];
                string password = collection["Password"];
                user.Password = password;
                user.UserName = userName;

                //var userLocation = GetUserLocation();
                var userLocation = new UserLocation
                {
                    IPAddress = GetRealIpAddress(),
                };
                //var ltttt= collection["Latitude"];
                if (collection["Latitude"] != "")
                {
                    userLocation.Latitude  = Convert.ToDecimal(collection["Latitude"]);
                    userLocation.Longitude = Convert.ToDecimal(collection["Longitude"]);
                }

                bool validUser = _userManager.ValidateUser(user);

                if (validUser)
                {
                    userLocation.IsValidLogin = 1;
                    var model      = _userManager.GetUserByUserName(user.UserName);
                    var difference = (DateTime.Now - model.PasswordUpdateDate).TotalDays;
                    var anUser     = Mapper.Map <User, ViewUser>(model);
                    anUser.IsPasswordChangeRequired = difference > anUser.PasswordChangeRequiredWithin;
                    Session["Branches"]             = _iCommonManager.GetAssignedBranchesToUserByUserId(anUser.UserId).ToList();
                    Session["Roles"] = _userManager.GetAssignedUserRolesByUserId(anUser.UserId);
                    anUser.IsGeneralRequisitionRight = _iCommonManager.GetFirstApprovalPathByUserId(anUser.UserId);
                    anUser.IsApprovalRight           = _iCommonManager.GetFirstApprovalPathByApproverUserId(anUser.UserId);
                    Session["user"] = anUser;
                    int companyId = Convert.ToInt32(collection["companyId"]);
                    var company   = _iCompanyManager.GetById(companyId);
                    Session["CompanyId"] = companyId;
                    Session["Company"]   = company;
                    FormsAuthentication.SetAuthCookie(user.UserName, false);
                    var employee = _iEmployeeManager.GetEmployeeById(anUser.EmployeeId);
                    if (employee.EmployeeName != null)
                    {
                        anUser.EmployeeImage   = employee.EmployeeImage;
                        anUser.DesignationName = employee.DesignationName;
                        anUser.EmployeeName    = employee.EmployeeName;
                        anUser.UserDoB         = employee.DoB;
                    }
                    else
                    {
                        anUser.EmployeeImage = "Images/login_image.png";
                        anUser.EmployeeName  = userName;
                    }
                    anUser.IpAddress     = GetRealIpAddress();
                    anUser.MacAddress    = GetMacAddress().ToString();
                    anUser.LogInDateTime = DateTime.Now;


                    bool result = _userManager.ChangeLoginStatus(anUser, 1, userLocation);
                    Session.Timeout = 180;
                    if (anUser.IsPasswordChangeRequired)
                    {
                        return(RedirectToAction("ChangePassword", "Home", new { area = "CommonArea", id = anUser.UserId }));
                    }
                    switch (anUser.Roles)
                    {
                    case "Management":
                        return(RedirectToAction("Home", "Home", new { area = "Management" }));

                    default:
                        return(RedirectToAction("Goto", "LogIn", new { area = "" }));
                    }
                }
                ViewBag.Message   = "Invalid Login";
                ViewBag.Companies = _iCompanyManager.GetAll().ToList().OrderBy(n => n.CompanyId).ToList();
                return(View());
            }
            catch (Exception exception)
            {
                Log.WriteErrorLog(exception);
                return(PartialView("_ErrorPartial", exception));
            }
        }