コード例 #1
0
        //------------------- Article List -----------------

        //==================================================

        //==================================================
        //----------------- Update Download Article --------
        public void ArticleDownload(int id)
        {
            //----------- update ------------
            #region Update Article

            App_Start.ConnectionString constr = new App_Start.ConnectionString();
            ConnectionString = constr.GetConnectionString();

            // 1. Instantiate the connection
            SqlConnection conn = new SqlConnection(ConnectionString);

            SqlDataReader rdr = null;

            try

            {
                conn.Open();
                SqlCommand cmd;

                cmd = new SqlCommand(@"SP_UPDATE_ARTICLE_DOWNLOAD", conn);


                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                cmd.Parameters["@id"].Value = id;
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                conn.Close();
                conn.Dispose();
            }

            #endregion Update Article
            //----------- update ------------
        }
コード例 #2
0
        public ActionResult ArticleList(string search_text, int?page)
        {
            int Startindex = 0;
            int pagesize   = 1;

            page       = page.HasValue ? Convert.ToInt32(page) - 1 : 0;
            Startindex = page.HasValue ? Convert.ToInt32(page * pagesize) : 0;


            List <ViewModel.Article_User_Rank_VM> article_list = new List <ViewModel.Article_User_Rank_VM>();

            int Total_item   = 0;
            int Total_page   = 0;
            int?Current_page = page;


            //===================================================================
            //--------------------- Get Session User ----------------------------
            #region Get Session User
            string username = null;
            if (Session["User"] != null)
            {
                User currentuser = (User)Session["User"];

                username = currentuser.username;
            }

            #endregion Get Session User
            //--------------------- Get Session User ----------------------------
            //===================================================================

            //===================================================================
            //---------------------- Get Article List ---------------------------
            #region Get Article List

            App_Start.ConnectionString constr = new App_Start.ConnectionString();
            ConnectionString = constr.GetConnectionString();

            // 1. Instantiate the connection
            SqlConnection conn = new SqlConnection(ConnectionString);

            SqlDataReader rdr = null;

            try

            {
                conn.Open();
                SqlCommand cmd;
                if (username == null)
                {
                    cmd = new SqlCommand(@"SP_ARTICLE_LIST", conn);
                }
                else
                {
                    cmd = new SqlCommand(@"SP_ARTICLE_USER_LIST", conn);
                    cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.NVarChar, 50));
                    cmd.Parameters["@Username"].Value = username;
                }

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@search", SqlDbType.NVarChar, 50));
                cmd.Parameters["@search"].Value = "%" + search_text + "%";

                cmd.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int));
                cmd.Parameters["@PageSize"].Value = pagesize;

                cmd.Parameters.Add(new SqlParameter("@CurrentPage", SqlDbType.Int));
                cmd.Parameters["@CurrentPage"].Value = page;


                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();

                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        article_list = (from DataRow dr in dataTable.Rows
                                        select new ViewModel.Article_User_Rank_VM()
                        {
                            id = Convert.ToInt32(dr["id"]),
                            Title = dr["Title"].ToString(),
                            En_Title = dr["En_Title"].ToString(),
                            Description = dr["Description"].ToString(),
                            writer = dr["writer"].ToString(),
                            Download = dr["Download"].ToString() != "" ? int.Parse(dr["Download"].ToString()) : int.Parse("0"),
                            Date = dr["Date"].ToString() != "" ? DateTime.Parse(dr["Date"].ToString()) :(DateTime?)null
                        }
                                        ).ToList();

                        //=====================================================
                        //---------------- Get Total item for pager -----------
                        rdr             = null;
                        cmd             = new SqlCommand(@"SP_TOTAL_ARTICLE_LIST", conn);
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add(new SqlParameter("@search", SqlDbType.NVarChar, 50));
                        cmd.Parameters["@search"].Value = "%" + search_text + "%";
                        rdr       = cmd.ExecuteReader();
                        dataTable = new DataTable();

                        dataTable.Load(rdr);

                        if (dataTable != null)
                        {
                            if (dataTable.Rows.Count > 0)
                            {
                                DataRow dr = dataTable.Rows[0];

                                Total_item = dr["Total"].ToString() != "" ? int.Parse(dr["Total"].ToString()) : 0;
                            }
                        }

                        //---------------- Get Total item for pager -----------
                        //=====================================================
                        rdr = null;
                        dataTable.Dispose();
                        conn.Close();
                        conn.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                conn.Close();
                conn.Dispose();
            }

            #endregion Get Article List
            //---------------------- Get Article List ---------------------------
            //===================================================================


            //institute_list = db.Institutes.Where(p => p.city_code.StartsWith(city)).Where(p => p.name.Contains(search_text)).OrderBy(p => p.name).Skip(Startindex).Take(pagesize).ToList();
            //Total_item = db.Institutes.Where(p => p.city_code.StartsWith(city)).Where(p => p.name.Contains(search_text)).Select(p => p.id).Count();



            Total_page = Total_item / pagesize;

            //==========================================
            //---------------- Set ViewBag -------------

            ViewBag.Total_item   = Total_item;
            ViewBag.Total_page   = Total_page;
            ViewBag.Current_page = Current_page;
            //---------------- Set ViewBag -------------
            //==========================================

            return(PartialView("~/Views/Shared/Partial/_ArticleList.cshtml", article_list));
        }
コード例 #3
0
        public ActionResult institute(int id)
        {
            if (id != 0)
            {
                App_Start.ConnectionString constr = new App_Start.ConnectionString();
                ConnectionString = constr.GetConnectionString();
                SqlConnection conn = new SqlConnection(ConnectionString);
                SqlDataReader rdr  = null;
                //============================================================
                //--------------------- Get Institute Info ------
                ViewModel.InstituteInfo_VM InstituteInfo = new ViewModel.InstituteInfo_VM();
                #region Get Institute Info
                try
                {
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    SqlCommand cmd = new SqlCommand(@"select Institutes.id,Institutes.name,Institutes.tel1,Institutes.tel2,Institutes.website,Institutes.address
		                ,Institutes.boyOrGirl,Institutes.city_code,Institutes.shoar,Institutes.Email
		                ,Institutes.Group_Channel1,Institutes.Group_Channel2,Institutes.Group_Channel3,Institutes.Group_Channel4
		                ,Institutes.Description,Institutes.mobile1,Institutes.mobile2,Institutes.Google_Map,Institutes.En_Name
		                ,(select InstituteKind.Name from InstituteKind where InstituteKind.id=Institutes.InstituteKindid) as InstituteKindName
	                 from Institutes 
	                where 
		                Institutes.id =@id
		                and (Institutes.Active is null or Institutes.Active=1) "        , conn);


                    cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.BigInt));
                    cmd.Parameters["@id"].Value = id;

                    rdr = cmd.ExecuteReader();
                    DataTable dataTable = new DataTable();

                    dataTable.Load(rdr);

                    if (dataTable != null)
                    {
                        if (dataTable.Rows.Count > 0)
                        {
                            DataRow dr = dataTable.Rows[0];

                            InstituteInfo.id                = id;
                            InstituteInfo.name              = dr["name"].ToString();
                            InstituteInfo.tel1              = dr["tel1"].ToString();
                            InstituteInfo.tel2              = dr["tel2"].ToString();
                            InstituteInfo.website           = dr["website"].ToString();
                            InstituteInfo.address           = dr["address"].ToString();
                            InstituteInfo.boyOrGirl         = dr["boyOrGirl"].ToString() != ""?bool.Parse(dr["boyOrGirl"].ToString()):(bool?)null;
                            InstituteInfo.city_code         = dr["city_code"].ToString();
                            InstituteInfo.shoar             = dr["shoar"].ToString();
                            InstituteInfo.Email             = dr["Email"].ToString();
                            InstituteInfo.Group_Channel1    = dr["Group_Channel1"].ToString();
                            InstituteInfo.Group_Channel2    = dr["Group_Channel2"].ToString();
                            InstituteInfo.Group_Channel3    = dr["Group_Channel3"].ToString();
                            InstituteInfo.Group_Channel4    = dr["Group_Channel4"].ToString();
                            InstituteInfo.Description       = dr["Description"].ToString();
                            InstituteInfo.mobile1           = dr["mobile1"].ToString();
                            InstituteInfo.mobile2           = dr["mobile2"].ToString();
                            InstituteInfo.Google_Map        = dr["Google_Map"].ToString();
                            InstituteInfo.En_Name           = dr["En_Name"].ToString();
                            InstituteInfo.InstituteKindName = dr["InstituteKindName"].ToString();


                            dataTable.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (rdr != null)
                    {
                        rdr.Close();
                        rdr = null;
                    }
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Dispose();
                        conn.Close();
                    }
                    ViewModel.ViewBagError viewbagerror = new ViewModel.ViewBagError();
                    viewbagerror.ClassName = "alert-danger";
                    viewbagerror.Msg       = "خطا در لود اطلاعات آموزشگاه : " + ex.Message;
                    ViewBag.ErrorMsg       = viewbagerror;
                }

                #endregion
                //--------------------- Get Institute Info ------
                //============================================================


                if (InstituteInfo.name != null)
                {
                    //============================================================
                    //--------------------- Get Institute Grades ------
                    List <Grade> InstituteGrades = new List <Grade>();
                    #region Get Institute Grades
                    try
                    {
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }

                        SqlCommand cmd = new SqlCommand(@"select Grades.id,Grades.Name
	                    from Institute_Grade 
                    inner join Grades ON
	                    Institute_Grade.Instituteid=@id
	                    AND Grades.id = Institute_Grade.Gradeid "    , conn);


                        cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.BigInt));
                        cmd.Parameters["@id"].Value = id;

                        rdr = cmd.ExecuteReader();
                        DataTable dataTable = new DataTable();

                        dataTable.Load(rdr);

                        if (dataTable != null)
                        {
                            if (dataTable.Rows.Count > 0)
                            {
                                InstituteGrades = (from DataRow dr in dataTable.Rows
                                                   select new Grade()
                                {
                                    id = int.Parse(dr["id"].ToString()),
                                    Name = dr["Name"].ToString()
                                }
                                                   ).ToList();
                                ViewBag.InstituteGrades = InstituteGrades;
                                dataTable.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (rdr != null)
                        {
                            rdr.Close();
                            rdr = null;
                        }
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Dispose();
                            conn.Close();
                        }
                        ViewModel.ViewBagError viewbagerror = new ViewModel.ViewBagError();
                        viewbagerror.ClassName = "alert-danger";
                        viewbagerror.Msg       = "خطا در لود پایه های تحصیلی آموزشگاه : " + ex.Message;
                        ViewBag.ErrorMsg       = viewbagerror;
                    }
                    #endregion
                    //--------------------- Get Institute Grades ------
                    //============================================================

                    try
                    {
                        ViewBag.Images = Directory.EnumerateFiles(Server.MapPath("~/Content/images/schools/" + id + ""))
                                         .Where(fn => Path.GetFileName(fn) != InstituteInfo.id + "-logo.png" &&
                                                Path.GetFileName(fn) != InstituteInfo.id + "-main.png" &&
                                                Path.GetFileName(fn) != InstituteInfo.id + "-head.png"
                                                )
                                         .Select(fn => "~/Content/images/schools/" + id + "/" + Path.GetFileName(fn));
                    }
                    catch (Exception ex)
                    {
                        ;
                    }
                }



                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Dispose();
                    conn.Close();
                }

                return(View(InstituteInfo));
            }

            return(View());
        }
コード例 #4
0
        public ActionResult Index()
        {
            App_Start.ConnectionString constr = new App_Start.ConnectionString();
            ConnectionString = constr.GetConnectionString();
            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlDataReader rdr  = null;

            //============================================================
            //------------- Get Institute 4 Selected In Home ---------
            List <ViewModel.InstituteSmallVM> InstituteList = new List <ViewModel.InstituteSmallVM>();

            #region Get Institute 4 Selected In Home
            try

            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                string query = "";

                query = @"select top 4 id,name,En_Name
			            ,address,boyOrGirl,(select Name from InstituteKind where InstituteKind.id=Institutes.InstituteKindid ) as InstituteKindName 
			            from Institutes
			            where
			            (Active is null or Active =1 )
			            order by [order]"            ;

                SqlCommand cmd = new SqlCommand(query, conn);

                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();

                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        InstituteList = (from DataRow dr in dataTable.Rows
                                         select new ViewModel.InstituteSmallVM()
                        {
                            id = Int64.Parse(dr["id"].ToString()),
                            name = dr["name"].ToString(),
                            En_Name = dr["En_Name"].ToString(),
                            InstituteKindName = dr["InstituteKindName"].ToString(),
                            address = dr["address"].ToString(),
                            boyOrGirl = dr["boyOrGirl"].ToString() != "" ? bool.Parse(dr["boyOrGirl"].ToString()) : (bool?)null
                        }
                                         ).ToList();
                        dataTable.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            #endregion
            //------------- Get Institute 4 Selected In Home ---------
            //============================================================
            return(View(InstituteList));
        }
コード例 #5
0
        public ActionResult InstituteList(string boy, string girl, int?ostan_code, int?city_code, int?zone_code, string search_text, int?page)
        {
            int Startindex = 0;
            int pagesize   = 1;

            page       = page.HasValue ? Convert.ToInt32(page) - 1 : 0;
            Startindex = page.HasValue ? Convert.ToInt32(page * pagesize) : 0;
            //pageIndex = string.IsNullOrEmpty(ViewBag.page) ? pageIndex : Convert.ToInt32(ViewBag.page);

            App_Start.ConnectionString constr = new App_Start.ConnectionString();
            ConnectionString = constr.GetConnectionString();
            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlDataReader rdr  = null;

            // ----------  boy --------------
            if (boy == null)
            {
                boy = "1";
            }

            //---------- girl  ---------------
            if (girl == null)
            {
                girl = "1";
            }

            //===================================================================
            //-------------------  Configure City institute ---------------------
            #region Configure City institute
            string city = "";
            StringClass_Convert stringclass = new StringClass_Convert();
            if (ostan_code != 0)
            {
                city = stringclass.Convert_to_4str(ostan_code);
                if (city_code != 0)
                {
                    city = city + stringclass.Convert_to_4str(city_code);
                    if (zone_code != 0)
                    {
                        city = city + stringclass.Convert_to_4str(zone_code);
                    }
                }
            }
            else
            {
                city = "";
            }
            #endregion Configure City institute
            //-------------------  Configure City institute ---------------------
            //===================================================================


            //===================================================================
            //-------------- Boyor Girl Analyze ----------
            #region Boy Or Girl Analyze

            string boyorgirl = "";
            if (boy == "1" && girl == "0")
            {
                boyorgirl = "1";
            }
            else if (boy == "0" && girl == "1")
            {
                boyorgirl = "0";
            }
            else if (boy == "1" && girl == "1")
            {
                boyorgirl = "01";
            }
            else if (boy == "0" && girl == "0")
            {
                boyorgirl = "00";
            }
            #endregion
            //-------------- Boyor Girl Analyze ----------
            //===================================================================

            int Total_item   = 0;
            int Total_page   = 0;
            int?Current_page = page;



            //============================================================
            //------------------------ Get Institute List Filter ---------
            List <ViewModel.InstituteSmallVM> InstituteList = new List <ViewModel.InstituteSmallVM>();
            #region Get Institute List Filter
            try

            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                string query = "";
                #region Search Query
                query = @"select * from
                        (
                        SELECT        Institutes.id, Institutes.name,Institutes.En_Name, Institutes.[address],Institutes.boyOrGirl,Institutes.[order],
				                        (select InstituteKind.Name from InstituteKind where InstituteKind.id=Institutes.InstituteKindid) as InstituteKindName,
				                        ROW_NUMBER() OVER(order by Institutes.[order]) AS rownum
				
                        FROM            Institutes 
				                        where 
					                        Institutes.name like @name
					                        and (Institutes.Active is null or Institutes.Active =1)
					                        and Institutes.city_code like @city_code "                    ;
                if (boyorgirl == "1")
                {
                    query += @"and (Institutes.boyOrGirl = 1  )";
                }
                else if (boyorgirl == "0")
                {
                    query += @"and (Institutes.boyOrGirl = 0  )";
                }
                else if (boyorgirl == "01")
                {
                    query += @"and (Institutes.boyOrGirl=1 or Institutes.boyOrGirl=0 or Institutes.boyOrGirl is  null  )";
                }
                else if (boyorgirl == "00")
                {
                    query += @"";
                }
                query += @") as Tbl_Institute
		
		                        where (Tbl_Institute.rownum>@CurrentPage and
				                        Tbl_Institute.rownum<=(@CurrentPage+@PageSize))
				                        order by [order]"                ;


                #endregion

                SqlCommand cmd = new SqlCommand(query, conn);

                cmd.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 50));
                if (search_text != null)
                {
                    cmd.Parameters["@name"].Value = "%" + search_text + "%";
                }
                else
                {
                    cmd.Parameters["@name"].Value = "%" + "" + "%";
                }


                cmd.Parameters.Add(new SqlParameter("@city_code", SqlDbType.NVarChar, 50));
                cmd.Parameters["@city_code"].Value = city + "%";



                cmd.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int));
                cmd.Parameters["@PageSize"].Value = pagesize;

                cmd.Parameters.Add(new SqlParameter("@CurrentPage", SqlDbType.Int));
                cmd.Parameters["@CurrentPage"].Value = page;


                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();

                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        InstituteList = (from DataRow dr in dataTable.Rows
                                         select new ViewModel.InstituteSmallVM()
                        {
                            id = Int64.Parse(dr["id"].ToString()),
                            name = dr["name"].ToString(),
                            En_Name = dr["En_Name"].ToString(),
                            InstituteKindName = dr["InstituteKindName"].ToString(),
                            address = dr["address"].ToString(),
                            boyOrGirl = dr["boyOrGirl"].ToString() != "" ? bool.Parse(dr["boyOrGirl"].ToString()) : (bool?)null
                        }
                                         ).ToList();
                        dataTable.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            #endregion
            //------------------------ Get Institute List Filter ---------
            //============================================================

            //============================================================
            //-------------------- Get Total Item List Filter ---------
            #region Get Institute List Filter
            try

            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }


                string query = "";
                #region Search Query
                query = @"SELECT   count(*) as TotalItem
                        FROM            Institutes 
				                        where 
					                        Institutes.name like @name
					                        and (Institutes.Active is null or Institutes.Active =1)
					                        and Institutes.city_code like @city_code "                    ;
                if (boyorgirl == "1")
                {
                    query += @"and (Institutes.boyOrGirl = 1  )";
                }
                else if (boyorgirl == "0")
                {
                    query += @"and (Institutes.boyOrGirl = 0  )";
                }
                else if (boyorgirl == "01")
                {
                    query += @"and (Institutes.boyOrGirl=1 or Institutes.boyOrGirl=0 or Institutes.boyOrGirl is  null  )";
                }
                else if (boyorgirl == "00")
                {
                    query += @"";
                }


                #endregion

                SqlCommand cmd = new SqlCommand(query, conn);

                cmd.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 50));
                if (search_text != null)
                {
                    cmd.Parameters["@name"].Value = "%" + search_text + "%";
                }
                else
                {
                    cmd.Parameters["@name"].Value = "%" + "" + "%";
                }


                cmd.Parameters.Add(new SqlParameter("@city_code", SqlDbType.NVarChar, 50));
                cmd.Parameters["@city_code"].Value = city + "%";

                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();

                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        DataRow dr = dataTable.Rows[0];
                        Total_item = dr["TotalItem"].ToString() != "" ? int.Parse(dr["TotalItem"].ToString()) : 0;
                        dataTable.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            #endregion
            //------------------------ Get Institute List Filter ---------
            //============================================================
            if (rdr != null)
            {
                rdr.Close();
                rdr = null;
            }
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }

            Total_page = Total_item / pagesize;

            //==========================================
            //---------------- Set ViewBag -------------

            ViewBag.Total_item   = Total_item;
            ViewBag.Total_page   = Total_page;
            ViewBag.Current_page = Current_page;
            //---------------- Set ViewBag -------------
            //==========================================

            return(PartialView("~/Views/Shared/Partial/_InstituteList.cshtml", InstituteList));
        }
コード例 #6
0
        public ActionResult institutes()
        {
            App_Start.ConnectionString constr = new App_Start.ConnectionString();
            ConnectionString = constr.GetConnectionString();
            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlDataReader rdr  = null;

            //============================================================
            //--------------------- Get Cities ------
            List <City> tbl_ostan = new List <City>();

            #region Get Institute Cities
            try
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                SqlCommand cmd = new SqlCommand(@"select Code,Pname from Cities where Code=State_Code and (active is null or active =1) order by Code", conn);

                rdr = cmd.ExecuteReader();
                DataTable dataTable = new DataTable();

                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if (dataTable.Rows.Count > 0)
                    {
                        tbl_ostan = (from DataRow dr in dataTable.Rows
                                     select new City()
                        {
                            Code = int.Parse(dr["Code"].ToString()),
                            Pname = dr["Pname"].ToString()
                        }
                                     ).ToList();
                        ViewBag.ostanlist = tbl_ostan;
                        dataTable.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Dispose();
                    conn.Close();
                }
                ViewModel.ViewBagError viewbagerror = new ViewModel.ViewBagError();
                viewbagerror.ClassName = "alert-danger";
                viewbagerror.Msg       = "خطا در لود پایه های تحصیلی آموزشگاه : " + ex.Message;
                ViewBag.ErrorMsg       = viewbagerror;
            }
            #endregion
            //--------------------- Get Cities ------
            //============================================================


            if (rdr != null)
            {
                rdr.Close();
                rdr = null;
            }
            if (conn.State == ConnectionState.Open)
            {
                conn.Dispose();
                conn.Close();
            }

            ViewBag.Current_ostan = 0;

            return(View());
        }
コード例 #7
0
        public IHttpActionResult UserLogin(string Username, string Password)
        {
            if (Username != null && Password != null)
            {
                //=========================================================
                //-------------------- Get User Institute ------
                ViewModel.API.Login.LoginAPIResult CurrentLoginAPIResult = new ViewModel.API.Login.LoginAPIResult();
                #region Get User Institute

                string ConnectionString;
                App_Start.ConnectionString constr = new App_Start.ConnectionString();
                ConnectionString = constr.GetConnectionString();

                SqlConnection conn      = new SqlConnection(ConnectionString);
                SqlDataReader rdr       = null;
                SqlDataReader rdrClass  = null;
                SqlDataReader rdrAccess = null;



                try
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    SqlCommand cmd = new SqlCommand(@"SP_API_USER_Institutes", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.NVarChar));
                    cmd.Parameters["@Username"].Value = Username;

                    cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.NVarChar));
                    cmd.Parameters["@Password"].Value = Password;

                    rdr = cmd.ExecuteReader();

                    DataTable dataTable       = new DataTable();
                    DataTable dataTableClass  = new DataTable();
                    DataTable dataTableAccess = new DataTable();

                    dataTable.Load(rdr);

                    if (dataTable != null)
                    {
                        if ((dataTable.Rows.Count > 0))
                        {
                            DataRow dr = dataTable.Rows[0];

                            #region Get User Information

                            CurrentLoginAPIResult.Username  = Username;
                            CurrentLoginAPIResult.Password  = Password;
                            CurrentLoginAPIResult.Firstname = dr["firstname"].ToString();
                            CurrentLoginAPIResult.Lastname  = dr["lastname"].ToString();
                            CurrentLoginAPIResult.token     = NewTokenCode(Username, Password);


                            #endregion

                            //============================================================
                            //----------------- Get User Class Course -----
                            List <ViewModel.API.Login.classInfo> CurrentClassInfo = new List <ViewModel.API.Login.classInfo>();
                            #region Get User Class Course


                            try
                            {
                                cmd             = new SqlCommand(@"SP_API_CLASS_COURSE_USER", conn);
                                cmd.CommandType = CommandType.StoredProcedure;

                                cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.NVarChar));
                                cmd.Parameters["@Username"].Value = Username;
                                rdrClass = cmd.ExecuteReader();
                                dataTableClass.Load(rdrClass);

                                if (dataTableClass != null)
                                {
                                    if (dataTableClass.Rows.Count > 0)
                                    {
                                        foreach (DataRow itemclass in dataTableClass.Rows)
                                        {
                                            ViewModel.API.Login.classInfo myClassInfo = new ViewModel.API.Login.classInfo();

                                            myClassInfo.id             = int.Parse(itemclass["Calssid"].ToString());
                                            myClassInfo.Instituteid    = int.Parse(itemclass["Instituteid"].ToString());
                                            myClassInfo.name           = itemclass["Classname"].ToString();
                                            myClassInfo.courseTitle    = itemclass["Coursename"].ToString();
                                            myClassInfo.studentsNumber = itemclass["StudentNumber"].ToString() != "" ? int.Parse(itemclass["StudentNumber"].ToString()) : 0;


                                            CurrentClassInfo.Add(myClassInfo);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                var msg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                                {
                                    ReasonPhrase = "Internal Server Error!!!"
                                };
                                throw new HttpResponseException(msg);
                            }



                            #endregion
                            //----------------- Get User Class Course -----
                            //============================================================

                            //============================================================
                            //----------------- Get User Access -----
                            List <ViewModel.API.Login.AccessLevels> CurrentAccessLevels = new List <ViewModel.API.Login.AccessLevels>();
                            #region Get User Access

                            try
                            {
                                cmd             = new SqlCommand(@"SP_API_USER_ACCESS", conn);
                                cmd.CommandType = CommandType.StoredProcedure;

                                cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.NVarChar));
                                cmd.Parameters["@Username"].Value = Username;
                                rdrAccess = cmd.ExecuteReader();
                                dataTableAccess.Load(rdrAccess);

                                if (dataTableAccess != null)
                                {
                                    if (dataTableAccess.Rows.Count > 0)
                                    {
                                        foreach (DataRow itemaccess in dataTableAccess.Rows)
                                        {
                                            ViewModel.API.Login.AccessLevels myAccess = new ViewModel.API.Login.AccessLevels();

                                            myAccess.Accessid    = int.Parse(itemaccess["Accessid"].ToString());
                                            myAccess.caption     = itemaccess["caption"].ToString();
                                            myAccess.Instituteid = int.Parse(itemaccess["Instituteid"].ToString());

                                            CurrentAccessLevels.Add(myAccess);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                var msg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                                {
                                    ReasonPhrase = "Internal Server Error!!!"
                                };
                                throw new HttpResponseException(msg);
                            }

                            #endregion
                            //----------------- Get User Access -----
                            //============================================================

                            CurrentLoginAPIResult.jobs = new List <ViewModel.API.Login.job>();
                            #region Get User Jobs
                            foreach (DataRow item in dataTable.Rows)
                            {
                                ViewModel.API.Login.job Currentjob = new ViewModel.API.Login.job();
                                #region Get Job Name
                                byte Manager_Teacher_Student_Parent = byte.Parse(item["Manager_Teacher_Student_Parent"].ToString());
                                if (Manager_Teacher_Student_Parent == 0)
                                {
                                    Currentjob.name = "Manager";
                                }
                                else if (Manager_Teacher_Student_Parent == 1)
                                {
                                    Currentjob.name = "Teacher";
                                }
                                else if (Manager_Teacher_Student_Parent == 2)
                                {
                                    Currentjob.name = "Student";
                                }
                                else if (Manager_Teacher_Student_Parent == 3)
                                {
                                    Currentjob.name = "Parent";
                                }
                                else if (Manager_Teacher_Student_Parent == 4)
                                {
                                    Currentjob.name = "Employee";
                                }
                                #endregion


                                Currentjob.schools = new List <ViewModel.API.Login.School>();


                                ViewModel.API.Login.School CurrentSchool = new ViewModel.API.Login.School();
                                #region Get School Info
                                CurrentSchool.id = int.Parse(item["Instituteid"].ToString());

                                CurrentSchool.name = item["name"].ToString();
                                #endregion

                                CurrentSchool.classes = new List <ViewModel.API.Login.classInfo>();



                                #region Set ClassInfo School
                                List <ViewModel.API.Login.classInfo> CurrentClassInfo_CurrentInstitute = CurrentClassInfo.Where(p => p.Instituteid == CurrentSchool.id).ToList();

                                foreach (var itemcalssinfo in CurrentClassInfo_CurrentInstitute)
                                {
                                    CurrentSchool.classes.Add(itemcalssinfo);
                                }
                                #endregion

                                Currentjob.schools.Add(CurrentSchool);


                                Currentjob.accesseLevels = new List <ViewModel.API.Login.AccessLevels>();

                                List <ViewModel.API.Login.AccessLevels> CurrentAccess = CurrentAccessLevels.Where(p => p.Instituteid == CurrentSchool.id).ToList();
                                #region Set AccessLevel Job
                                foreach (var itemaccess in CurrentAccess)
                                {
                                    Currentjob.accesseLevels.Add(itemaccess);
                                }
                                #endregion



                                CurrentLoginAPIResult.jobs.Add(Currentjob);
                            }

                            #endregion
                        }
                        else
                        {
                            var msg = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                            {
                                ReasonPhrase = "Username Or Password Is Not Valid!!!"
                            };
                            throw new HttpResponseException(msg);
                        }
                    }
                    else
                    {
                        var msg = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                        {
                            ReasonPhrase = "Username Or Password Is Not Valid!!!"
                        };
                        throw new HttpResponseException(msg);
                    }
                }
                catch (Exception ex)
                {
                    var msg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        ReasonPhrase = "Internal Server Error!!!"
                    };
                    throw new HttpResponseException(msg);
                }

                #endregion
                //-------------------- Get User Institute ------
                //=========================================================

                return(Ok(CurrentLoginAPIResult));
            }

            else
            {
                var msg = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    ReasonPhrase = "Username Or Password Is Not Valid!!!"
                };
                throw new HttpResponseException(msg);
            }
        }
コード例 #8
0
        public IHttpActionResult ListSchoolInfo()
        {
            List <ViewModel.API.School> SchoolInfoList = new List <ViewModel.API.School>();


            string ConnectionString;

            App_Start.ConnectionString constr = new App_Start.ConnectionString();
            ConnectionString = constr.GetConnectionString();

            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlDataReader rdr  = null;

            //===========================================================================
            //------------------------------- Get Cities -----------
            List <Models.City> Cities = new List <Models.City>();

            #region Get Cities
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                SqlCommand cmd = new SqlCommand(@"select * from Cities where (active =1 or active is null)", conn);


                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();

                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if ((dataTable.Rows.Count > 0))
                    {
                        Cities = (from DataRow dr in dataTable.Rows
                                  select new Models.City()
                        {
                            Code = Convert.ToInt32(dr["Code"].ToString()),
                            State_Code = Convert.ToInt32(dr["State_Code"].ToString()),
                            Pname = dr["Pname"].ToString(),
                            Ename = dr["Ename"].ToString(),
                        }
                                  ).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                var msg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    ReasonPhrase = "Internal Server Error!!!"
                };
                throw new HttpResponseException(msg);
            }
            #endregion
            //------------------------------- Get Cities -----------
            //===========================================================================


            //===========================================================================
            //------------------------------- Get CityZones -----------
            List <Models.CityZone> CityZones = new List <Models.CityZone>();
            #region Get CityZones
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                SqlCommand cmd = new SqlCommand(@"select * from CityZones where (active =1 or active is null)", conn);


                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();


                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if ((dataTable.Rows.Count > 0))
                    {
                        CityZones = (from DataRow dr in dataTable.Rows
                                     select new Models.CityZone()
                        {
                            Code = Convert.ToInt32(dr["Code"].ToString()),
                            Zone_Code = Convert.ToInt32(dr["Zone_Code"].ToString()),
                            Pname = dr["Pname"].ToString(),
                            Ename = dr["Ename"].ToString(),
                        }
                                     ).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                var msg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    ReasonPhrase = "Internal Server Error!!!"
                };
                throw new HttpResponseException(msg);
            }
            #endregion
            //------------------------------- Get Cities -----------
            //===========================================================================



            //===========================================================================
            //------------------------------- Get School List -----

            #region Get School List



            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                SqlCommand cmd = new SqlCommand(@"select id,name,address,city_code,tel1,En_Name,Description,boyOrGirl,Edit_Date from Institutes
	where (Active =1 or Active is null)"    , conn);


                rdr = cmd.ExecuteReader();

                DataTable dataTable = new DataTable();


                dataTable.Load(rdr);

                if (dataTable != null)
                {
                    if ((dataTable.Rows.Count > 0))
                    {
                        foreach (DataRow item in dataTable.Rows)
                        {
                            ViewModel.API.School CurrentSchool = new ViewModel.API.School();

                            CurrentSchool.about   = item["Description"].ToString();
                            CurrentSchool.address = item["address"].ToString();

                            bool gender = item["boyOrGirl"].ToString() != "" ? bool.Parse(item["boyOrGirl"].ToString()) : true;
                            if (gender == true)
                            {
                                CurrentSchool.gender = "پسرانه";
                            }
                            else
                            {
                                CurrentSchool.gender = "دخترانه";
                            }

                            CurrentSchool.id            = int.Parse(item["id"].ToString());
                            CurrentSchool.lastRefreshed = item["Edit_Date"].ToString() != null ? item["Edit_Date"].ToString() : "";
                            //CurrentSchool.liked = "";
                            CurrentSchool.phoneNumber = item["tel1"].ToString();
                            CurrentSchool.schoolName  = item["name"].ToString();

                            string url = "";
                            if (item["En_Name"].ToString() != "")
                            {
                                url = "http://egbaliye.forooshgahyas.ir/Content/images/schools/" + CurrentSchool.id + "/" + item["En_Name"].ToString() + "-main.JPG";
                            }
                            CurrentSchool.imageUrl = url;

                            int Zone_Code = 0, Code = 0, State_Code = 0;

                            #region Analyze CityCode
                            if (item["city_code"].ToString() != "")
                            {
                                string CityCode = item["city_code"].ToString();

                                if (CityCode.Length >= 4)
                                {
                                    string provinceCode = CityCode.Substring(0, 4);

                                    if (provinceCode != "")
                                    {
                                        Code = int.Parse(provinceCode);


                                        if (CityCode.Length >= 8)
                                        {
                                            string townCode = CityCode.Substring(4, 4);

                                            if (townCode != "")
                                            {
                                                State_Code = int.Parse(townCode);


                                                if (CityCode.Length >= 12)
                                                {
                                                    string regionCode = CityCode.Substring(8, 4);
                                                    if (regionCode != "")
                                                    {
                                                        Zone_Code = int.Parse(regionCode);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion


                            Models.City CurrentCity = Cities.Where(p => p.Code == Code && p.State_Code == Code).FirstOrDefault();

                            if (CurrentCity != null)
                            {
                                CurrentSchool.province = CurrentCity.Pname;
                            }

                            CurrentCity = Cities.Where(p => p.Code == State_Code && p.State_Code == Code).FirstOrDefault();

                            if (CurrentCity != null)
                            {
                                CurrentSchool.town = CurrentCity.Pname;
                            }

                            Models.CityZone myzone = CityZones.Where(p => p.Code == State_Code && p.Zone_Code == Zone_Code).FirstOrDefault();
                            if (myzone != null)
                            {
                                CurrentSchool.region = myzone.Zone_Code;
                            }


                            SchoolInfoList.Add(CurrentSchool);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (rdr != null)
                {
                    rdr.Close();
                    rdr = null;
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                var msg = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    ReasonPhrase = "Internal Server Error!!!"
                };
                throw new HttpResponseException(msg);
            }



            #endregion
            //------------------------------- Get School List -----
            //===========================================================================
            if (rdr != null)
            {
                rdr.Close();
                rdr = null;
            }
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }

            return(Ok(SchoolInfoList));
        }
コード例 #9
0
        public ActionResult Employee_list(int?page)
        {
            int pageIndex = 1;
            int pagesize  = 2;

            pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
            IPagedList <ViewModel.EmployeeList_VM> result = null;

            User userinfo = (User)Session["User"];

            #region Get Session
            ViewModel.Institute_Info_Session_VM Institute_info_Session = new ViewModel.Institute_Info_Session_VM();
            if (Session["Institute_info"] != null)
            {
                Institute_info_Session = (ViewModel.Institute_Info_Session_VM)Session["Institute_info"];
            }
            else
            {
                Institute_info_Session = null;
            }

            #endregion

            if (Institute_info_Session != null)
            {
                App_Start.ConnectionString constr = new App_Start.ConnectionString();
                ConnectionString = constr.GetConnectionString();
                SqlConnection conn = new SqlConnection(ConnectionString);
                SqlDataReader rdr  = null;

                //============================================================
                //--------------------- Get Employee List in Class id ---

                List <ViewModel.EmployeeList_VM> EmployeeList = new List <ViewModel.EmployeeList_VM>();
                #region Get Employee List in Institute id
                try
                {
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    SqlCommand cmd = new SqlCommand(@"select              Users.username,Users.firstname,Users.lastname,Users.gender,
					
					case 
						When User_Jobs.Jobid = 1 Then Users.Manager_Code
						When User_Jobs.Jobid = 2 Then Users.Teacher_Code
						When User_Jobs.Jobid = 5 Then Users.Employe_Code
					End as Code
					,
	                (select Jobs.Name from Jobs where Jobs.id = User_Jobs.Jobid) as JobName
                from User_Jobs
	                inner join Users On
		                User_Jobs.Instituteid =@Instituteid
		                and (User_Jobs.Jobid != 3 and User_Jobs.Jobid != 4)
		                and Users.username like User_Jobs.Username
                ", conn);


                    cmd.Parameters.Add(new SqlParameter("@Instituteid", SqlDbType.Int));
                    cmd.Parameters["@Instituteid"].Value = Institute_info_Session.id;

                    rdr = cmd.ExecuteReader();
                    DataTable dataTable = new DataTable();

                    dataTable.Load(rdr);

                    if (dataTable != null)
                    {
                        if (dataTable.Rows.Count > 0)
                        {
                            EmployeeList = (from DataRow dr in dataTable.Rows
                                            select new ViewModel.EmployeeList_VM()
                            {
                                username = dr["username"].ToString(),
                                firstname = dr["firstname"].ToString(),
                                lastname = dr["lastname"].ToString(),
                                gender = dr["gender"].ToString() != "" ? bool.Parse(dr["gender"].ToString()) : (bool?)null,
                                Code = dr["Code"].ToString(),
                                JobName = dr["JobName"].ToString()
                            }
                                            ).ToList();
                            dataTable.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (rdr != null)
                    {
                        rdr.Close();
                        rdr = null;
                    }
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Dispose();
                        conn.Close();
                    }
                    ViewModel.ViewBagError viewbagerror = new ViewModel.ViewBagError();
                    viewbagerror.ClassName = "alert-danger";
                    viewbagerror.Msg       = "خطا در لود لیست کارمندان : " + ex.Message;
                    ViewBag.ErrorMsg       = viewbagerror;
                }
                #endregion
                //--------------------- Get Employee List in Class id ---
                //============================================================
                result = EmployeeList.ToPagedList(pageIndex, pagesize);
                return(View("~/Views/maindashboard/Employee/Employeelist.cshtml", result));
            }

            else
            {
                ViewModel.ViewBagError viewbagerror = new ViewModel.ViewBagError();
                viewbagerror.ClassName = "alert-danger";
                viewbagerror.Msg       = "شناسه آموزشگاه صحیح نیست.";
                ViewBag.ErrorMsg       = viewbagerror;
                return(View("~/Views/maindashboard/Employee/Employeelist.cshtml"));
            }
        }
コード例 #10
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (Need)
            {
                string query = actionContext.Request.RequestUri.Query;

                var accessToken = HttpContext.Current;
                var TokenCode   = accessToken.Request.Headers["Authorization"];
                if (TokenCode != null)
                {
                    string t = TokenCode.Replace("Bearer ", "");
                    TokenCode = t;
                }



                //====================================================================
                //---------------------- Get Information For APILog ---------------------

                #region Get Information For Log
                string actionName     = actionContext.ActionDescriptor.ActionName;
                string controllerName = actionContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                var    values         = actionContext.ActionArguments.Values;

                string verb       = Convert.ToString(actionContext.ControllerContext.Request.Method);
                string routevalue = "";

                string querrystring = string.Empty;


                for (int i = 0; i < values.Count(); i++)
                {
                    if (values.ElementAt(i) != null)
                    {
                        var item = HttpContext.Current.Request.QueryString.Keys[i];

                        string name  = values.ElementAt(i).ToString();
                        string value = values.ElementAt(i).ToString();
                        routevalue = routevalue + item + "=" + value;
                    }

                    if (i + 1 < values.Count)
                    {
                        routevalue = routevalue + "&";
                    }
                }

                string ip = GetClientIpAddress(actionContext.Request);

                string browser = GetBrowser(actionContext.Request);
                string OS      = GetClientOS(actionContext.Request);

                string Description = null;


                var context = actionContext.RequestContext;



                #endregion Get Information For Log



                //---------------------- Get Information For Log ---------------------
                //====================================================================

                //====================================================================
                //----------------------- Insert Log to Tbl APILog ----------------------
                #region Insert Log to Tbl APILog
                string ConnectionString;
                App_Start.ConnectionString constr = new App_Start.ConnectionString();
                ConnectionString = constr.GetConnectionString();

                // 1. Instantiate the connection
                SqlConnection conn = new SqlConnection(ConnectionString);



                try
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(@"INSERT INTO APILogs
                              (Controller, Action, IP, Date, OS, Browser, Description,TokenCode)
                VALUES        (@Controller, @Action, @IP, @Date, @OS, @Browser, @Description,@TokenCode)", conn);

                    cmd.Parameters.Add(new SqlParameter("@Controller", SqlDbType.NVarChar, 50));
                    cmd.Parameters["@Controller"].Value = controllerName;

                    cmd.Parameters.Add(new SqlParameter("@Action", SqlDbType.NVarChar, 50));
                    cmd.Parameters["@Action"].Value = actionName + " - " + routevalue;

                    cmd.Parameters.Add(new SqlParameter("@IP", SqlDbType.NVarChar, 50));
                    cmd.Parameters["@IP"].Value = ip;

                    cmd.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
                    cmd.Parameters["@Date"].Value = DateTime.Now;

                    cmd.Parameters.Add(new SqlParameter("@OS", SqlDbType.NVarChar, 50));
                    if (OS != null)
                    {
                        cmd.Parameters["@OS"].Value = OS;
                    }
                    else
                    {
                        cmd.Parameters["@OS"].Value = DBNull.Value;
                    }


                    cmd.Parameters.Add(new SqlParameter("@Browser", SqlDbType.NVarChar, 50));
                    if (OS != null)
                    {
                        cmd.Parameters["@Browser"].Value = browser;
                    }
                    else
                    {
                        cmd.Parameters["@Browser"].Value = DBNull.Value;
                    }


                    cmd.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar));
                    if (Description != null)
                    {
                        cmd.Parameters["@Description"].Value = Description;
                    }
                    else
                    {
                        cmd.Parameters["@Description"].Value = DBNull.Value;
                    }


                    cmd.Parameters.Add(new SqlParameter("@TokenCode", SqlDbType.NVarChar));
                    if (TokenCode != null)
                    {
                        cmd.Parameters["@TokenCode"].Value = TokenCode;
                    }
                    else
                    {
                        cmd.Parameters["@TokenCode"].Value = DBNull.Value;
                    }



                    cmd.ExecuteNonQuery();


                    conn.Close();
                }
                catch (Exception ex)
                {
                    conn.Close();
                }
                #endregion Insert Log to Tbl Log
                //----------------------- Insert Log to Tbl Log ----------------------
                //====================================================================
            }
            base.OnActionExecuting(actionContext);
        }
コード例 #11
0
        public ActionResult Index(string username, string password)
        {
            if (username != null && password != null)
            {
                App_Start.ConnectionString constr = new App_Start.ConnectionString();
                ConnectionString = constr.GetConnectionString();
                SqlConnection conn = new SqlConnection(ConnectionString);
                SqlDataReader rdr  = null;


                try
                {
                    //=====================================
                    //------------ Get User Info --------
                    User user = new User();
                    #region Get User Info
                    try
                    {
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }

                        SqlCommand cmd = new SqlCommand(@"select username,firstname,lastname,gender 
                                        from Users where username like @username and password like @password and (Active is null or Active =1 )
                                ", conn);

                        cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50));
                        cmd.Parameters["@username"].Value = username;

                        cmd.Parameters.Add(new SqlParameter("@password", SqlDbType.NVarChar));
                        cmd.Parameters["@password"].Value = password;

                        rdr = cmd.ExecuteReader();

                        DataTable dataTable = new DataTable();

                        dataTable.Load(rdr);

                        if (dataTable != null)
                        {
                            if (dataTable.Rows.Count > 0)
                            {
                                DataRow dr = dataTable.Rows[0];

                                user.username  = dr["username"].ToString();
                                user.firstname = dr["firstname"].ToString();
                                user.lastname  = dr["lastname"].ToString();
                                user.gender    = dr["gender"].ToString() != "" ? bool.Parse(dr["gender"].ToString()) :(bool?)null;

                                Session["User"] = user;
                                dataTable.Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (rdr != null)
                        {
                            rdr.Close();
                            rdr = null;
                        }
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Dispose();
                            conn.Close();
                        }
                    }
                    #endregion
                    //------------ Get User Info --------
                    //=====================================


                    if (user.username != null)
                    {
                        //=====================================
                        //------------ get user access --------
                        #region Get User Access
                        try
                        {
                            if (conn.State != ConnectionState.Open)
                            {
                                conn.Open();
                            }

                            SqlCommand cmd = new SqlCommand(@"select Accesses.caption,Accesses.Instituteid 
		                                from UserAccesses 
	                                inner join Accesses ON
		                                UserAccesses.Username like @username
		                                and Accesses.id=UserAccesses.id 
		                                and (Accesses.Active is null or Accesses.Active=1)
                                ", conn);

                            cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50));
                            cmd.Parameters["@username"].Value = username;

                            rdr = cmd.ExecuteReader();

                            DataTable dataTable = new DataTable();

                            dataTable.Load(rdr);

                            if (dataTable != null)
                            {
                                if (dataTable.Rows.Count > 0)
                                {
                                    List <Access> accesses = new List <Access>();
                                    accesses = (from DataRow dr in dataTable.Rows
                                                select new Access()
                                    {
                                        caption = dr["caption"].ToString(),
                                        Instituteid = int.Parse(dr["Instituteid"].ToString())
                                    }
                                                ).ToList();
                                    Session["Access"] = accesses;
                                    dataTable.Dispose();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (rdr != null)
                            {
                                rdr.Close();
                                rdr = null;
                            }
                            if (conn.State == ConnectionState.Open)
                            {
                                conn.Dispose();
                                conn.Close();
                            }
                        }
                        #endregion
                        //------------ get user access --------
                        //=====================================

                        //=====================================
                        //------------ get user job -----------
                        #region User Jobs

                        try
                        {
                            if (conn.State != ConnectionState.Open)
                            {
                                conn.Open();
                            }

                            SqlCommand cmd = new SqlCommand(@"select Jobs.id,Jobs.Caption,User_Jobs.Instituteid from User_Jobs 
	                                        inner join Jobs ON
		                                        User_Jobs.Username like @Username
		                                        and Jobs.id = User_Jobs.Jobid
		                                        and (Jobs.Active is null or Jobs.Active =1)
                                ", conn);

                            cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.NVarChar, 50));
                            cmd.Parameters["@Username"].Value = username;

                            rdr = cmd.ExecuteReader();

                            DataTable dataTable = new DataTable();

                            dataTable.Load(rdr);

                            if (dataTable != null)
                            {
                                if (dataTable.Rows.Count > 0)
                                {
                                    List <ViewModel.User_Jobs_VM> jobs = new List <ViewModel.User_Jobs_VM>();
                                    jobs = (from DataRow dr in dataTable.Rows
                                            select new ViewModel.User_Jobs_VM()
                                    {
                                        id = Int64.Parse(dr["id"].ToString()),
                                        Caption = dr["Caption"].ToString(),
                                        Instituteid = Int64.Parse(dr["Instituteid"].ToString())
                                    }
                                            ).ToList();
                                    Session["Job"] = jobs;
                                    dataTable.Dispose();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (rdr != null)
                            {
                                rdr.Close();
                                rdr = null;
                            }
                            if (conn.State == ConnectionState.Open)
                            {
                                conn.Dispose();
                                conn.Close();
                            }
                        }

                        #endregion
                        //------------ get user job -----------
                        //=====================================


                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.result = "نام کاربری یا رمز عبور صحیح نیست .";
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.result = "سیستم با خطا مواجه شد .";
                }
            }
            return(View("Index", null));
        }