示例#1
0
        public IActionResult SearchData(string schemaname, string searchtext, [FromBody] SearchDataRequestModel requestModel, [FromQuery] int skip = 0, [FromQuery] int limit = 100)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }

                requestModel.UserId = userId;

                if (requestModel == null)
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("Invalid request body"))));
                }
                if (string.IsNullOrEmpty(schemaname))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("Schema name can not be empty"))));
                }

                if (string.IsNullOrEmpty(searchtext))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("Search text can not be empty"))));
                }

                requestModel.SchemaName = schemaname;
                requestModel.SearchText = searchtext;
                requestModel.Skip       = skip;
                requestModel.Limit      = limit;
                var validationResult = requestModel.Validate();
                if (validationResult != null && validationResult.Any())
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(validationResult)));
                }

                return(new CommonActionResult(MongoConnector.SearchData(requestModel)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }
示例#2
0
        public IActionResult SearchGetData(string schemaname,
                                           string searchtext,
                                           [FromQuery] string websiteId,
                                           [FromQuery] string searchProperty,
                                           [FromQuery] string filter  = null,
                                           [FromQuery] string include = null,
                                           [FromQuery] string sort    = null,
                                           [FromQuery] int skip       = 0,
                                           [FromQuery] int limit      = 100)
        {
            try
            {
                var userId = AuthHelper.AuthorizeRequest(Request);
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommonActionResult(CommonAPIResponse.UnAuthorized()));
                }

                if (string.IsNullOrEmpty(schemaname))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("Schema name can not be empty"))));
                }
                if (string.IsNullOrEmpty(searchtext))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("Search text can not be empty"))));
                }
                if (string.IsNullOrEmpty(websiteId))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("WebsiteId can not be empty"))));
                }
                if (string.IsNullOrEmpty(searchProperty))
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(new System.ComponentModel.DataAnnotations.ValidationResult("Search Property can not be empty"))));
                }

                SearchDataRequestModel requestModel = new SearchDataRequestModel
                {
                    Filter         = filter,
                    Include        = include?.Split(',').ToList(),
                    Sort           = sort,
                    SearchProperty = searchProperty,
                    WebsiteId      = websiteId,
                    UserId         = userId,
                    SchemaName     = schemaname.Trim(' ').ToUpper(),
                    SearchText     = searchtext,
                    Skip           = skip,
                    Limit          = limit
                };
                var validationResult = requestModel.Validate();
                if (validationResult != null && validationResult.Any())
                {
                    return(new CommonActionResult(CommonAPIResponse.BadRequest(validationResult)));
                }

                return(new CommonActionResult(MongoConnector.SearchData(requestModel)));
            }
            catch (Exception ex)
            {
                return(new CommonActionResult(CommonAPIResponse.InternalServerError(ex)));
            }
        }