public IHttpActionResult PostTerm([FromBody] SRSessionDTLNewViewModel term) { try { if (ModelState.IsValid) { var exist = _isdrepo.GetAll().FirstOrDefault(x => x.SubSessionID == term.SubSessionID && x.ParentID == term.ParentID); if (exist == null) { var newTerm = Mapper.Map <SRSessionsDTL>(term); newTerm.AuditUserID = User.Identity.Name; newTerm.AuditDateTime = DateTime.Now; //Save to database _isdrepo.Insert(newTerm); _isdrepo.Save(); return(Json(new { success = true })); } } } catch (DbEntityValidationException dbex) { return(Json(new { Message = ValidationErrorMsg(dbex) })); } // Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { data = GetErrorMessages().ToList() })); }
public IHttpActionResult EditTerm([FromBody] SRSessionDTLNewViewModel term) { try { if (ModelState.IsValid) { var currentRecord = _isdrepo.GetAll().FirstOrDefault(x => x.RecordID == term.RecordID); if (currentRecord != null) { currentRecord.AuditUserID = User.Identity.Name; } //Save to database _isdrepo.Edit2(currentRecord, term); _isdrepo.Save(); return(Json(new { success = true })); } } catch (DbEntityValidationException dbex) { return(Json(new { Message = ValidationErrorMsg(dbex) })); } return(Json(new { Message = "Failed", ModelState = ModelState })); }