示例#1
0
        // PUT api/Comment/5

        public async Task<IHttpActionResult> updateComment(Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }
            db.Entry(comment).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(comment.Id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }
            return StatusCode(HttpStatusCode.NoContent);
        }
示例#2
0
        public async Task<IHttpActionResult> PostComment(Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if (!( HttpContext.Current.Request.IsAuthenticated))
            {
               // return BadRequest();
                return BadRequest("you must be logged in post comment");
            }
            comment.time = DateTime.UtcNow;
            comment.postedBy = User.Identity.GetUserId();
            db.Comments.Add(comment);
            await db.SaveChangesAsync();
            //db.Comments.Include(x => x.AspNetUser).Select(x=>x.;

            var ret = db.Comments.Where(x => x.Id == comment.Id).Select(x => new
            {
                description = x.description,
                postedById = x.postedBy,
                postedByName = x.AspNetUser.Email,
                time = x.time,
                id = x.Id,
                adId = x.adId,
                imageExtension = x.AspNetUser.dpExtension,
                islogin = x.postedBy
            }).FirstOrDefault();

            
            return Ok(ret);
           // return CreatedAtRoute("DefaultApi", new { id = comment.Id }, comment);
        }
示例#3
0
 public void AddComment(Comment comment)
 {
     if (Context.User.Identity.IsAuthenticated)
     {
         comment.time = DateTime.UtcNow;
         comment.postedBy = Context.User.Identity.GetUserId();
         db.Comments.Add(comment);
         db.SaveChanges();
         var ret = db.Comments.Where(x => x.Id == comment.Id).Select(x => new
         {
             description = x.description,
             postedById = x.postedBy,
             postedByName = x.AspNetUser.Email,
             time = x.time,
             imageExtension = x.AspNetUser.dpExtension,
             id = x.Id,
         }).FirstOrDefault();
         Clients.Caller.AppendCommentToMe(ret);
         Clients.Others.appendComment(ret);
     }
 }