public object Create(CommentVM commentVM) { try { AdComment Comment = new AdComment(); object ObjectReturn = CreateS.Comment(commentVM, Comment); if (ObjectReturn != null) { return(ObjectReturn); } db.SaveChanges(); db = new TageerEntities(); Comment = db.AdComments.Find(Comment.Id); return(new ResponseVM(RequestTypeEnumVM.Success, Token.Created, new CommentVM { Id = Comment.Id, AdId = Comment.FKAd_Id, Comment = Comment.Comment, UserImage = Comment.User.Image, UserName = Comment.User.UserName })); } catch (Exception ex) { return(new ResponseVM(RequestTypeEnumVM.Error, Token.SomeErrorInServer, ex)); } }
internal object Comment(CommentVM commentVM, AdComment comment) { var Ad = db.Ads.Find(commentVM.AdId); var User = db.Users.Find(AccessToken.GetUserId()); if (Ad == null) { return(new ResponseVM(RequestTypeEnumVM.Error, Token.AdNotFound)); } if (string.IsNullOrEmpty(commentVM.Comment)) { return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Comment} : {Token.FiledIsRequired}")); } if (commentVM.AdId <= 0) { return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.AdId} : {Token.FiledIsRequired}")); } if (commentVM.Comment.Length > 1000) { return(new ResponseVM(RequestTypeEnumVM.Error, $"{Token.Comment} : {Token.MaxLength} = 1000")); } comment.Comment = commentVM.Comment; comment.FKAd_Id = commentVM.AdId; comment.FkUser_Id = AccessToken.GetUserId(); comment.DateTime = DateTime.Now; db.AdComments.Add(comment); //Add Notifify To User Ownar Ad if (Ad.FkUser_Id != User.Id) { db.Notifications.Add(new Notification { TitleAr = $"علق {User.UserName} على اعلان {Ad.Title} ", TitleEn = $"{User.UserName} added comment to ad {Ad.Title}", DataTime = DateTime.Now, UsersPrivateNotifies = new List <UsersPrivateNotify> { new UsersPrivateNotify { FkUser_Id = Ad.FkUser_Id } } }); } return(null); }
protected void btnSubmitNewComment_Click(object sender, EventArgs e) { if (txtNewComment.Text.Trim() == String.Empty) { return; } if (CurrentUserSession != null) { var comment = new AdComment(AdID, CurrentUserSession.Username) { CommentText = (Config.Misc.EnableBadWordsFilterComments ? Parsers.ProcessBadWords(txtNewComment.Text) : txtNewComment.Text) }; comment.Save(); } loadComments = true; }
public AdCommentViewModel() { adComment = new AdComment(); }
public void AddCommentToAd(AdComment comment) { _dbContext.AdComments.Add(comment); _dbContext.SaveChanges(); }