public Result <COMMENTSEC> Save(COMMENTSEC Entity) { var result = new Result <COMMENTSEC>(); try { var objtosave = _context.commentsecs.FirstOrDefault(u => u.CommunicationId == Entity.CommunicationId); if (objtosave == null) { objtosave = new COMMENTSEC(); _context.commentsecs.Add(objtosave); } if (!IsValid(objtosave, result)) { return(result); } _context.SaveChanges(); } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
public bool IsValid(COMMENTSEC obj, Result <COMMENTSEC> result) { if (!ValidationHelper.IsStringValid(obj.UserId.ToString())) { result.HasError = true; result.Message = "Invalid UserId"; return(false); } return(true); }
public ActionResult CommentInsert(COMMENTSEC commentsec) { try { var result = CommunicationDao.Save(commentsec); if (result.HasError) { ViewBag.Message = result.Message; return(View("WorkProgress")); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("WorkProgress")); }
public COMMENTSEC Post(COMMENTSEC commentsec) { try { var objToSave = new COMMENTSEC(); _context.commentsecs.Add(objToSave); objToSave.UserId = commentsec.UserId; objToSave.Commt = commentsec.Commt; objToSave.ProjectSectionId = commentsec.ProjectSectionId; _context.SaveChanges(); return(commentsec); } catch (Exception e) { return(null); } }