public ActionResult AjaxHandler(JQueryDataTableParam param) { BusinessLayer <Equipment> bl = new BusinessLayer <Equipment>(new CapaNavDocDal()); BusinessLayer <MaintenanceData> mbl = new BusinessLayer <MaintenanceData>(new CapaNavDocDal()); BusinessLayer <ActivityField> afbl = new BusinessLayer <ActivityField>(new CapaNavDocDal()); List <EquipmentDetailsViewModel> model = new List <EquipmentDetailsViewModel>(bl.GetList().Select(e => (EquipmentDetailsViewModel)e.ToModel(new EquipmentDetailsViewModel()))); model = TableDataAdapter.Search(model, param); model = TableDataAdapter.SortList(model, param); model = TableDataAdapter.PageList(model, param); string[][] data = model.Select(m => new[] { m.Id.ToString(), m.PartNumber, m.Manufacturer, m.Name, m.Type, m.Ata.ToString(), m.ActivityFieldId.ToInt32() == 0 ? "" : afbl.Get(m.ActivityFieldId.ToInt32()).Description, m.MechanicsGroup, m.MaintenanceDataId.ToInt32() == 0 ? "" : mbl.Get(m.MaintenanceDataId.ToInt32()).Name, m.MonitoringDate, m.MaintenanceDataId }).ToArray(); return(Json(new { param.sEcho, iTotalRecords = model.Count, iTotalDisplayRecords = param.iDisplayLength, aaData = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult AjaxHandler(JQueryDataTableParam param) { BusinessLayer <User> bl = new BusinessLayer <User>(new CapaNavDocDal()); List <UserDetailsViewModel> model = new List <UserDetailsViewModel>(bl.GetList().Select(u => (UserDetailsViewModel)u.ToModel(new UserDetailsViewModel()))); model = TableDataAdapter.Search(model, param); model = TableDataAdapter.SortList(model, param); model = TableDataAdapter.PageList(model, param); string[][] data = model.Select(m => new[] { m.Id.ToString(), m.FirstName, m.LastName, m.UserName, m.Password }).ToArray(); return(Json(new { param.sEcho, iTotalRecords = model.Count, iTotalDisplayRecords = param.iDisplayLength, aaData = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult AjaxHandler(JQueryDataTableParam param) { BusinessLayer <MaintenanceData> bl = new BusinessLayer <MaintenanceData>(new CapaNavDocDal()); List <MaintenanceDataDetailsViewModel> model = new List <MaintenanceDataDetailsViewModel>(bl.GetList().Select(d => (MaintenanceDataDetailsViewModel)d.ToModel(new MaintenanceDataDetailsViewModel()))); model = TableDataAdapter.Search(model, param); model = TableDataAdapter.SortList(model, param); model = TableDataAdapter.PageList(model, param); string[][] data = model.Select(m => new[] { m.Id, m.Type, m.Sender, m.DocumentReference, m.DocumentPartNumber, m.Review, m.Date, m.Name, m.OnCertificate, m.MonitoringDate, bl.Get(m.Id.ToInt32()).Document == null ? null : "" }).ToArray(); return(Json(new { param.sEcho, iTotalRecords = model.Count, iTotalDisplayRecords = param.iDisplayLength, aaData = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult AjaxHandler(JQueryDataTableParam param) { BusinessLayer <ActivityField> bl = new BusinessLayer <ActivityField>(new CapaNavDocDal()); List <ActivityFieldDetailsViewModel> model = new List <ActivityFieldDetailsViewModel>(bl.GetList().Select(a => (ActivityFieldDetailsViewModel)a.ToModel(new ActivityFieldDetailsViewModel()))); model = TableDataAdapter.Search(model, param); model = TableDataAdapter.SortList(model, param); model = TableDataAdapter.PageList(model, param); string[][] data = model.Select(m => new[] { m.Id.ToString(), m.Description }).ToArray(); return(Json(new { param.sEcho, iTotalRecords = model.Count, iTotalDisplayRecords = param.iDisplayLength, aaData = data }, JsonRequestBehavior.AllowGet)); }
protected override async Task <OperationOutput> InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter) { var keys = getKeys(context); var result = await tableDataAdapter.UpsertAsync(inputObject, keys); switch (result) { case TableDataAdapter.UpsertResult.NothingChanged: context.Response.StatusCode = 304; break; case TableDataAdapter.UpsertResult.OneRowInserted: context.Response.StatusCode = 201; break; case TableDataAdapter.UpsertResult.OneRowUpdated: context.Response.StatusCode = 200; break; } var endpointMetadata = context.GetEndpoint().Metadata.GetMetadata <SmartAPIEndpointMetadata>(); if (endpointMetadata.Options.Trigger_AfterOperation != null) { await endpointMetadata.Options.Trigger_AfterOperation(context, tableDataAdapter.Collection, inputObject, keys); } if (endpointMetadata.Options.Upsert_FillBodyWithMember && context.Response.StatusCode != 304) { var array = new List <dynamic>(); array = await tableDataAdapter.SelectAsync(keys); if (0 == array.Count) { throw new NotFoundException(); } else if (array.Count > 1) { throw new InternalServerErrorException(); } return(new OperationOutput(OperationOutput.RessourceType.Member, tableDataAdapter.Collection.membername, array.First())); } else { return(null); } }
public override async Task Invoke(HttpContext context, Collection collection, string injectAttributeName, object injectAttributeValue) { try { string format = context.Request.Headers.ContainsKey("Accept") ? context.Request.Headers["Accept"].ToString().ToLower() : "application/json"; if ("application/json" == format) { context.Response.ContentType = "application/json"; } else if ("application/xml" == format) { context.Response.ContentType = "application/xml"; } var input = await InputAsync(context); var connectionString = collection.db.connectionstring; using (var connection = DBConnectionBuilder.Use(collection.db.dbtype, collection.db.connectionstring)) { await connection.OpenAsync(); using (var tableDataAdapter = new TableDataAdapter(connection, collection)) { if (!string.IsNullOrEmpty(injectAttributeName)) { tableDataAdapter.injectAttribute(injectAttributeName, injectAttributeValue); } var output = await InternalHandlerASync(context, input, tableDataAdapter); await connection.CloseAsync(); await OutputAsync(context, output, collection); } } } catch (HttpException smartAPIException) { string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; if (null != smartAPIException.Message) { string warningValue = ((int)smartAPIException.HttpStatusCode).ToString() + " " + host + " \"" + smartAPIException.Message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); } context.Response.StatusCode = (int)smartAPIException.HttpStatusCode; } catch (SQLiteException sqliteException) when(sqliteException.ErrorCode == 19) { var httpStatusCode = System.Net.HttpStatusCode.Conflict; string message = "A conflict occured. Check correctness of your operation regarding with data constraints."; if (sqliteException.Message.Contains("UNIQUE")) { message = "A conflict occured. Check correctness of your operation regarding with unicity constraints."; } string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; string warningValue = ((int)httpStatusCode).ToString() + " " + host + " \"" + message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); context.Response.StatusCode = (int)httpStatusCode; } catch (FIQLException ex) { var httpStatusCode = System.Net.HttpStatusCode.BadRequest; string message = "A problem occured with your FIQL request. " + ex.Message; string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; string warningValue = ((int)httpStatusCode).ToString() + " " + host + " \"" + message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); context.Response.StatusCode = (int)httpStatusCode; } catch (Exception /*ex*/) { var httpStatusCode = System.Net.HttpStatusCode.InternalServerError; string message = "Internal server error"; string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; string warningValue = ((int)httpStatusCode).ToString() + " " + host + " \"" + message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); context.Response.StatusCode = (int)httpStatusCode; } }
protected abstract Task <OperationOutput> InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter);
public override async Task Invoke(HttpContext context, Collection collection, string injectAttributeName, object injectAttributeValue) { try { string format = context.Request.Headers.ContainsKey("Accept") ? context.Request.Headers["Accept"].ToString().ToLower() : "application/json"; if ("application/json" == format) { context.Response.ContentType = "application/json"; } else if ("application/xml" == format) { context.Response.ContentType = "application/xml"; } var operations = await InputAsync(context); context.Response.StatusCode = 304; var connectionString = collection.db.connectionstring; using (var connection = DBConnectionBuilder.Use(collection.db.dbtype, collection.db.connectionstring)) { await connection.OpenAsync(); var transaction = await Task <IDbTransaction> .Run(() => { return(connection.BeginTransaction()); }); foreach (var operation in operations) { if (String.IsNullOrEmpty(operation.op) || operation.op != "replace") { throw new HttpException(System.Net.HttpStatusCode.UnprocessableEntity, "operation is not supported"); } if (String.IsNullOrEmpty(operation.path)) { throw new HttpException(System.Net.HttpStatusCode.UnprocessableEntity, "path must be set"); } if (!operation.path.StartsWith("/")) { throw new HttpException(System.Net.HttpStatusCode.UnprocessableEntity, "path must begin with /"); } if (operation.path.Length <= 1) { throw new HttpException(System.Net.HttpStatusCode.UnprocessableEntity, "path must be set"); } var attribute = collection.attributes.Where(a => a.attributename == operation.path.Substring(1)).FirstOrDefault(); if (null == attribute) { throw new HttpException(System.Net.HttpStatusCode.UnprocessableEntity, "path doesn't exists"); } using (var tableDataAdapter = new TableDataAdapter(connection, collection)) { if (!string.IsNullOrEmpty(injectAttributeName)) { tableDataAdapter.injectAttribute(injectAttributeName, injectAttributeValue); } var input = new Dictionary <string, object>(); /*var value = new Dictionary<string, object>(); * value.Add("Value", operation.value);*/ var value = new { Value = operation.value }; input.Add(attribute.attributename, value); await InternalHandlerASync(context, input, tableDataAdapter); } } await Task.Run(() => { transaction.Commit(); }); await connection.CloseAsync(); } } catch (HttpException smartAPIException) { string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; if (null == smartAPIException.Message) { string warningValue = ((int)smartAPIException.HttpStatusCode).ToString() + " " + host + " \"" + smartAPIException.Message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); } context.Response.StatusCode = (int)smartAPIException.HttpStatusCode; } catch (SQLiteException sqliteException) when(sqliteException.ErrorCode == 19) { var httpStatusCode = System.Net.HttpStatusCode.Conflict; string message = "A conflict occured. Check correctness of your operation regarding with data constraints."; if (sqliteException.Message.Contains("UNIQUE")) { message = "A conflict occured. Check correctness of your operation regarding with unicity constraints."; } string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; string warningValue = ((int)httpStatusCode).ToString() + " " + host + " \"" + message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); context.Response.StatusCode = (int)httpStatusCode; } catch (Exception /*ex*/) { var httpStatusCode = System.Net.HttpStatusCode.InternalServerError; string message = "Internal server error"; string host = (null == HttpException.Host) ? "undefinedhost" : HttpException.Host; string warningValue = ((int)httpStatusCode).ToString() + " " + host + " \"" + message + "\" " + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); context.Response.Headers.Add("Warning", warningValue); context.Response.StatusCode = (int)httpStatusCode; } }
protected async Task InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter) { var keys = getKeys(context); var result = await tableDataAdapter.UpsertAsync(inputObject, keys); if (result == TableDataAdapter.UpsertResult.OneRowUpdated) { context.Response.StatusCode = 204; } var endpointMetadata = context.GetEndpoint().Metadata.GetMetadata <SmartAPIEndpointMetadata>(); if (endpointMetadata.Options.Trigger_AfterOperation != null) { await endpointMetadata.Options.Trigger_AfterOperation(context, tableDataAdapter.Collection, inputObject, keys); } }
protected override async Task <OperationOutput> InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter) { var keys = getKeys(context); await tableDataAdapter.DeleteASync(keys); context.Response.StatusCode = 204; var endpointMetadata = context.GetEndpoint().Metadata.GetMetadata <SmartAPIEndpointMetadata>(); if (endpointMetadata.Options.Trigger_AfterOperation != null) { await endpointMetadata.Options.Trigger_AfterOperation(context, tableDataAdapter.Collection, inputObject, keys); } return(null); }
protected override async Task <OperationOutput> InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter) { var row = await tableDataAdapter.InsertAsync(inputObject); var id = (long)row.serial; context.Response.StatusCode = 201; var httpRequestFeature = context.Features.Get <IHttpRequestFeature>(); var baseUrl = httpRequestFeature.RawTarget; if (string.IsNullOrEmpty(baseUrl)) { baseUrl = httpRequestFeature.PathBase + httpRequestFeature.Path; } context.Response.Headers["Location"] = baseUrl + "/" + id; var endpointMetadata = context.GetEndpoint().Metadata.GetMetadata <SmartAPIEndpointMetadata>(); if (endpointMetadata.Options.Trigger_AfterOperation != null) { await endpointMetadata.Options.Trigger_AfterOperation(context, tableDataAdapter.Collection, inputObject, new string[] { id.ToString() }); } if (endpointMetadata.Options.Upsert_FillBodyWithMember) { var array = new List <dynamic>(); array = await tableDataAdapter.SelectAsync(new string[] { id.ToString() }); if (0 == array.Count) { throw new NotFoundException(); } else if (array.Count > 1) { throw new InternalServerErrorException(); } return(new OperationOutput(OperationOutput.RessourceType.Member, tableDataAdapter.Collection.membername, array.First())); } else { return(null); } }
protected override async Task <OperationOutput> InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter) { var array = new List <dynamic>(); if (context.Request.Query.ContainsKey("query") && tableDataAdapter.Attributes.Select(x => x.fiqlkeyindex.HasValue).Count() > 0) { var fiqlParser = new FIQLParser(); var rootExpression = fiqlParser.Parse(context.Request.Query["query"]); var whereClause = rootExpression.ComputeWhereClause(tableDataAdapter.Attributes); Console.WriteLine(whereClause.whereSqlStatement); array = await tableDataAdapter.SelectAsync(whereClause); } else { array = await tableDataAdapter.SelectAsync(); } context.Response.StatusCode = 200; return(new OperationOutput(OperationOutput.RessourceType.Collection, tableDataAdapter.Collection.collectionname, array)); }
protected override async Task <OperationOutput> InternalHandlerASync(HttpContext context, object inputObject, TableDataAdapter tableDataAdapter) { var keys = getKeys(context); var array = new List <dynamic>(); array = await tableDataAdapter.SelectAsync(keys); if (0 == array.Count) { throw new NotFoundException(); } else if (array.Count > 1) { throw new InternalServerErrorException(); } context.Response.StatusCode = 200; return(new OperationOutput(OperationOutput.RessourceType.Member, tableDataAdapter.Collection.membername, array.First())); }