public ActionResult Create(int id) { if (Session["uid"] != null) { //Hämta session-id theUser = Convert.ToInt64(Session["uid"].ToString()); } CaseComment casecomment = new CaseComment(); casecomment.caseID = id; casecomment.userID = theUser; //TODO actual user-id if (Request["comment"] != null && Request["comment"] != "") { casecomment.commentStr = Request["comment"]; } else { casecomment.commentStr = "asdf"; } if (ModelState.IsValid) { casecommentRepository.InsertOrUpdate(casecomment); casecommentRepository.Save(); } return View(); }
public ActionResult CreateComment(CaseComment caseComment) { if (ModelState.IsValid) { var casecommentRepository = new CaseCommentRepository(); casecommentRepository.InsertOrUpdate(caseComment); casecommentRepository.Save(); return RedirectToAction("Details", new { id = caseComment.caseID }); } return RedirectToAction("Index"); }
public ActionResult Edit(CaseComment casecomment) { if (ModelState.IsValid) { casecommentRepository.InsertOrUpdate(casecomment); casecommentRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(CaseComment casecomment) { if (casecomment.commentID == default(int)) { // New entity context.CaseComments.Add(casecomment); } else { // Existing entity context.Entry(casecomment).State = EntityState.Modified; } }