public void CreateComment(int memberId, NewsCommentCreateRequesetModel model) { if ((model == null) || !model.NewsId.HasValue) { throw new OrgException("Invalid news"); } if ((model == null) || !model.Type.HasValue) { throw new OrgException("Invalid comment type"); } using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString)) { OrgComm.Data.Models.News news = dbc.News.SingleOrDefault(r => r.Id == model.NewsId.Value); if (news == null) { throw new OrgException("News not found"); } OrgComm.Data.Models.NewsComment comment = new OrgComm.Data.Models.NewsComment { Text = model.Text, Type = model.Type.Value, MemberId = memberId, CreatedDate = DateTime.Now }; news.Comments.Add(comment); news.CommentCount = news.Comments.Count(); dbc.SaveChanges(); } }
public ResultModel CreateComment(NewsCommentCreateRequesetModel param) { ResultModel result = new ResultModel(); try { int?memberId = IdentityHelper.GetMemberId(); if (!memberId.HasValue) { throw new OrgException("Invalid MemberId"); } NewsBL bl = new NewsBL(); bl.CreateComment(memberId.Value, param); result.Status = true; result.Message = "Comment created"; } 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); }