Exemplo n.º 1
0
        public ActionResult Login(LoginModel loginModel)
        {
            Char charRange = '/';

            //STEP1: GOI HAM LOGIN TOI CSDL *****************************************************
            this.SetConnectionDB();
            BI_Project.Services.User.UserServices userServices = new UserServices(this.DBConnection);
            BI_Project.Services.Departments.DepartmentServices departmentServices = new DepartmentServices(this.DBConnection);

            EntityUserModel       entityUser       = userServices.CheckLogin(loginModel);
            EntityDepartmentModel entityDepartment = departmentServices.GetEntityById(entityUser.DeptId);
            SetDefaultPageService setDefault       = new SetDefaultPageService(DBConnection);

            if (entityUser.UserName != null)
            {
                Session["UserName"] = entityUser.UserName;
                Session["FullName"] = entityUser.FullName;
                Session[this.SESSION_NAME_USER_NAME] = entityUser.UserName;
                Session[this.SESSION_NAME_USERID]    = entityUser.UserId;
                Session["DepartIdUserLogin"]         = entityUser.DeptId;
                Session["IsAdmin"]         = entityUser.IsAdmin;
                Session["IsSuperAdmin"]    = entityUser.IsSuperAdmin;
                Session["CodeIsAdmin"]     = entityDepartment.Code;
                Session["Filter01IsAdmin"] = entityDepartment.Filter01;
                List <EntityUserMenuModel> entityUserMenuModel = setDefault.GetListDefaultPage(entityUser.UserId);
                foreach (EntityUserMenuModel item in entityUserMenuModel)
                {
                    if (item.IsDefaultPage == true)
                    {
                        var    _path       = item.Path;
                        string _controller = _path.Split(charRange)[0];
                        string _action     = _path.Split(charRange)[1];
                        int    _menuId     = item.MenuId;

                        return(RedirectToAction(_action + "/" + _menuId, _controller));
                    }
                }
                return(RedirectToAction("Index"));
            }
            if (userServices.ERROR != null)
            {
                Session["msgcode"] = MessageType.ServerError;
                FileHelper.SaveFile(userServices.ERROR, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + BI_Project.Helpers.Utility.APIStringHelper.GenerateFileId() + ".txt");
            }
            else
            {
                Session["msgcode"] = MessageType.BusinessError;
            }

            this.GetLanguage();
            ViewData["VIEWDATA_LANGUAGE"] = this.LANGUAGE_OBJECT;
            return(View("~/" + this.THEME_FOLDER + "/" + this.THEME_ACTIVE + "/login.cshtml", loginModel));

            //STEP2: NEU DANG NHAP KHONG THANH CONG
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            this.SaveAccessLog("create");
            if (null == Session[this.SESSION_NAME_USERID])
            {
                return(RedirectToAction("Login", "Home"));
            }
            if (Session["IsAdmin"] is false)
            {
                return(RedirectToAction("Logout", "Home"));
            }
            this.SetCommonData();


            ViewData["pagename"]     = "department_create";
            ViewData["action_block"] = "Departments/block_department_create";
            ViewData["data-form"]    = TempData["data"];

            string departId = (Request.QueryString["departid"] == null ? "0" : Request.QueryString["departid"].ToString());

            this.SetConnectionDB();
            DepartmentServices services = new DepartmentServices(this.DBConnection);

            EntityDepartmentModel model = new EntityDepartmentModel();

            if (ViewData["data-form"] != null)
            {
                model = (EntityDepartmentModel)ViewData["data-form"];
            }
            else
            {
                model = services.GetEntityById(Int32.Parse(departId));
            }

            //EntityDepartmentModel modelResponse = services.GetEntityById(Int32.Parse(departId));
            this.GetLanguage();
            if (model.DepartId > 0)
            {
                ViewData["pagename"] = "department_edit";
            }

            if (services.ERROR != null)
            {
                FileHelper.SaveFile(new { data = model, ERROR = services.ERROR }, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
            }
            BlockDepartmentCreateLangModel blockLang = new BlockDepartmentCreateLangModel();

            BI_Project.Models.UI.BlockModel blockModel = new Models.UI.BlockModel("block_department_create", this.LANGUAGE_OBJECT, blockLang);
            blockModel.DataModel  = model;
            ViewData["BlockData"] = blockModel;


            return(View("~/" + this.THEME_FOLDER + "/" + this.THEME_ACTIVE + "/index.cshtml"));
        }
Exemplo n.º 3
0
        public EntityDepartmentModel GetEntityById(int id)
        {
            EntityDepartmentModel output = new EntityDepartmentModel();

            try
            {
                DBConnection.OpenDBConnect();
                if (this.DBConnection.ERROR != null)
                {
                    throw new Exception("Can't connect to db");
                }
                //STEP1:  ***************************************************************/


                Dictionary <string, object> dicParas    = new Dictionary <string, object>();
                Dictionary <string, object> dicParaOuts = new Dictionary <string, object>();
                dicParas.Add("DEPARTID", id);
                DataSet dataSet = DBConnection.ExecSelectSP("SP_DEPART_GET_BY_ID", dicParas, ref dicParaOuts, true);
                //**********************TABLE: ROLE***************************************
                DataTable table1 = dataSet.Tables[0];
                foreach (DataRow row in table1.Rows)
                {
                    output.Name     = row["Name"].ToString();
                    output.DepartId = Int32.Parse(row["Id"].ToString());
                    output.Filter01 = row["Filter01"].ToString();
                    output.Code     = row["Code"].ToString();
                }
                //**********************TABLE: ROLEMENU ***********************************************
                //DataTable table2 = dataSet.Tables[1];

                //foreach (DataRow row in table2.Rows)
                //{
                //    output.ListRoleMenus.Add(Int32.Parse(row["menuid"].ToString()));
                //}
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
            }
            finally
            {
                this.DBConnection.CloseDBConnect();
            }
            return(output);
        }
Exemplo n.º 4
0
        public int CreateDepart(EntityDepartmentModel departModel)
        {
            int output = 0;

            try
            {
                DBConnection.OpenDBConnect();
                //STEP1:  ***************************************************************/


                Dictionary <string, object> dicParas    = new Dictionary <string, object>();
                Dictionary <string, object> dicParaOuts = new Dictionary <string, object>();

                if (departModel.Name != null)
                {
                    dicParas.Add("Name", departModel.Name);
                    dicParas.Add("Filter01", departModel.Filter01);
                    dicParas.Add("Code", departModel.Code);
                    dicParas.Add("Filter02", departModel.Filter02);

                    if (departModel.DepartId == 0)
                    {
                        //dicParas.Add("")
                        output = DBConnection.ExecSPNonQuery("SP_DEPARTMENT_INSERT", dicParas, ref dicParaOuts, true);
                    }
                    else
                    {
                        dicParas.Add("DepartId", departModel.DepartId);
                        output = DBConnection.ExecSPNonQuery("SP_DEPARTMENT_UPDATE", dicParas, ref dicParaOuts, true);
                    }
                }
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
                output     = -1;
            }
            finally
            {
                DBConnection.CloseDBConnect();
            }


            return(output);
        }
Exemplo n.º 5
0
        public List <EntityDepartmentModel> GetListAdminLogin(string code)
        {
            List <EntityDepartmentModel> output = new List <EntityDepartmentModel>();

            this.DBConnection.OpenDBConnect();
            if (this.DBConnection.ERROR != null)
            {
                throw new Exception("Can't connect to db");
            }

            try
            {
                string sqlSelectDepart = " select * from Department where Code = @Code  ";
                this.DBConnection.command.Parameters.Clear();
                this.DBConnection.command.Parameters.AddWithValue("@Code", code);
                this.DBConnection.command.CommandText = sqlSelectDepart;


                using (SqlDataReader reader = DBConnection.command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            EntityDepartmentModel entityRole = new EntityDepartmentModel();
                            entityRole.DepartId = reader.GetInt32(reader.GetOrdinal("Id"));
                            entityRole.Name     = reader.IsDBNull(reader.GetOrdinal("Name")) ? null : reader.GetString(reader.GetOrdinal("Name"));
                            entityRole.Filter01 = reader.IsDBNull(reader.GetOrdinal("Filter01")) ? null : reader.GetString(reader.GetOrdinal("Filter01"));
                            entityRole.Code     = reader.IsDBNull(reader.GetOrdinal("Code")) ? null : reader.GetString(reader.GetOrdinal("Code"));
                            output.Add(entityRole);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.ERROR = ex.ToString();
            }
            finally
            {
                this.DBConnection.CloseDBConnect();
            }
            return(output);
        }
        public ActionResult Index(int id)
        {
            //lay url tu menu voi id

            ViewData["pagename"]     = "Embed_Tableau";
            ViewData["action_block"] = "Tableau/TableauView";

            SetCommonData();
            GetLanguage();
            SetConnectionDB();


            BI_Project.Models.UI.PageModel pageModel = new Models.UI.PageModel("Embed_Tableau");
            // BI_Project.Models.UI.BlockModel blockModel = new BlockModel("TableauView");
            pageModel.SetLanguage(this.LANGUAGE_OBJECT);
            //pageModel.H1Title = pageModel.GetElementByPath("page_excel.menu" + id + ".h1");
            pageModel.Title        = pageModel.GetElementByPath("title");
            ViewData["page_model"] = pageModel;

            TableauModel param = new TableauModel();

            ViewData["BlockData"] = param;
            MenuServices _menuServices = new MenuServices(DBConnection);


            EntityMenuModel _entityMenuModel = _menuServices.GetMenuModel(id.ToString());

            UserServices _userServices = new UserServices(DBConnection);

            DepartmentServices _departmentServices = new DepartmentServices(DBConnection);

            EntityDepartmentModel _entityDepartmentModel = new EntityDepartmentModel();

            //param.Site_Root = _entityMenuModel.Site_Root;
            param.Ticket     = Helpers.TableauHelper.GetTicket("");
            param.TableauUrl = _entityMenuModel.TableauUrl;
            param.Hidden     = 1;
            param.username   = Session["UserName"].ToString();
            ViewBag.Id       = id;

            var listFilter01 = _departmentServices.GetList().Select(x => x.Filter01).ToArray();

            StringBuilder builderOrganization = new StringBuilder();

            foreach (var _list in listFilter01)
            {
                builderOrganization.Append(_list).Append(',');
            }


            string _resultListOrganization = builderOrganization.ToString().TrimEnd(',');

            ViewBag.ListDepartment = _resultListOrganization;



            var getUser       = _userServices.GetList();
            var getUserCheck  = getUser.FirstOrDefault(x => x.UserName == param.username);
            var getDepartment = _departmentServices.GetEntityById(getUserCheck.DeptId);


            if (getUserCheck.IsAdmin == false && (getDepartment.Filter01 != "PE" || getDepartment.Filter01 != "PA" || getDepartment.Filter01 != "PB" || getDepartment.Filter01 != "PC" || getDepartment.Filter01 != "PD"))
            {
                param.GetFilter(id);
            }
            //param.GetFilter(id);
            Random rd   = new Random();
            int    item = rd.Next(100, 999);
            string log  = DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) + "_" + item;

            if (_menuServices.ERROR != null)
            {
                FileHelper.SaveFile(new { ERROR = _menuServices.ERROR }, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + APIStringHelper.GenerateFileId() + ".txt");
            }

            FileHelper.SaveFile(_entityMenuModel, this.LOG_FOLDER + "/MenuModel_" + log + ".txt");
            FileHelper.SaveFile(param.Ticket, this.LOG_FOLDER + "/Ticket_" + log + ".txt");
            return(View("~/" + this.THEME_FOLDER + "/" + this.THEME_ACTIVE + "/index.cshtml"));
        }
        public ActionResult Create(EntityDepartmentModel model)
        {
            if (null == Session[this.SESSION_NAME_USERID])
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (Session["IsAdmin"] == null)
            {
                return(RedirectToAction("Logout", "Home"));
            }
            this.SetConnectionDB();

            this.GetLanguage();
            int output = 0;

            if (model.Code == null)
            {
                Session["msg_code"] = -1;
                Session["msg_text"] = BlockLanguageModel.GetElementLang(this.LANGUAGE_OBJECT, "messages.block_department_create.error_code");
                TempData["data"]    = model;
                return(RedirectToAction("Create"));
            }
            model.Code = model.Filter01.Substring(0, 2);
            DepartmentServices departServices = new DepartmentServices(this.DBConnection);

            output = departServices.CreateDepart(model);

            /****************************************RESPONSE FAILE OR SUCCESS******************************************/

            //this.GetLanguage();
            BlockDepartmentCreateLangModel blockLang = new BlockDepartmentCreateLangModel();

            blockLang.BlockName = "block_department_create";
            blockLang.SetLanguage(this.LANGUAGE_OBJECT);
            Session["msg_text"] = blockLang.GetMessage(output);
            Session["msg_code"] = output;

            if (departServices.ERROR != null)
            {
                BI_Project.Helpers.FileHelper.SaveFile(departServices.ERROR, this.LOG_FOLDER + "/ERROR_" + this.GetType().ToString() + BI_Project.Helpers.Utility.APIStringHelper.GenerateFileId() + ".txt");
            }

            if (model.DepartId > 0 && output > 0)
            {
                Session["msg_text"] = blockLang.GetLangByPath("messages.block_department_create.success_edit", this.LANGUAGE_OBJECT);
            }
            if (output == 0)
            {
                Session["msg_text"] = blockLang.GetLangByPath("messages.block_department_create.error_business_1", this.LANGUAGE_OBJECT);
                //return RedirectToAction("Create?roleid=" + model.RoleId);
            }
            if (output > 0)
            {
                return(RedirectToAction("List"));
            }


            TempData["data"] = model;
            return(RedirectToAction("Create"));
        }