public int GetQueryData([FromBody] IncomingWidgetCreatorRequest request) { var result = default(int); using (var context = new DatabaseController(Context, Configuration)) { result = context.AddUserQuery(request, UserId); } return(result); }
internal int AddUserQuery(IncomingWidgetCreatorRequest request, int userId) { var query = string.Empty; query = $"select * from {request.TableName} where "; request.rule.Rules.ForEach(x => { query += $"{x.field} {GetOperator(x.Operator.ToLower())} "; var data = IsList(x.value); if (data.Count > 0) { var i = 0; data.ForEach(y => { if (i == 0) { query += $"{y}"; } else { query += $" and {y}"; } i++; }); } else { query += $"({x.value})"; } }); var queryData = Context.UserQueries.Add(new UserQueries { QueryData = query, QueryName = request.ControlName, UserId = userId, DateOfQuery = DateTime.Now }); Context.SaveChanges(); return(queryData.Entity.Id); }