public JsonResult EditComment(ObservationComment model) { using (Entity context = new Entity()) { try { t_observation_comment comment = context.t_observation_comment.Find(model.CommentId); if (comment == null) { throw new ArgumentException("Invalid commentId: " + model.CommentId.ToString()); } comment.comment = model.Comment; comment.updatedby_userid = CurrentUser.Id; comment.updated_date = DateTime.Now; context.SaveChanges(); context.Entry(comment).Reference(n => n.updatedby).Load(); return(Json(new { success = true, Comment = comment.comment, UpdatedBy = comment.updatedby.full_name, UpdatedOn = comment.updated_date.Value.ToString("d") })); } catch (Exception ex) { return(GetJsonResult(ex)); } } }
public JsonResult AddComment(ObservationComment model) { using (Entity context = new Entity()) { try { t_observation_comment comment = new t_observation_comment(); comment.observation_id = model.ObservationId; comment.comment = model.Comment; comment.createdby_userid = CurrentUser.Id; comment.created_date = DateTime.Now; context.t_observation_comment.Add(comment); context.SaveChanges(); context.Entry(comment).Reference(n => n.createdby).Load(); return(Json(new { success = true, CommentId = comment.observation_comment_id, ObservationId = comment.observation_id, Comment = comment.comment, CreatedBy = comment.createdby.full_name, CreatedOn = comment.created_date.ToString("d") })); } catch (Exception ex) { return(GetJsonResult(ex)); } } }
public ObservationComment(t_observation_comment comment) { CommentId = comment.observation_comment_id; ObservationId = comment.observation_id; Comment = comment.comment; CreatedByUserId = comment.createdby_userid; CreatedOn = comment.created_date; UpdatedByUserId = comment.updatedby_userid; UpdatedOn = comment.updated_date; }
public JsonResult DeleteComment(int commentId) { using (Entity context = new Entity()) { try { t_observation_comment comment = context.t_observation_comment.Find(commentId); context.t_observation_comment.Remove(comment); context.SaveChanges(); return(Json(new { success = true })); } catch (Exception ex) { return(GetJsonResult(ex)); } } }
private int?UpsertComment(dynamic model) { // "New" comments are always new (no collisions). Check if "updated" comments // exist before updating; if they no longer exist for some reason, re-create. t_observation_comment entity = null; int commentId; if (Int32.TryParse(model.CommentId.ToString(), out commentId)) { entity = Context.t_observation_comment.Find(commentId); } bool isNew = entity == null; if (isNew) { entity = new t_observation_comment() { observation_id = model.ObservationId, createdby_userid = CurrentUserId, created_date = Convert.ToDateTime(model.CreatedOn) }; Context.t_observation_comment.Add(entity); } else { entity.updatedby_userid = CurrentUserId; entity.updated_date = Convert.ToDateTime(model.UpdatedOn); } entity.comment = model.Comment; Context.SaveChanges(); if (isNew) { return(entity.observation_comment_id); } else { return(null); } }