public DataSourceResult GetPage(int page, int pageSize, string whereCondition, string userID)
        {
            List <SqlParameter> param = new List <SqlParameter>();

            param.Add(new SqlParameter("@Page", page));
            param.Add(new SqlParameter("@PageSize", pageSize));
            param.Add(new SqlParameter("@WhereCondition", whereCondition));
            param.Add(new SqlParameter("@UserID", userID));
            DataTable dt  = new SqlHelper().ExecuteQuery("p_Master_Announcement_Select_By_Page", param);
            var       lst = new List <Master_Announcement>();

            foreach (DataRow row in dt.Rows)
            {
                var item = new Master_Announcement();
                item.AnnouncementID = !row.IsNull("AnnouncementID") ? Convert.ToInt32(row["AnnouncementID"].ToString()): 0;
                item.Title          = !row.IsNull("Title") ? row["Title"].ToString() : "";
                item.HTMLContent    = !row.IsNull("HTMLContent") ? row["HTMLContent"].ToString() : "";
                item.TextContent    = !row.IsNull("TextContent") ? row["TextContent"].ToString() : "";
                item.Status         = !row.IsNull("Status") ? Convert.ToBoolean(row["Status"]) : false;
                item.CreatedAt      = !row.IsNull("CreatedAt") ? DateTime.Parse(row["CreatedAt"].ToString()) : DateTime.Parse("01/01/1900");
                item.CreatedBy      = !row.IsNull("CreatedBy") ? row["CreatedBy"].ToString() : "";

                //reference
                lst.Add(item);
            }
            DataSourceResult result = new DataSourceResult();

            result.Data  = lst;
            result.Total = dt.Rows.Count > 0 ? Convert.ToInt32(dt.Rows[0]["RowCount"]) : 0;
            return(result);
        }
Beispiel #2
0
 public ActionResult Partial()
 {
     if (userAsset.ContainsKey("View") && userAsset["View"])
     {
         IDbConnection dbConn = new OrmliteConnection().openConn();
         var dict = new Dictionary<string, object>();
         dict["asset"] = userAsset;
         dict["activestatus"] = new CommonLib().GetActiveStatus();
         ViewData["listConfig_Announcement"] = new Master_Announcement().GetAllSort("", "CreatedAt", "DESC");
         dbConn.Close();
         return PartialView("_Home", dict);
     }
     else
         return RedirectToAction("LogOn", "Account");
 }
        public List <Master_Announcement> GetAllSort(string whereCondition, string orderBy, string ordervalue)
        {
            List <SqlParameter> param = new List <SqlParameter>();

            param.Add(new SqlParameter("@OrderBy", orderBy));
            param.Add(new SqlParameter("@Ordervalue", ordervalue));
            param.Add(new SqlParameter("@WhereCondition", whereCondition));
            DataTable dt  = new SqlHelper().ExecuteQuery("p_Master_Announcement_SelectAll", param);
            var       lst = new List <Master_Announcement>();

            foreach (DataRow row in dt.Rows)
            {
                var item = new Master_Announcement();
                item.AnnouncementID = !row.IsNull("AnnouncementID") ? Convert.ToInt32(row["AnnouncementID"].ToString()) : 0;
                item.Title          = !row.IsNull("Title") ? row["Title"].ToString() : "";
                item.HTMLContent    = !row.IsNull("HTMLContent") ? row["HTMLContent"].ToString() : "";
                item.TextContent    = !row.IsNull("TextContent") ? row["TextContent"].ToString() : "";
                item.Status         = !row.IsNull("Status") ? Convert.ToBoolean(row["Status"]) : false;
                item.HTMLContent    = !row.IsNull("HTMLContent") ? row["HTMLContent"].ToString() : "";
                item.CreatedAt      = !row.IsNull("CreatedAt") ? DateTime.Parse(row["CreatedAt"].ToString()) : DateTime.Parse("01/01/1900");
                item.CreatedBy      = !row.IsNull("CreatedBy") ? row["CreatedBy"].ToString() : "";
                lst.Add(item);

                //reference
                DateTime dateNow    = DateTime.Now;
                DateTime dateCreate = !row.IsNull("CreatedAt") ? DateTime.Parse(row["CreatedAt"].ToString()) : DateTime.Parse("01/01/1900");
                double   subdate    = dateNow.Subtract(dateCreate).TotalDays;
                if (subdate <= 7)
                {
                    item.isNewPost = true;
                }
                else
                {
                    item.isNewPost = false;
                }
                item.UserName         = !row.IsNull("UserName") ? row["UserName"].ToString() : "";
                item.DateFormatString = String.Format("{0:dd/MM/yyyy}", dateCreate);
            }

            return(lst);
        }
        public ActionResult Create(Master_Announcement item)
        {
            //if (form.AllKeys.Contains("TextContent"))
            //{
            //    item.TextContent = form.Get("TextContent");
            //}

            //CHECK IS NULL VALUE
            if (string.IsNullOrEmpty(item.TextContent))
            {
                item.TextContent = "";
            }
            if (string.IsNullOrEmpty(item.HTMLContent))
            {
                item.HTMLContent = "";
            }
            if (string.IsNullOrEmpty(item.Title))
            {
                item.Title = "";
            }

            IDbConnection dbConn = new OrmliteConnection().openConn();

            try
            {
                    var isExist = dbConn.GetByIdOrDefault<Master_Announcement>(item.AnnouncementID);

                    if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null)
                    {
                        if (isExist != null)
                        {
                            return Json(new { success = false, message = "Đối tượng này đã tồn tại." });
                        }
                        item.CreatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;

                        dbConn.Insert<Master_Announcement>(item);
                        long lastInsertId = dbConn.GetLastInsertId();
                        dbConn.Close();
                        return Json(new { success = true, AnnouncementID = lastInsertId, createdat = item.CreatedAt, createdby = item.CreatedBy });
                    }
                    else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null)
                    {
                        item.UpdatedAt = DateTime.Now;
                        item.CreatedBy = currentUser.UserID;
                        dbConn.Update<Master_Announcement>(item);
                        dbConn.Close();
                        return Json(new { success = true });
                    }
                    else
                        return Json(new { success = false, message = "You don't have permission" });
            }
            catch (Exception ex)
            {
                log.Error("AD_Announcement - Create - " + ex.Message);
                return Json(new { success = false, message = ex.Message });
            }
            finally
            {
                dbConn.Close();
            }
        }
 public ActionResult Read([DataSourceRequest]DataSourceRequest request)
 {
     log4net.Config.XmlConfigurator.Configure();
     string whereCondition = "";
     if (request.Filters.Count > 0)
     {
         whereCondition = " AND " + new KendoApplyFilter().ApplyFilter(request.Filters[0]);
     }
     var data = new Master_Announcement().GetPage(request.Page, request.PageSize, whereCondition, currentUser.UserID);
     return Json(data);
 }
        public List<Master_Announcement> GetAllSort(string whereCondition,string orderBy, string ordervalue)
        {
            List<SqlParameter> param = new List<SqlParameter>();
            param.Add(new SqlParameter("@OrderBy", orderBy));
            param.Add(new SqlParameter("@Ordervalue", ordervalue));
            param.Add(new SqlParameter("@WhereCondition", whereCondition));
            DataTable dt = new SqlHelper().ExecuteQuery("p_Master_Announcement_SelectAll", param);
            var lst = new List<Master_Announcement>();
            foreach (DataRow row in dt.Rows)
            {
                var item = new Master_Announcement();
                item.AnnouncementID = !row.IsNull("AnnouncementID") ? Convert.ToInt32(row["AnnouncementID"].ToString()) : 0;
                item.Title = !row.IsNull("Title") ? row["Title"].ToString() : "";
                item.HTMLContent = !row.IsNull("HTMLContent") ? row["HTMLContent"].ToString() : "";
                item.TextContent = !row.IsNull("TextContent") ? row["TextContent"].ToString() : "";
                item.Status = !row.IsNull("Status") ? Convert.ToBoolean(row["Status"]) : false;
                item.HTMLContent = !row.IsNull("HTMLContent") ? row["HTMLContent"].ToString() : "";
                item.CreatedAt = !row.IsNull("CreatedAt") ? DateTime.Parse(row["CreatedAt"].ToString()) : DateTime.Parse("01/01/1900");
                item.CreatedBy = !row.IsNull("CreatedBy") ? row["CreatedBy"].ToString() : "";
                lst.Add(item);

                //reference
                DateTime dateNow = DateTime.Now;
                DateTime dateCreate = !row.IsNull("CreatedAt") ? DateTime.Parse(row["CreatedAt"].ToString()) : DateTime.Parse("01/01/1900");
                double subdate = dateNow.Subtract(dateCreate).TotalDays;
                if (subdate <= 7)
                {
                    item.isNewPost = true;
                }
                else
                {
                    item.isNewPost = false;
                }
                item.UserName = !row.IsNull("UserName") ? row["UserName"].ToString() : "";
                item.DateFormatString = String.Format("{0:dd/MM/yyyy}", dateCreate);
            }

            return lst;
        }
        public DataSourceResult GetPage(int page, int pageSize, string whereCondition, string userID)
        {
            List<SqlParameter> param = new List<SqlParameter>();
            param.Add(new SqlParameter("@Page", page));
            param.Add(new SqlParameter("@PageSize", pageSize));
            param.Add(new SqlParameter("@WhereCondition", whereCondition));
            param.Add(new SqlParameter("@UserID", userID));
            DataTable dt = new SqlHelper().ExecuteQuery("p_Master_Announcement_Select_By_Page", param);
            var lst = new List<Master_Announcement>();
            foreach (DataRow row in dt.Rows)
            {
                var item = new Master_Announcement();
                item.AnnouncementID =!row.IsNull("AnnouncementID") ? Convert.ToInt32( row["AnnouncementID"].ToString() ): 0;
                item.Title = !row.IsNull("Title") ? row["Title"].ToString() : "";
                item.HTMLContent = !row.IsNull("HTMLContent") ? row["HTMLContent"].ToString() : "";
                item.TextContent = !row.IsNull("TextContent") ? row["TextContent"].ToString() : "";
                item.Status = !row.IsNull("Status") ? Convert.ToBoolean(row["Status"]) : false;
                item.CreatedAt = !row.IsNull("CreatedAt") ? DateTime.Parse(row["CreatedAt"].ToString()) : DateTime.Parse("01/01/1900");
                item.CreatedBy = !row.IsNull("CreatedBy") ? row["CreatedBy"].ToString() : "";

                //reference
                lst.Add(item);
            }
            DataSourceResult result = new DataSourceResult();
            result.Data = lst;
            result.Total = dt.Rows.Count > 0 ? Convert.ToInt32(dt.Rows[0]["RowCount"]) : 0;
            return result;
        }