public IHttpActionResult Delete(int id) { var funcName = "Delete"; Logger.DebugFormat("{0} <-- Start", funcName); IHttpActionResult result; try { // Delete ProductCategory item in database this.DeleteRecord(id); // Commit changed this.UnitOfWork.SaveChanges((exception) => { throw new DatabaseException((int)DatabaseErrorCode.Delete, exception); }); // Build action result var responseContext = new UpdateResponseContext <T> { Result = true, Description = "Dữ liệu đã được xóa" }; result = HttpActionResultBuilder.BuildJsonContentResult(this.Request, responseContext); } catch (Exception ex) { Logger.ErrorFormat("{0} - Exception: {1}", funcName, ex); result = HttpActionResultBuilder.BuildExceptionResult(this.Request, ex); } Logger.DebugFormat("{0} --> End", funcName); return(result); }
public virtual IHttpActionResult Update(UpdateRequestContext <T> requestContext) { var funcName = "Update"; Logger.DebugFormat("{0} <-- Start", funcName); IHttpActionResult result; try { if (requestContext == null) { throw new ArgumentException("Could not get request context"); } // Keeps input request for using later this.updateRequestContext = requestContext; // Update record to database var record = this.UpdateRecord(); // Commit changed this.UnitOfWork.SaveChanges((exception) => { throw new DatabaseException((int)DatabaseErrorCode.Update, exception); }); // Build action result var responseContext = new UpdateResponseContext <T> { Record = record, Result = true, Description = "Dữ liệu đã được cập nhật" }; result = HttpActionResultBuilder.BuildJsonContentResult(this.Request, responseContext); } catch (Exception ex) { Logger.ErrorFormat("{0} - Exception: {1}", funcName, ex); result = HttpActionResultBuilder.BuildExceptionResult(this.Request, ex); } Logger.DebugFormat("{0} --> End", funcName); return(result); }