public IHttpActionResult Putcourse_comment(int id, course_comment course_comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != course_comment.id) { return(BadRequest()); } db.Entry(course_comment).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!course_commentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Getcourse_SingleComment(int id) { course_comment course_comment = db.course_comment.Include(x => new { x.AspNetUser.UserName, x.AspNetUser.Photo }).FirstOrDefault(x => x.id == id); if (course_comment == null) { return(NotFound()); } return(Ok(course_comment)); }
public IHttpActionResult Deletecourse_comment(int id) { course_comment course_comment = db.course_comment.Find(id); if (course_comment == null) { return(NotFound()); } db.course_comment.Remove(course_comment); db.SaveChanges(); return(Ok(course_comment)); }
public async Task <IHttpActionResult> Postcourse_comment(course_comment course_comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.course_comment.Add(course_comment); db.SaveChanges(); //send notification to all friends var friends = db.friends.Where(x => x.UserId == course_comment.user_id && x.Confirmed == true).Select(x => x.friendId); var friends2 = db.friends.Where(x => x.friendId == course_comment.user_id && x.Confirmed == true).Select(x => x.UserId); friends.Concat(friends2); var new_notifi = new cls_notifi { source_name = "course", source_id = course_comment.course_id.ToString(), image = db.AspNetUsers.FirstOrDefault(x => x.Id == course_comment.user_id).Photo,//"no image", body_English = db.AspNetUsers.FirstOrDefault(x => x.Id == course_comment.user_id).UserName + " commented on course " + db.courses.FirstOrDefault(x => x.id == course_comment.course_id).name, body_Arabic = "كتب " + db.AspNetUsers.FirstOrDefault(x => x.Id == course_comment.user_id).UserName + " تعليق على كورس " + db.courses.FirstOrDefault(x => x.id == course_comment.course_id).name, timestamp = DateTime.Now, readed = false }; //await Push(new_notifi, "notifications/" + db.courses.FirstOrDefault(x => x.id == course_comment.course_id).instructor + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy")); foreach (var item in friends) { await Push(new_notifi, "notifications/" + item + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy")); PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == item).DeviceToken, "comment", new_notifi.body_English, "course", course_comment.course_id.ToString()); } return(CreatedAtRoute("DefaultApi", new { id = course_comment.id }, course_comment)); }