예제 #1
0
        public IActionResult GetResults(string entityName, [FromQuery] string fields, string searchText, string orderBy, string filters, int pageIndex, int pageSize)
        {
            try {
                var stopwatch = StopwatchLogger.Start(_log);
                _log.Info("Called EntityController GetResults");
                var tenantId     = TenantCode;
                var queryFilter  = ApiHelper.GetQueryFilter(filters, tenantId, IsSystemAdmin, entityName);
                var queryContext = new QueryContext {
                    Fields = fields, Filters = queryFilter, PageSize = pageSize, PageIndex = pageIndex, OrderBy = orderBy
                };

                if (!string.IsNullOrEmpty(searchText))
                {
                    var defaultLayout = _iILayoutManager.GetDefaultLayoutForEntity(TenantCode, entityName, (int)LayoutType.List, "", 0);
                    if (defaultLayout != null && defaultLayout.ListLayoutDetails != null && defaultLayout.ListLayoutDetails.SearchProperties != null)
                    {
                        var freeTextSearch = defaultLayout.ListLayoutDetails.SearchProperties.FirstOrDefault(t => t.Name.Equals("FreeTextSearch"));
                        if (freeTextSearch != null && freeTextSearch.Properties != null && freeTextSearch.Properties.Any())
                        {
                            queryContext.FreeTextSearch = new List <QueryFilter> ();
                            foreach (var prop in freeTextSearch.Properties)
                            {
                                var filter = new QueryFilter();
                                filter.FieldName = prop.Name;
                                filter.Operator  = Comparison.Like.ToString();
                                filter.Value     = searchText;
                                queryContext.FreeTextSearch.Add(filter);
                            }
                        }
                    }
                }
                var result = _iEntityResourceManager.GetResult(tenantId, entityName, queryContext);
                stopwatch.StopAndLog("GetResults of EntityController");

                if (result == null || result.Rows.Count <= 0)
                {
                    return(Ok(new { result = new List <string> (), totalRow = 0 }));
                }
                if (result.Columns.Contains("Context"))
                {
                    result = SetEntityNamebyCode(entityName, result);  //Added to get Entityname by Entity code for Email/SMSTemplate
                }
                dynamic totalRow = (result.Columns.Contains("totalRow")) ? result.Rows[0]["totalRow"] : result.Rows.Count;
                ApiHelper.MapDynamicColumn(result.Columns);
                return(Ok(new { result, totalRow }));
            } catch (FieldAccessException fx) {
                _log.Error(ExceptionFormatter.SerializeToString(fx));
                return(StatusCode((int)HttpStatusCode.BadRequest, fx.Message));
            } catch (Exception ex) {
                //return StatusCode((int)HttpStatusCode.InternalServerError, ex.Message);
                _log.Error(ExceptionFormatter.SerializeToString(ex));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
예제 #2
0
        public IActionResult ExecuteQuery(string entityName, [FromQuery] string fields, string orderBy, string filter, int maxCount, int pageIndex, int pageSize)
        {
            try
            {
                var stopwatch = StopwatchLogger.Start(_log);
                _log.Info("Called QueryController ExecuteQuery");

                if (string.IsNullOrEmpty(fields))
                {
                    return(BadRequest("Field required"));
                }
                var tenantId = TenantCode;

                var queryContext = new QueryContext
                {
                    Fields    = fields,
                    PageSize  = pageSize,
                    PageIndex = pageIndex,
                    MaxResult = maxCount,
                };
                if (!string.IsNullOrEmpty(filter))
                {
                    queryContext.Filters = CreateFilterObjFromString(filter);
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    queryContext.OrderBy = orderBy;
                }

                var result = _iEntityResourceManager.GetResult(tenantId, entityName, queryContext);

                stopwatch.StopAndLog("ExecuteQuery of QueryController");

                if (result == null || result.Rows.Count <= 0)
                {
                    return(Ok(new { result = new List <string>(), totalRow = 0 }));
                }
                dynamic totalRow = result.Rows[0]["totalRow"];
                ApiHelper.MapDynamicColumn(result.Columns);
                return(Ok(new { result, totalRow }));
            }
            catch (FieldAccessException fx) {
                //return BadRequest (fx.Message);
                _log.Error(ExceptionFormatter.SerializeToString(fx));
                return(StatusCode((int)HttpStatusCode.BadRequest, ApiConstant.CustomErrorMessage));
            } catch (Exception ex) {
                //return StatusCode ((int) HttpStatusCode.InternalServerError, ex.Message);
                _log.Error(ExceptionFormatter.SerializeToString(ex));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage));
            }
        }
예제 #3
0
        BatchTypeReturnMessage IBatchTypes.OnExecute(dynamic obj)
        {
            try
            {
                var           tenantId  = (Guid)obj[0];
                BatchTypeInfo batchType = (BatchTypeInfo)obj[1];
                var           result    = _iSettingManager.GetSettingsByContext(tenantId, SettingContextTypeEnum.EMAIL);

                if (result != null)
                {
                    EmailSenderOptions options = Newtonsoft.Json.JsonConvert.DeserializeObject <EmailSenderOptions>(result.Content);

                    //get mail in draft mode
                    var queryFilter1 = new List <QueryFilter>();
                    queryFilter1.Add(new QueryFilter {
                        FieldName = "CurrentWorkFlowStep", Operator = "Equal", Value = WorkFlowEngine.Draft.ToString()
                    });
                    queryFilter1.Add(new QueryFilter {
                        FieldName = "TenantId", Operator = "Equal", Value = tenantId.ToString()
                    });
                    // queryFilter1.Add(new QueryFilter{FieldName="CurrentWorkFlowStep",Operator="Equal" ,Value= WorkFlowEngine.Fail.ToString()});
                    var queryContext1 = new QueryContext {
                        Fields = "Date,Recipient,Sender,Subject,Body,CurrentWorkFlowStep", Filters = queryFilter1, PageSize = 100, PageIndex = 1
                    };
                    var emails      = _iEntityResourceManager.GetResult(tenantId, "email", queryContext1);
                    var emailMapped = EntityMapper <Email> .Mappers(emails);

                    if (emailMapped.Count > 0)
                    {
                        foreach (var emailMap in emailMapped)
                        {
                            var currentWorkFlowId = Guid.Empty;
                            if (emailMap.CurrentWorkFlowStep.Value == "Draft")
                            {
                                currentWorkFlowId = WorkFlowEngine.Draft;
                            }
                            else if (emailMap.CurrentWorkFlowStep.Value == "Send")
                            {
                                currentWorkFlowId = WorkFlowEngine.Sent;
                            }
                            else if (emailMap.CurrentWorkFlowStep.Value == "Failure")
                            {
                                currentWorkFlowId = WorkFlowEngine.Fail;
                            }
                            else if (emailMap.CurrentWorkFlowStep.Value == "Cancel")
                            {
                                currentWorkFlowId = WorkFlowEngine.Cancel;
                            }

                            var nextSteps      = _workFlow.GetNextPossibleSteps(tenantId, "email", "Standard", currentWorkFlowId);
                            var nextTransition = (from nextStep in nextSteps where nextStep.TransitionType.Id == WorkFlowEngine.Sent select nextStep).FirstOrDefault();

                            try
                            {
                                SendEmail(emailMap.Recipient.Value, emailMap.Subject.Value, emailMap.Body.Value, options);
                            }
                            catch (System.Exception ex)
                            {
                                _log.Error("An error has occurred while sending email", ex.Message);
                                nextTransition = (from nextStep in nextSteps where nextStep.TransitionType.Id == WorkFlowEngine.Fail select nextStep).FirstOrDefault();
                            }

                            var transitionWapper = new TransitionWapper
                            {
                                EntityName            = "email",
                                SubTypeName           = "Standard",
                                StepId                = nextTransition.InnerStepId,
                                RefId                 = Guid.Parse(emailMap.InternalId.Value),
                                CurrentTransitionType = currentWorkFlowId,
                                NextTransitionType    = nextTransition.TransitionType.Id
                            };

                            _workFlow.ManageTransitionFirstStep(tenantId, transitionWapper);
                        }
                    }
                }
                else
                {
                    _log.Error("Email gateway not configured");
                }
            }
            catch (System.Exception ex)
            {
                _log.Error("Email send failed", ex.Message);
            }

            return(new BatchTypeReturnMessage {
                NoDataFound = true
            });
        }