Esempio n. 1
0
        public IActionResult Get(long id)
        {
            var @case = _repository.Read()
                        .Include(x => x.Tags)
                        .Include(x => x.Steps)
                        .Include(x => x.Links)
                        .Include(x => x.Attachments)
                        .Include(x => x.EmailTemplates)
                        .Where(x => x.Id == id && x.IsDeleted == false)
                        .Select(x => Dto.FromModel(x))
                        .FirstOrDefault();

            if (@case is null)
            {
                return(NotFound());
            }
            return(Ok(@case));
        }
Esempio n. 2
0
        public List <CategoryDto> Get(string query)
        {
            var queryable = _repository.Read().Where(c => c.IsDeleted == false);

            if (!string.IsNullOrWhiteSpace(query))
            {
                queryable = queryable.Where(c =>
                                            c.Category.Contains(query) ||
                                            c.Title.Contains(query) ||
                                            c.Tags.Any(tag => tag.Name.Contains(query)) ||
                                            c.Steps.Any(step => step.Description.Contains(query)));
            }

            var casesByCategory = queryable
                                  .GroupBy(c => c.Category)
                                  .Select(g => new CategoryDto {
                Name = g.Key, Cases = g.Select(x => Dto.FromModel(x))
            })
                                  .ToList();

            return(casesByCategory);
        }
Esempio n. 3
0
        public override async Task <SaveResponse <IDocument> > SaveAsync(IDocument item)
        {
            var response = new SaveResponse <IDocument>();

            try
            {
                using (var connection = ConnectionFactory.GetConnection())
                {
                    var trans            = connection.BeginTransaction();
                    var sql              = GetDocumentMergeStatement();
                    var mergeDocumentDto = await connection.QuerySingleAsync <DocumentDto>(sql, Dto.FromModel(item), trans);

                    var document = mergeDocumentDto.ToModel();

                    var fieldDtos = item.Fields.Select(f =>
                    {
                        var fieldDto = new MergeDocumentFieldDto
                        {
                            DocumentId = document.Id
                        };
                        return((MergeDocumentFieldDto)fieldDto.FromModel(f));
                    }).AsList();

                    foreach (var fieldDto in fieldDtos)
                    {
                        document.Fields.Add(
                            connection.QuerySingle <MergeDocumentFieldDto>(GetFieldMergeStatement(), fieldDto, trans).ToModel());
                    }

                    trans.Commit();


                    document.Fields = fieldDtos
                                      .Select(dto => dto.ToModel())
                                      .AsList();

                    response.Content = document;
                    response.Message = $@"Merge document {document.Name} was inserted/updated successfully.";
                }
            }
            catch (Exception e)
            {
                var message = $@"Error saving merge document.";
                LogManager.LogError(e, message);
                response.AddError(e);
                Console.WriteLine(e);
            }

            return(response);
        }
Esempio n. 4
0
 public IEnumerable <TagDto> Get([FromQuery] long tenant)
 {
     return(_repository.Read().Where(tag => tag.Case.TenantId == tenant).Select(m => Dto.FromModel(m)).ToList());
 }
Esempio n. 5
0
        public override async Task <SaveResponse <IRuleSet> > SaveAsync(IRuleSet item)
        {
            var response = new SaveResponse <IRuleSet>();

            try
            {
                var sql = GetMergeStatement();
                using (var connection = ConnectionFactory.GetConnection())
                {
                    using (var trans = connection.BeginTransaction())
                    {
                        // Save rule set
                        var ruleSetDto = await connection.QuerySingleAsync <RuleSetDto>(sql, Dto.FromModel(item), trans);

                        // Save rules
                        var ruleDtos = item.Rules
                                       .Select(r =>
                        {
                            var dto = (RuleDto) new RuleDto()
                                      .FromModel(r);
                            dto.RuleSetId = ruleSetDto.Id;

                            return(dto);
                        });

                        await connection.ExecuteAsync(GetRuleMergeStatement(), ruleDtos, trans);

                        trans.Commit();

                        sql = $@"{GetRuleSelectStatement()} AND RuleSetId = @ruleSetId;";
                        var results = await connection.QueryAsync <RuleDto>(sql, new { RuleSetId = ruleSetDto.Id });

                        var ruleSet = ruleSetDto.ToModel();
                        ruleSet.Rules = results
                                        .Select(dto => dto.ToModel())
                                        .AsList();

                        response.Content = ruleSet;
                        response.Message = $@"RuleSet: {item.Name} record was inserted/updated.";
                    }
                }
            }
            catch (Exception e)
            {
                var message = $@"Error saving RuleSet information.";
                LogManager.LogError(e, message);
                response.AddError(e);
                Console.WriteLine(e);
            }

            return(response);
        }
Esempio n. 6
0
        public async Task <SaveResponse <IReadOnlyList <ISales> > > SaveAllSalesAsync(IReadOnlyList <ISales> items)
        {
            var response = new SaveResponse <IReadOnlyList <ISales> >();

            try
            {
                if (items.Any())
                {
                    using (var connection = ConnectionFactory.GetConnection())
                    {
                        var sql     = "spmSales";
                        var results = await connection.ExecuteAsync(sql, items.Select(m => Dto.FromModel(m)), commandType : CommandType.StoredProcedure);

                        response.Content = items;
                        response.Message = $@"Sales records were inserted/updated.";
                    }
                }
            }
            catch (Exception e)
            {
                var message = $@"Error saving Sales information.";
                LogManager.LogError(e, message);
                response.AddError(e);
                Console.WriteLine(e);
            }

            return(response);
        }
Esempio n. 7
0
        public override async Task <SaveResponse <IAuditWorkflow> > SaveAsync(IAuditWorkflow item)
        {
            var response = new SaveResponse <IAuditWorkflow>();

            try
            {
                var sql = GetMergeStatement();
                using (var connection = ConnectionFactory.GetConnection())
                {
                    using (var trans = connection.BeginTransaction())
                    {
                        // Save workflow
                        var workflowDto = await connection.QuerySingleAsync <WorkflowDto>(sql, Dto.FromModel(item), trans);

                        // Save workflow steps
                        var workflowStepDtos = item.Steps.Values
                                               .Select(r =>
                        {
                            var dto = (WorkflowStepDto) new WorkflowStepDto()
                                      .FromModel(r);
                            dto.WorkflowId = workflowDto.Id;

                            return(dto);
                        });

                        await connection.ExecuteAsync(GetWorkflowStepMergeStatement(), workflowStepDtos, trans);

                        trans.Commit();

                        // Get the workflow now that the IDs have been created
                        var getResponse = await GetByIdAsync(workflowDto.Id);

                        response.Join <SaveResponse <IAuditWorkflow> >(getResponse);

                        response.Content = getResponse.Content;
                        response.Message = $@"RuleSet: {item.Name} record was inserted/updated.";
                    }
                }
            }
            catch (Exception e)
            {
                var message = $@"Error saving RuleSet information.";
                LogManager.LogError(e, message);
                response.AddError(e);
                Console.WriteLine(e);
            }

            return(response);
        }