public async Task<HttpResponseMessage> PutComment(Comment comment) { JObject result = new JObject(); if (!ModelState.IsValid) { return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } db.Entry(comment).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(comment.Id)) { result = Methods.CustomResponseMessage(0, "Comment isn't exists!"); return Request.CreateResponse(HttpStatusCode.NotFound, result); } else { throw; } } result = Methods.CustomResponseMessage(0, "Update Comment is successful!"); return Request.CreateResponse(HttpStatusCode.OK, result); }
public async Task<HttpResponseMessage> PostComment(Comment comment) { JArray result = new JArray(); JObject ownerInfo = new JObject(); if (!ModelState.IsValid) { return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } //db.Comments.Add(comment); //await db.SaveChangesAsync(); try { var cmtDate = new SqlParameter("@Date", comment.CommentDate); var storeId = new SqlParameter("@StoreID", comment.StoreID); var userId = new SqlParameter("@UserID", comment.UserID); var content = new SqlParameter("@Content", comment.Content); result = Methods.GetInstance().ExecQueryWithResult("viethung_paybayservice.sp_AddComment", CommandType.StoredProcedure, ref Methods.err, cmtDate, storeId, userId, content); var store = new SqlParameter("@StoreID", comment.StoreID); var user = new SqlParameter("@UserID", comment.UserID); var owner = Methods.GetInstance().ExecQueryWithResult("viethung_paybayservice.sp_GetOwnerInfo", CommandType.StoredProcedure, ref Methods.err, store, user); if(owner.Count > 0) { ownerInfo = owner[0].ToObject<JObject>(); } //var currentUser = this.User as ServiceUser; //await PushHelper.SendToastAsync(WebApiConfig.Services, ownerInfo["UserName"].ToString(), comment.Content, new Uri(ownerInfo["Avatar"].ToString())); await PushHelper.SendToastAsync(WebApiConfig.Services, ownerInfo["UserName"].ToString() + " just commented!", comment.Content, new Uri(ownerInfo["Avatar"].ToString()), ownerInfo["OwnerID"].ToString()); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } return Request.CreateResponse(HttpStatusCode.OK, result); }