Esempio n. 1
0
        public ActionResult Login(UserRegistration UR)
        {
            bool status = true;

            if (string.IsNullOrEmpty(UR.UserName))
            {
                status = false;
            }
            else if (string.IsNullOrEmpty(UR.Password))
            {
                status = false;
            }
            //else if (UR.BranchID <= 0)
            //    status = false;
            //else if (UR.AcFinancialYearID <= 0)
            //    status = false;



            if (status)
            {
                List <SP_LoginUser_Result> Log = new List <SP_LoginUser_Result>();

                Log = rgm.LoginUser(UR);
                var userlogin = entity.UserRegistrations.Where(d => d.EmailId == UR.UserName && d.Password == UR.Password).ToList();
                if (userlogin.Count > 0)
                {
                    foreach (var item in userlogin)
                    {
                        FormsAuthentication.SetAuthCookie(item.UserName, true);
                        var User_Registration = (from t in entity.UserRegistrations
                                                 where t.UserID == item.UserID
                                                 select t
                                                 ).FirstOrDefault();
                        if (User_Registration.BranchID == 0 || User_Registration.BranchID == null)
                        {
                            User_Registration.BranchID = entity.BranchMasters.FirstOrDefault().BranchID;
                        }
                        var acfinancialyearid = entity.AcFinancialYears.Where(d => d.BranchID == User_Registration.BranchID).FirstOrDefault().AcFinancialYearID;

                        int?BranchCurrencyId = (from e in entity.BranchMasters where e.BranchID == User_Registration.BranchID select e.CurrencyID).FirstOrDefault();
                        var basecurrency     = (from t in entity.CurrencyMasters where t.CurrencyID == BranchCurrencyId select t).FirstOrDefault();
                        Session["BaseCurrencyId"]     = BranchCurrencyId;
                        Session["BaseCurrency"]       = basecurrency.CurrencyName;
                        Session["BaseCurrencySymbol"] = basecurrency.Symbol;
                        Session["UserID"]             = item.UserID;
                        Session["UserName"]           = item.UserName;
                        Session["branchid"]           = User_Registration.BranchID;
                        var AccompanyId = (from c in entity.AcCompanies select c.AcCompanyID).FirstOrDefault();
                        Session["AcCompanyID"] = AccompanyId;
                        Session["fyearid"]     = acfinancialyearid;
                        SourceMastersModel objSourceMastersModel = new SourceMastersModel();
                        Session["Company"]    = objSourceMastersModel.GetAcCompaniesById(AccompanyId).AcCompany1;
                        Session["BranchName"] = entity.BranchMasters.Find(User_Registration.BranchID).BranchName;
                        var fyearFrom = (from t in entity.AcFinancialYears where t.AcFinancialYearID == acfinancialyearid select t.AcFYearFrom).FirstOrDefault();
                        Session["FyearFrom"] = fyearFrom;
                        var fyearTo = (from t in entity.AcFinancialYears where t.AcFinancialYearID == acfinancialyearid select t.AcFYearTo).FirstOrDefault();

                        Session["FyearTo"] = fyearTo;
                        var query = (from t in entity.UserRegistrations
                                     where t.UserID == item.UserID && t.RoleID.HasValue
                                     select t.RoleID.Value).ToList();
                        var UserRoleID = (from t in entity.UserRegistrations
                                          where t.UserID == item.UserID
                                          select t.RoleID).FirstOrDefault();
                        Session["UserRoleID"] = UserRoleID;
                        if (query != null)
                        {
                            Session["RoleID"] = query;
                            if (query[0] == 1)
                            {
                                var menuaccesslevels = new List <MenuAccessLevel>();
                                var menus            = (from t in entity.Menus where t.IsAccountMenu.Value == false orderby t.MenuOrder select t).ToList();

                                Session["Menu"] = menus;
                            }
                            else
                            {
                                Int32 roleid   = query[0];
                                var   menudata = (from t in entity.MenuAccessLevels
                                                  join s in entity.Menus on t.MenuID equals s.MenuID
                                                  where t.RoleID == roleid && t.IsView == true
                                                  orderby s.MenuOrder
                                                  select s).ToList();
                                Session["menu"] = menudata;
                            }
                        }
                        else
                        {
                            Session["RoleID"] = new List <int>();
                        }
                    }

                    return(RedirectToAction("Home", "Home"));
                }

                Session["ForgotStatus"]  = "Forgot";
                Session["StatusMessage"] = "Invalid EmailId!";
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                ViewBag.ErrorMessage = "Please fill mandatory fields";
                ViewBag.Branch       = entity.BranchMasters.ToList();

                ViewBag.fyears = entity.AcFinancialYearSelect(Convert.ToInt32(Session["branchid"])).ToList();
                return(View());
            }
        }