// Store Fuctionality
        public void AddStore(string userId, string storeId)
        {
            LoginUserModel lgModel = new LoginUserModel();

            if (!ValidationUtility.IsNull(storeId))
            {
                string[] storeIdList = storeId.Split(',');

                for (int i = 0; i < storeIdList.Length; i++)
                {
                    int sId = ValidationUtility.ToInteger(storeIdList[i]);
                    int uId = ValidationUtility.ToInteger(userId);
                    lgModel.AddUserStore(sId, uId);

                }
            }
        }
        public void AssignAreaManager(string generalManagerId, string areaManagerId)
        {
            LoginUserModel lgModel = new LoginUserModel();

            if (!ValidationUtility.IsNull(areaManagerId))
            {
                string[] amIdList = areaManagerId.Split(',');

                for (int i = 0; i < amIdList.Length; i++)
                {

                    int gmId = ValidationUtility.ToInteger(generalManagerId);
                    int amId = ValidationUtility.ToInteger(amIdList[i]);
                    lgModel.AddAssignAreaManager(gmId, amId);
                }
            }
        }
        public JsonResult DeleteUser(int id)
        {
            LoginUserModel lgModel = new LoginUserModel();

            string error = "";
            string msg = "";

            try
            {
                lgModel.Delete(id);
                error = "Success";
                msg = "User Deleted Successfully";
            }
            catch (Exception ex)
            {

                error = "Error";
                msg = "User is not Deleted";
                log.Error(" Exception in DeleteUser Method ", ex);
            }

            ResponseDTO resDTO = new ResponseDTO { Error = error, Message = msg };
            return Json(resDTO, JsonRequestBehavior.AllowGet);
        }
 public void AddUser(string name, string role, string emailId)
 {
     LoginUserModel lgModel = new LoginUserModel();
     lgModel.Add(name, role, emailId);
 }
 public void UpdateUser(int id, string sec, string userId, string roleType, string emailId)
 {
     LoginUserModel lgModel = new LoginUserModel();
     lgModel.Update(id, sec, userId, roleType, emailId);
 }
        public void removeStore(string userId, string storeId)
        {
            LoginUserModel lgModel = new LoginUserModel();

            if (!ValidationUtility.IsNull(storeId) && !ValidationUtility.IsEqual(storeId, "Manager"))
            {
                int sid = ValidationUtility.ToInteger(storeId);
                int uid = ValidationUtility.ToInteger(userId);
                lgModel.ReomoveStore(sid, uid, true);
            }
            else if (!ValidationUtility.IsNull(storeId) && ValidationUtility.IsEqual(storeId, "Manager"))
            {
                int sid = ValidationUtility.ToInteger(storeId);
                int uid = ValidationUtility.ToInteger(userId);
                lgModel.ReomoveStore(sid, uid, false);
            }
        }
        public void UpdateStore(string userId, string newStoreId, string preStoreId)
        {
            LoginUserModel lgModel = new LoginUserModel();

            if (!ValidationUtility.IsNull(newStoreId) && !ValidationUtility.IsNull(preStoreId))
            {
                if (ValidationUtility.IsEqual(preStoreId, "Manager"))
                {
                    int nsid = ValidationUtility.ToInteger(newStoreId);
                    int uid = ValidationUtility.ToInteger(userId);
                    lgModel.UpdateUserStore(nsid, 0, uid);
                }

            }
        }
 public JsonResult GetStoreName()
 {
     LoginUserModel lgModel = new LoginUserModel();
     ArrayList val = lgModel.GetStoreList();
     return Json(val, JsonRequestBehavior.AllowGet);
 }
        public void RemoveAssignedAreaManager(string tId)
        {
            LoginUserModel lgModel = new LoginUserModel();

            int id = ValidationUtility.ToInteger(tId);

            lgModel.RemoveareaManager(id);
        }
 public JsonResult GetRoleList()
 {
     LoginUserModel lgModel = new LoginUserModel();
     ArrayList roleList = lgModel.GetAllRoleList();
     return Json(roleList, JsonRequestBehavior.AllowGet);
 }
        public JsonResult GetAssignAreaManagerList(string userId)
        {
            LoginUserModel lgModel = new LoginUserModel();

            ArrayList list = new ArrayList();
            int gmId = ValidationUtility.ToInteger(userId);

            ArrayList assignAreaManager = lgModel.GetAllAssignAreaManagerList(gmId);
            ArrayList AllUser = lgModel.GetList();
            ArrayList remainingAreaManager = new ArrayList();

            for (int j = 0; j < AllUser.Count; j++)
            {
                UserContext allDTO = (UserContext)AllUser[j];
                if (allDTO.Role == "AreaManager")
                {
                    remainingAreaManager.Add(allDTO);
                }
            }

            for (int i = 0; i < assignAreaManager.Count; i++)
            {
                AssignAreaManagerInfoDTO asineDTO = (AssignAreaManagerInfoDTO)assignAreaManager[i];

                for (int k = 0; k < remainingAreaManager.Count; k++)
                {
                    UserContext unAsineDTO = (UserContext)remainingAreaManager[k];

                    if (asineDTO.AreaManagerId == unAsineDTO.Id)
                    {
                        remainingAreaManager.Remove(unAsineDTO);
                        break;
                    }

                }

            }

            list.Add(assignAreaManager);
            list.Add(remainingAreaManager);

            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetAllUser()
        {
            LoginUserModel lgModel = new LoginUserModel();
            DataTable ds = lgModel.GetUserList();
            string jsone = ValidationUtility.DataTableToJson(ds);
            //JsonResult js = Json(ds, JsonRequestBehavior.AllowGet);
            // string s = jsone;
            //return Json(jsone, JsonRequestBehavior.AllowGet);

            ArrayList list = lgModel.GetList();

            return Json(list, JsonRequestBehavior.AllowGet);
        }
        //public JsonResult GetAllAssignStore()
        //{
        //    LoginUserModel lgModel = new LoginUserModel();
        //    ArrayList list = lgModel.GetUserAssignStore();
        //    return Json(list, JsonRequestBehavior.AllowGet);
        //}
        public JsonResult GetAllAssignStore(string userId)
        {
            LoginUserModel lgModel = new LoginUserModel();
            ArrayList list = new ArrayList();

            ArrayList allStoreList = ValidationUtility.GetStoreList(false);

            int uId = ValidationUtility.ToInteger(userId);

            ArrayList AssignStoreList = lgModel.GetUserAssignStore(uId);
            ArrayList unAssingStoreList = new ArrayList();

            for (int i = 0; i < AssignStoreList.Count; i++)
            {
                StoreDTO asineDTO = (StoreDTO)AssignStoreList[i];

                for (int j = 0; j < allStoreList.Count; j++)
                {
                    StoreDTO unAsineDTO = (StoreDTO)allStoreList[j];

                    if (asineDTO.Id == unAsineDTO.Id)
                    {
                        allStoreList.Remove(unAsineDTO);
                        break;
                    }

                }

            }

            list.Add(AssignStoreList);
            list.Add(allStoreList);

            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Authenticate()
        {
            try
            {
                log.Info("Call Info");
                // RecordSalesJob rsb = new RecordSalesJob();
                // rsb.UpdateRecordSale();

                    string userId = Request.Form["userId"];
                    string password = Request.Form["password"];

                    log.Info("userId  " + userId);

                    LoginUserModel lgModel = new LoginUserModel();

                    UserContext context = lgModel.UserAuthenticate(userId, password);

                    if (context != null && ValidationUtility.IsEqual("Manager", context.Role))
                    {
                        context.StoreDBConnectionString = lgModel.GetConnectionString(context.Id);

                        Session["UserId"] = context.UserId;
                        Session["UserContext"] = context;
                        Session["ConnectionString"] = context.StoreDBConnectionString;
                        return Redirect("/Manager/Index");
                    }

                    if (context != null && ValidationUtility.IsEqual("Admin", context.Role))
                    {
                        context.StoreDBConnectionString = lgModel.GetConnectionString();

                        Session["UserId"] = context.UserId;
                        Session["UserContext"] = context;
                        Session["ConnectionString"] = context.StoreDBConnectionString;
                        return Redirect("/Admin/Index");
                    }
                    if (context != null && ValidationUtility.IsEqual("Corporate", context.Role))
                    {
                        context.StoreDBConnectionString = lgModel.GetConnectionString(context.Id);

                        Session["UserId"] = context.UserId;
                        Session["UserContext"] = context;
                        Session["ConnectionString"] = context.StoreDBConnectionString;
                        return Redirect("/Corporate/Index");
                    }

                    if (context != null && ValidationUtility.IsEqual("AreaManager", context.Role))
                    {
                        context.StoreDBConnectionString = lgModel.GetConnectionString(context.Id);

                        Session["UserId"] = context.UserId;
                        Session["UserContext"] = context;
                        Session["ConnectionString"] = context.StoreDBConnectionString;
                        return Redirect("/AreaManager/Index");
                    }

                    if (context != null && ValidationUtility.IsEqual("Maintenance", context.Role))
                    {
                        context.StoreDBConnectionString = lgModel.GetConnectionString();

                        Session["UserId"] = context.UserId;
                        Session["UserContext"] = context;
                        Session["ConnectionString"] = context.StoreDBConnectionString;
                        return Redirect("/Maintenance/Index");
                    }

                    if (context != null && ValidationUtility.IsEqual("GeneralManager", context.Role))
                    {
                        context.StoreDBConnectionString = lgModel.GetConnectionString(context.Id);

                        Session["UserId"] = context.UserId;
                        Session["UserContext"] = context;
                        Session["ConnectionString"] = context.StoreDBConnectionString;
                        return Redirect("/GeneralManager/Index");
                    }

                    else
                    {
                        log.Error(" User contex is null  ");

                        ViewBag.Message = " Please Enter Correct Information ";
                        return Redirect("/Home");
                    }

            }
            catch (Exception ex)
            {
                log.Error("Exception in Authenticate ", ex);
            }

            return Redirect("/Home");

            //if (userId == "pos1" && password == "pos1")
            //{
            //    ViewBag.Message = "Succeeded";

            //}
            //else
            //{
            //    ViewBag.Message = "Failed";
            //}

            // return  View("~/views/ManagerDashboard/Home");
        }