Beispiel #1
0
        public ActionResult Edit_Post(PostEditModel model)
        {
            try
            {
                var coverImg = string.Empty;
                if (model.Cover != null)
                {
                    if (model.Cover[0] != null)
                    {
                        var apiReturn = CdnServices.UploadImagesAsync(model.Cover, model.PostType.ToString(), "Post/Stories").Result;
                        if (apiReturn != null)
                        {
                            if (apiReturn.Data != null)
                            {
                                var resultData = JsonConvert.DeserializeObject <List <string> >(apiReturn.Data.ToString());
                                var returnData = new List <string>();
                                if (resultData.HasData())
                                {
                                    coverImg = resultData[0];
                                }
                            }
                        }
                    }
                }

                var postInfo = new IdentityPost();
                postInfo.Id           = model.Id;
                postInfo.Title        = model.Title;
                postInfo.BodyContent  = model.BodyContent;
                postInfo.Description  = model.Description;
                postInfo.PostType     = model.PostType;
                postInfo.CreatedBy    = User.Identity.GetUserId();
                postInfo.IsHighlights = model.IsHighlights;
                postInfo.Status       = model.Status;
                postInfo.UrlFriendly  = string.Format("{0}-{1}", UrlFriendly.ConvertToUrlFriendly(model.Title), EpochTime.GetIntDate(DateTime.Now).ToString());

                if (!string.IsNullOrEmpty(coverImg))
                {
                    postInfo.Cover = coverImg;
                }
                else
                {
                    postInfo.Cover = model.CurrentCover;
                }

                model.CurrentCover = postInfo.Cover;

                _mainStore.Update(postInfo);

                this.AddNotification(ManagerResource.LB_UPDATE_SUCCESS, NotificationType.SUCCESS);
            }
            catch (Exception ex)
            {
                this.AddNotification(ManagerResource.COMMON_ERROR_EXTERNALSERVICE_TIMEOUT, NotificationType.ERROR);

                logger.Error("Failed to EditPost because: " + ex.ToString());
            }

            return(View(model));
        }
Beispiel #2
0
        public IdentityPost GetById(int id)
        {
            var parameters = new Dictionary <string, object>
            {
                { "@Id", id }
            };

            var sqlCmd = @"M_Post_GetById";

            IdentityPost info = null;

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters))
                    {
                        if (reader.Read())
                        {
                            //Get common info
                            info = ExtractPostItem(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to GetById. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(info);
        }
Beispiel #3
0
        public int Update(IdentityPost identity)
        {
            var sqlCmd = @"M_Post_Update";

            var parameters = new Dictionary <string, object>
            {
                { "@Id", identity.Id },
                { "@Title", identity.Title },
                { "@Description", identity.Description },
                { "@BodyContent", identity.BodyContent },
                { "@IsHighlights", identity.IsHighlights },
                { "@Cover", identity.Cover },
                { "@UrlFriendly", identity.UrlFriendly },
                { "@PostType", identity.PostType },
                { "@Status", identity.Status }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    var result = MsSqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, sqlCmd, parameters);

                    return(Utils.ConvertToInt32(result));
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to M_Post_Update. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }
        }
Beispiel #4
0
        public List <IdentityPost> GetByPage(IdentityPost filter)
        {
            int offset     = (filter.PageIndex - 1) * filter.PageSize;
            var parameters = new Dictionary <string, object>
            {
                { "@Keyword", filter.Keyword },
                { "@Offset", offset },
                { "@PageSize", filter.PageSize },
                { "@SortField", filter.SortField },
                { "@SortType", filter.SortType },
                { "@Status", filter.Status }
            };

            var sqlCmd = @"M_Post_GetByPage";

            List <IdentityPost> myList = new List <IdentityPost>();

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters))
                    {
                        while (reader.Read())
                        {
                            //Get common info
                            var entity = ExtractPostItem(reader);

                            myList.Add(entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to M_Post_GetByPage. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(myList);
        }
Beispiel #5
0
        private IdentityPost ExtractPostItem(IDataReader reader)
        {
            var entity = new IdentityPost();

            entity.Id           = Utils.ConvertToInt32(reader["Id"]);
            entity.Title        = reader["Title"].ToString();
            entity.Description  = reader["Description"].ToString();
            entity.BodyContent  = reader["BodyContent"].ToString();
            entity.IsHighlights = Utils.ConvertToBoolean(reader["IsHighlights"]);
            entity.Cover        = reader["Cover"].ToString();
            entity.UrlFriendly  = reader["UrlFriendly"].ToString();
            entity.PostType     = Utils.ConvertToInt32(reader["PostType"]);
            entity.CreatedBy    = reader["CreatedBy"].ToString();
            entity.CreatedDate  = reader["CreatedDate"] == DBNull.Value ? null : (DateTime?)reader["CreatedDate"];
            entity.Status       = Utils.ConvertToInt32(reader["Status"]);

            if (reader.HasColumn("TotalCount"))
            {
                entity.TotalCount = Utils.ConvertToInt32(reader["TotalCount"]);
            }

            return(entity);
        }
Beispiel #6
0
        public int Insert(IdentityPost identity)
        {
            var sqlCmd = @"M_Post_Insert";
            var newId  = 0;

            var parameters = new Dictionary <string, object>
            {
                { "@Title", identity.Title },
                { "@Description", identity.Description },
                { "@BodyContent", identity.BodyContent },
                { "@IsHighlights", identity.IsHighlights },
                { "@Cover", identity.Cover },
                { "@UrlFriendly", identity.UrlFriendly },
                { "@PostType", identity.PostType },
                { "@CreatedBy", identity.CreatedBy },
                { "@Status", identity.Status }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters);
                    if (reader.Read())
                    {
                        newId = Utils.ConvertToInt32(reader[0]);
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to M_Post_Insert. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(newId);
        }
Beispiel #7
0
 public int Update(IdentityPost identity)
 {
     return(myRepository.Update(identity));
 }
Beispiel #8
0
 public int Insert(IdentityPost identity)
 {
     return(myRepository.Insert(identity));
 }
Beispiel #9
0
 public List <IdentityPost> GetByPage(IdentityPost filter)
 {
     return(myRepository.GetByPage(filter));
 }
Beispiel #10
0
        public JsonResult GetListPost()
        {
            var currentPage = 1;
            var status      = -1;
            var keyword     = string.Empty;
            var pageSize    = (Request["pagination[perpage]"] != null) ? Utils.ConvertToInt32(Request["pagination[perpage]"]) : SystemSettings.DefaultPageSize;

            if (Request["pagination[page]"] != null)
            {
                currentPage = Utils.ConvertToInt32(Request["pagination[page]"], 1);
            }

            if (Request["query[Status]"] != null)
            {
                status = Utils.ConvertToInt32(Request["query[Status]"], -1);
            }

            if (Request["query[generalSearch]"] != null)
            {
                keyword = Request["query[generalSearch]"].ToString();
            }

            var model = new ManagePostModel();

            model.meta = new CommonMetaPagingModel();

            model.meta.field = Request["sort[field]"];
            model.meta.sort  = Request["sort[sort]"];

            var filter = new IdentityPost
            {
                //Name = !string.IsNullOrEmpty(model.Name) ? model.Name.Trim() : null,
                //Phone = !string.IsNullOrEmpty(model.Phone) ? model.Phone.Trim() : null,
                //Code = !string.IsNullOrEmpty(model.Code) ? model.Code.Trim() : null,
                //FromDate = string.IsNullOrEmpty(model.FromDate) ? null : (DateTime?)DateTime.ParseExact(model.FromDate, ManagePostModel.DATETIME_FORMAT, null),
                //ToDate = string.IsNullOrEmpty(model.ToDate) ? null : (DateTime?)DateTime.ParseExact(model.ToDate, ManagePostModel.DATETIME_FORMAT, null),
                Keyword   = keyword,
                PageIndex = currentPage,
                PageSize  = pageSize,
                SortField = model.meta.field,
                SortType  = model.meta.sort,
                Status    = status
            };

            try
            {
                model.data = _mainStore.GetByPage(filter);

                model.meta.perpage = pageSize;
                if (model.data != null && model.data.Count > 0)
                {
                    model.meta.total = model.data[0].TotalCount;
                    model.meta.page  = currentPage;
                    model.meta.pages = (int)Math.Ceiling((double)model.meta.total / (double)model.meta.perpage);
                }

                if (model.data.HasData())
                {
                    foreach (var item in model.data)
                    {
                        item.Cover            = SocialCdnHelper.GetFullImgPath(item.Cover);
                        item.CreatedDateLabel = item.CreatedDate.DateTimeQuestToString();

                        foreach (var type in Enum.GetValues(typeof(EnumPostType)))
                        {
                            if ((int)type == item.PostType)
                            {
                                item.PostTypeLabel = EnumExtensions.GetEnumDescription((Enum)type);
                            }
                        }
                    }
                }

                return(Json(new { data = model.data, meta = model.meta }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed to GetListPost because: " + ex.ToString());
            }

            return(Json(new { model }, JsonRequestBehavior.AllowGet));
        }