Beispiel #1
0
        public IList <NewsModel> GetNewsByMember(int memberId, NewsByCriteriaRequestModel model)
        {
            using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString))
            {
                var member = dbc.Members.SingleOrDefault(r => r.Id == memberId);

                if (member == null)
                {
                    throw new OrgException("Invalid member");
                }

                var qry = (from n in dbc.News
                           where n.CompanyId == member.CompanyId
                           select n);

                qry = qry.OrderByDescending(r => r.CreatedDate);

                if (model != null)
                {
                    if (model.PageSize.HasValue && (model.PageSize.Value > 0))
                    {
                        if (model.Page.HasValue && (model.Page.Value > 1))
                        {
                            qry = qry.Skip((model.Page.Value - 1) * model.PageSize.Value);
                        }

                        qry = qry.Take(model.PageSize.Value);
                    }
                }

                var news = qry.ToList();

                return(news.Select(r => new NewsModel
                {
                    Id = r.Id,
                    LikeCount = r.LikeCount,
                    CommentCount = r.CommentCount,
                    Likes = r.Likes.Select(rr => new NewsLikeModel
                    {
                        MemberId = rr.MemberId,
                        LikeType = rr.LikeType
                    }).ToList(),
                    Text = r.Contents.Where(cr => cr.Type == (int)OrgComm.Data.Models.NewsContent.ContentType.Text).Select(cr => Encoding.Default.GetString(Encoding.Convert(Encoding.UTF8, Encoding.Default, cr.Data))).ToList(),
                    ImageUrl = r.Contents.Where(cr => cr.Type == (int)OrgComm.Data.Models.NewsContent.ContentType.Image).Select(cr => String.Format(NewsBL.ImageUrlFormatString, cr.Id)).ToList(),
                    CreatedDate = r.CreatedDate.ToString(AppConfigs.GeneralDateTimeFormat),
                    Ticks = r.CreatedDate.Ticks
                }).ToList());
            }
        }
Beispiel #2
0
        public NewsResultModel GetNews(NewsByCriteriaRequestModel param)
        {
            NewsResultModel result = new NewsResultModel();

            try
            {
                int?memberId = IdentityHelper.GetMemberId();
                if (!memberId.HasValue)
                {
                    throw new OrgException("Invalid MemberId");
                }

                NewsBL bl = new NewsBL();

                var news = bl.GetNewsByMember(memberId.Value, param);

                result.Status  = true;
                result.Message = "Got " + news.Count.ToString() + " news";
                result.News    = news;
            }
            catch (OrgException oex)
            {
                result.Status  = false;
                result.Message = oex.Message;
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = AppConfigs.InternalErrorMessage;

                if (AppConfigs.DebugInternalMessage)
                {
                    result.InternalMessage = ex.Message;
                }
            }

            return(result);
        }