예제 #1
0
 public static string AddNewComment(CommentModelDTO model)
 {
     if (Convert.ToBoolean(model.UserId) && model.CommentContent.Any())
     {
         using (var context = GetMMBContext())
         {
             var commentEntity = CommentEntity();
             commentEntity.CommentContent = model.CommentContent;
             commentEntity.UserId         = model.UserId;
             commentEntity.Likes          = 0;
             commentEntity.Dislikes       = 0;
             commentEntity.CreatedOn      = DateTime.UtcNow;
             commentEntity.UpdatedOn      = DateTime.UtcNow;
             commentEntity.IsRoot         = model.IsComment;
             if (model.ParentId == 0)
             {
                 commentEntity.ParentId = null;
             }
             else
             {
                 commentEntity.ParentId = model.ParentId;
             }
             if (commentEntity.BlogId == 0)
             {
                 commentEntity.BlogId = null;
             }
             else
             {
                 commentEntity.BlogId = model.BlogId;
             }
             context.Comment.Add(commentEntity);
             context.SaveChanges();
             return("Success");
         }
     }
     else
     {
         return("Failed");
     }
 }
예제 #2
0
 public JsonResult AddNewComment(CommentModelDTO model)
 {
     try
     {
         var addStatus = CommentBusiness.AddNewComment(model);
         if (addStatus == "Success")
         {
             var response = new ApiRespnoseWrapper {
                 Status = ApiRespnoseStatus.Success, Results = new ArrayList()
                 {
                     addStatus
                 }
             };
             return(new JsonResult {
                 Data = response
             });
         }
         else
         {
             var response = new ApiRespnoseWrapper {
                 Status = ApiRespnoseStatus.Failed, Results = new ArrayList()
                 {
                     addStatus
                 }
             };
             return(new JsonResult {
                 Data = response
             });
         }
     }
     catch (Exception ex)
     {
         CommonFunctions.LogDetails(ex, null);
         return(CommonBusiness.GetErrorResponse());
     }
 }