public HttpResponseMessage AddCommentToAlbum([FromUri] int id, [FromBody] CommentAlbumModel commentModel) { if (commentModel.DataId != id) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Dữ liệu không phù hợp")); } using (var db = new OnlineMusicEntities()) { AlbumComment comment = new AlbumComment(); commentModel.UpdateEntity(comment); comment.Date = DateTime.Now; db.AlbumComments.Add(comment); db.SaveChanges(); comment.User = (from u in db.Users where u.Id == comment.UserId select u).FirstOrDefault(); commentModel = commentDto.GetCommentQuery(db, awhereClause: null).Where(c => c.Id == comment.Id).FirstOrDefault(); return(Request.CreateResponse(HttpStatusCode.Created, commentModel)); } }
public HttpResponseMessage EditComment([FromUri] int id, [FromBody] CommentAlbumModel commentModel) { if (commentModel.DataId != id) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Dữ liệu không phù hợp")); } using (var db = new OnlineMusicEntities()) { AlbumComment comment = (from c in db.AlbumComments where c.Id == commentModel.Id select c).FirstOrDefault(); if (comment == null) { return(Request.CreateErrorResponse(HttpStatusCode.OK, "Không tìm thấy comment id=" + commentModel.Id)); } commentModel.UpdateEntity(comment); db.SaveChanges(); commentModel = commentDto.GetCommentQuery(db, awhereClause: null).Where(c => c.Id == comment.Id).FirstOrDefault(); return(Request.CreateResponse(HttpStatusCode.OK, commentModel)); } }