public IHttpActionResult PostAccount([FromBody] SRLedgerCOAViewModel coaccount) { try { if (ModelState.IsValid) { var exist = _ilcrepo.GetAll().FirstOrDefault(x => x.GLAccountNumber == coaccount.GLAccountNumber); if (exist == null) { var newCOA = Mapper.Map <LedgerChartOfAccount>(coaccount); newCOA.AuditUserID = User.Identity.Name; //Save to database _ilcrepo.Insert(newCOA); _ilcrepo.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 EditAccount([FromBody] SRLedgerCOAViewModel coaccount) { try { if (ModelState.IsValid) { var currentRecord = _ilcrepo.GetAll().FirstOrDefault(x => x.GLAccountNumber == coaccount.GLAccountNumber); if (currentRecord != null) { currentRecord.AuditUserID = User.Identity.Name; } //Save to database _ilcrepo.Edit2(currentRecord, coaccount); _ilcrepo.Save(); return(Json(new { success = true })); } } catch (DbEntityValidationException dbex) { return(Json(new { Message = ValidationErrorMsg(dbex) })); } return(Json(new { Message = "Failed", ModelState = ModelState })); }