public override IEnumerable <Model.LocationService> Search(string query = null, int?skip = 0, int?take = 0, string extraparams = null) { var searchquery = _crudService.Get <Model.LocationService>(Getbyincludes).AsNoTracking(); if (!IsBlankQuery(query)) { string[] terms = SplitSearchTerms(query); searchquery = searchquery.Where(ls => terms.All(t => ls.CustomerLocation.Name.Contains(t)) ); } if (!string.IsNullOrEmpty(extraparams)) { var extras = System.Web.HttpUtility.ParseQueryString(WebUtility.UrlDecode(extraparams)); if (extras["ServiceTypeIds"] != null && extras["ServiceTypeIds"].Any()) { IEnumerable <int> serviceTypeIds = extras["ServiceTypeIds"].Split(',').Select(System.Int32.Parse).ToList(); searchquery = searchquery.Where(c => serviceTypeIds.Contains(c.Good.ServiceTypeId)); } if (extras["archived"] != null && extras["archived"].Any()) { var includeArchived = bool.Parse(extras["archived"]); if (!includeArchived) { searchquery = searchquery.Where(u => !u.Archived); } } if (extras["services"] != null && extras["services"].Any()) { string termService = extras["services"]; searchquery = searchquery.Where(s => s.Good.Name.Contains(termService)); } if (extras["city"] != null && extras["city"].Any()) { string termCity = extras["city"]; searchquery = searchquery.Where(s => s.CustomerLocation.Address.City.Contains(termCity)); } if (extras["state"] != null && extras["state"].Any()) { string termState = extras["state"]; searchquery = searchquery.Where(s => s.CustomerLocation.Address.State.Name.Contains(termState)); } if (extras["zip"] != null && extras["zip"].Any()) { string termZip = extras["zip"]; searchquery = searchquery.Where(s => s.CustomerLocation.Address.Zip.Contains(termZip)); } } var ct = searchquery.Count(); return(searchquery .OrderBy(c => c.Id) .Skip(skip.GetValueOrDefault()) .Take(take.GetValueOrDefault()) .ToSearchResults(ct) .Respond(this)); }
public static async Task <ActionResult <T> > Add <T, TKey>(this Controller controller, ICRUDService <T, TKey> manager, T value) where T : class where TKey : IComparable { TKey newid = await manager.Add(value); string newuri = controller.GetCurrentUri() + "/" + newid; return(controller.Created(newuri, await manager.Get(newid))); }
public static async Task <ActionResult <IEnumerable <UriAndValue <T> > > > Add <T, TKey>(this Controller controller, ICRUDService <T, TKey> manager, IEnumerable <T> values) where T : class where TKey : IComparable { IEnumerable <TKey> newids = await manager.Add(values); IEnumerable <T> newobjects = await manager.Get(newids); string uri = controller.GetCurrentUri("/bulk"); var newuris = newids.Select(id => uri + "/" + id); var results = newids.Select((id, idx) => new UriAndValue <T>() { Uri = uri + "/" + id, Value = newobjects.ElementAt(idx) }); return(controller.Ok(newuris)); }
public override IEnumerable <Good> Search(string query = null, int?skip = 0, int?take = 0, string extraparams = null) { var searchquery = _crudService.Get <Good>(Getbyincludes).AsNoTracking(); if (!IsBlankQuery(query)) { string[] terms = SplitSearchTerms(query); searchquery = searchquery.Where(g => terms.All(t => g.Name.Contains(t)) ); } if (!string.IsNullOrEmpty(extraparams)) { var extras = System.Web.HttpUtility.ParseQueryString(WebUtility.UrlDecode(extraparams)); if (extras["ServiceTypeIds"] != null && extras["ServiceTypeIds"].Any()) { IEnumerable <int> serviceTypeIds = extras["ServiceTypeIds"].Split(',').Select(System.Int32.Parse).ToList(); searchquery = searchquery.Where(c => serviceTypeIds.Contains(c.ServiceTypeId)); } if (extras["ServiceDivisionIds"] != null && extras["ServiceDivisionIds"].Any()) { IEnumerable <int> serviceDivisionIds = extras["ServiceDivisionIds"].Split(',').Select(System.Int32.Parse).ToList(); searchquery = searchquery.Where(c => serviceDivisionIds.Contains(c.ServiceDivisionId)); } if (extras["archived"] != null && extras["archived"].Any()) { var includeArchived = bool.Parse(extras["archived"]); if (!includeArchived) { searchquery = searchquery.Where(u => !u.Archived); } } } var ct = searchquery.Count(); return(searchquery .OrderBy(c => c.Name) .Skip(skip.GetValueOrDefault()) .Take(take.GetValueOrDefault()) .ToSearchResults(ct) .Respond(this)); }
public async Task <IActionResult> GetMock( [FromHeader] string idSessao, [FromHeader] string token, string api, string metodo) { var query = Request.QueryString.ToString(); query = query.Remove(query.IndexOf("&hash")); string jString = System.IO.File.ReadAllText("MockGet.json"); var json = JsonConvert.DeserializeObject <List <dynamic> >(jString); List <dynamic> MockResult = new List <dynamic>(); foreach (var obj in json) { if (obj.rota.ToString() == $"{api}/{metodo}{query}") { MockResult.Add(obj); } } if (MockResult.Count > 0) { return(new JsonResult(MockResult)); } List <dynamic> result = await acrudService.Get(query, api, metodo, idSessao, token); foreach (var obj in result) { json.Add(obj); } string output = JsonConvert.SerializeObject(json, Formatting.Indented); System.IO.File.WriteAllText("MockGet.json", output); return(new JsonResult(result)); }
public ActionResult <List <Model.Knjige> > Get([FromQuery] Model.Requests.KnjigeSearchRequest request) { return(_service.Get(request)); }
public virtual IEnumerable <T> Search(string query = null, int?skip = 0, int?take = 0, string extraparams = null) { var searchquery = Crudservice.Get <T>(); if (Searchchildincludes != null && Searchchildincludes.Length > 0) { searchquery = Searchchildincludes.Aggregate(searchquery, (current, t) => current.Include(t)); } var parameter = Expression.Parameter(typeof(T)); if (!IsBlankQuery(query) && Searchfields.Length > 0) { var terms = SplitSearchTerms(query); var final = Enumerable.Empty <T>().AsQueryable(); var searchResults = Enumerable.Empty <T>().AsQueryable(); foreach (var t in terms) { foreach (var searchfield in Searchfields) { switch (searchfield.Comparetype) { case CrudSearchFieldType.Method.Equals: //Equals var expression = Expression.Lambda <Func <T, bool> >( Expression.Equal(Expression.MakeMemberAccess(parameter, typeof(T).GetProperty(searchfield.Name)), Expression.Constant(t)), parameter); searchResults = searchquery.Where(expression); break; case CrudSearchFieldType.Method.Contains: //Contains var method = typeof(string).GetMethod("Contains", new[] { typeof(string) }); if (method != null) { var expressionBody = Expression.Call(Expression.Property(parameter, searchfield.Name), method, Expression.Constant((t))); searchResults = searchquery.Where(Expression.Lambda <Func <T, bool> >(expressionBody, parameter)); } break; default: throw new ArgumentOutOfRangeException(); } final = searchResults.Union(final); } } searchquery = final; } Expression orderByProperty = Expression.Property(parameter, Orderby); searchquery = orderByProperty.Type == typeof(int) ? searchquery.OrderBy(GetOrderByExpressionInt(parameter, orderByProperty)) : searchquery.OrderBy(GetOrderByExpressionString(parameter, orderByProperty)); var ct = searchquery.Count(); if (take > 0) { searchquery = searchquery.Skip(skip.GetValueOrDefault()).Take(take.GetValueOrDefault()); } return(searchquery .ToSearchResults <T>(ct) .Respond <T>(this)); }
public override IEnumerable <Contract> Search(string query = null, int?skip = 0, int?take = 0, string extraparams = null) { var searchquery = _crudService.Get <Contract>(Getbyincludes).AsNoTracking(); if (!IsBlankQuery(query)) { string[] terms = SplitSearchTerms(query); searchquery = searchquery.Where(c => terms.All(t => c.Number.Contains(t)) ); } if (!string.IsNullOrEmpty(extraparams)) { var extras = System.Web.HttpUtility.ParseQueryString(WebUtility.UrlDecode(extraparams)); if (extras["ServiceDivisionIds"] != null && extras["ServiceDivisionIds"].Any()) { IEnumerable <int> serviceDivisionIds = extras["ServiceDivisionIds"].Split(',').Select(System.Int32.Parse).ToList(); searchquery = searchquery.Where(c => serviceDivisionIds.Contains(c.ServiceDivisionId)); } if (extras["ContractStatusIds"] != null && extras["ContractStatusIds"].Any()) { IEnumerable <int> ContractStatusIds = extras["ContractStatusIds"].Split(',').Select(System.Int32.Parse).ToList(); searchquery = searchquery.Where(c => ContractStatusIds.Contains(c.StatusId)); } if (extras["archived"] != null && extras["archived"].Any()) { var includeArchived = bool.Parse(extras["archived"]); if (!includeArchived) { searchquery = searchquery.Where(u => !u.Archived); } } if (extras["OrderDateStart"] != null && extras["OrderDateEnd"] != null) { var hasOrderDateStart = System.DateTime.TryParseExact( extras["OrderDateStart"], "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var orderDateStart); var hasOrderDateEnd = System.DateTime.TryParseExact( extras["OrderDateEnd"], "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var orderDateEnd); if (hasOrderDateStart && hasOrderDateEnd) { searchquery = searchquery .Where(c => DbFunctions.TruncateTime(orderDateStart) <= DbFunctions.TruncateTime(c.StartDate)) .Where(c => DbFunctions.TruncateTime(orderDateEnd) >= DbFunctions.TruncateTime(c.EndDate)); } } } var ct = searchquery.Count(); return(searchquery .OrderBy(c => c.Number) .Skip(skip.GetValueOrDefault()) .Take(take.GetValueOrDefault()) .ToSearchResults(ct) .Respond(this)); }