示例#1
0
        protected string GetEntityTitle(EntityType entityType, int entityId, bool checkAccess, out DomainObject entity)
        {
            switch (entityType)
            {
            case EntityType.Contact:
            case EntityType.Company:
            case EntityType.Person:
                var contact = (entity = _daoFactory.GetContactDao().GetByID(entityId)) as ASC.CRM.Core.Entities.Contact;
                if (contact == null || (checkAccess && !_crmSecurity.CanAccessTo(contact)))
                {
                    throw new ItemNotFoundException();
                }
                return(contact.GetTitle());

            case EntityType.Opportunity:
                var deal = (entity = _daoFactory.GetDealDao().GetByID(entityId)) as Deal;
                if (deal == null || (checkAccess && !_crmSecurity.CanAccessTo(deal)))
                {
                    throw new ItemNotFoundException();
                }
                return(deal.Title);

            case EntityType.Case:
                var cases = (entity = _daoFactory.GetCasesDao().GetByID(entityId)) as Cases;
                if (cases == null || (checkAccess && !_crmSecurity.CanAccessTo(cases)))
                {
                    throw new ItemNotFoundException();
                }
                return(cases.Title);

            default:
                throw new ArgumentException("Invalid entityType: " + entityType);
            }
        }
        public RelationshipEventDto Convert(RelationshipEvent source, RelationshipEventDto destination, ResolutionContext context)
        {
            var result = new RelationshipEventDto
            {
                Id       = source.ID,
                CreateBy = _employeeWraperHelper.Get(source.CreateBy),
                Created  = _apiDateTimeHelper.Get(source.CreateOn),
                Content  = source.Content,
                Files    = new List <FileWrapper <int> >(),
                CanEdit  = _crmSecurity.CanEdit(source)
            };


            var historyCategory = _daoFactory.GetListItemDao().GetByID(source.CategoryID);

            if (historyCategory != null)
            {
                result.Category = (HistoryCategoryBaseDto)context.Mapper.Map <HistoryCategoryDto>(historyCategory);
            }

            if (source.EntityID > 0)
            {
                result.Entity = _entityDtoHelper.Get(source.EntityType, source.EntityID);
            }

            result.Files = _daoFactory.GetRelationshipEventDao().GetFiles(source.ID).ConvertAll(file => _fileWrapperHelper.Get <int>(file));

            if (source.ContactID > 0)
            {
                var relativeContact = _daoFactory.GetContactDao().GetByID(source.ContactID);

                if (relativeContact != null)
                {
                    result.Contact = context.Mapper.Map <ContactBaseDto>(relativeContact);
                }
            }

            result.CanEdit = _crmSecurity.CanAccessTo(source);

            return(result);
        }
示例#3
0
        private SearchResultItem[] GetSearchResultItems(String[] keywords)
        {
            var result = new List <SearchResultItem>();

            if (IncludeToSearch(EntityType.Task))
            {
                var sqlQuery = Query(CrmDbContext.Tasks);

                if (_findedIDs.ContainsKey(EntityType.Task))
                {
                    sqlQuery = sqlQuery.Where(x => _findedIDs[EntityType.Task].Contains(x.Id));
                }
                else
                {
                    if (keywords.Length > 0)
                    {
                        foreach (var k in keywords)
                        {
                            sqlQuery = sqlQuery.Where(x => Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Title, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Description, k + "%"));
                        }
                    }
                }

                sqlQuery.ToList().ForEach(x =>
                {
                    if (!_crmSecurity.CanAccessTo(new Task {
                        ID = x.Id
                    }))
                    {
                        return;
                    }

                    result.Add(new SearchResultItem
                    {
                        Name        = x.Title,
                        Description = HtmlUtil.GetText(x.Description, 120),
                        URL         = _pathProvider.BaseAbsolutePath,
                        Date        = _tenantUtil.DateTimeFromUtc(x.CreateOn),
                        Additional  = new Dictionary <String, Object>
                        {
                            { "imageRef", _webImageSupplier.GetAbsoluteWebPath("tasks_widget.png", ProductEntryPoint.ID) },
                            { "relativeInfo", GetPath(
                                  x.ContactId,
                                  x.EntityId,
                                  x.EntityType) },
                            { "typeInfo", EntityType.Task.ToLocalizedString() }
                        }
                    });
                });
            }

            if (IncludeToSearch(EntityType.Opportunity))
            {
                var sqlQuery = Query(CrmDbContext.Deals);

                if (_findedIDs.ContainsKey(EntityType.Opportunity))
                {
                    sqlQuery = sqlQuery.Where(x => _findedIDs[EntityType.Opportunity].Contains(x.Id));
                }
                else
                {
                    if (keywords.Length > 0)
                    {
                        foreach (var k in keywords)
                        {
                            sqlQuery = sqlQuery.Where(x => Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Title, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Description, k + "%"));
                        }
                    }
                }


                sqlQuery.ToList().ForEach(x =>
                {
                    if (!_crmSecurity.CanAccessTo(new Deal {
                        ID = x.Id
                    }))
                    {
                        return;
                    }

                    result.Add(new SearchResultItem
                    {
                        Name        = x.Title,
                        Description = HtmlUtil.GetText(x.Description, 120),
                        URL         = string.Concat(_pathProvider.BaseAbsolutePath, string.Format("deals.aspx?id={0}", x.Id)),
                        Date        = _tenantUtil.DateTimeFromUtc(x.CreateOn),
                        Additional  = new Dictionary <string, object>
                        {
                            { "imageRef", _webImageSupplier.GetAbsoluteWebPath("deal_widget.png", ProductEntryPoint.ID) },
                            { "relativeInfo", GetPath(
                                  x.ContactId,
                                  0,
                                  0) },
                            { "typeInfo", EntityType.Opportunity.ToLocalizedString() }
                        }
                    });
                });
            }


            if (IncludeToSearch(EntityType.Contact))
            {
                var sqlQuery = Query(CrmDbContext.Contacts);

                if (_findedIDs.ContainsKey(EntityType.Contact))
                {
                    sqlQuery = sqlQuery.Where(x => _findedIDs[EntityType.Contact].Contains(x.Id));
                }
                else
                {
                    if (keywords.Length > 0)
                    {
                        foreach (var k in keywords)
                        {
                            sqlQuery = sqlQuery.Where(x => Microsoft.EntityFrameworkCore.EF.Functions.Like(x.FirstName, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.LastName, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.CompanyName, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Title, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Notes, k + "%")
                                                      );
                        }
                    }
                }

                sqlQuery.ToList().ForEach(x =>
                {
                    if (x.IsCompany)
                    {
                        if (!_crmSecurity.CanAccessTo(new Company {
                            ID = x.Id
                        }))
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (!_crmSecurity.CanAccessTo(new Person {
                            ID = x.Id
                        }))
                        {
                            return;
                        }
                    }

                    result.Add(new SearchResultItem
                    {
                        Name        = x.IsCompany ? x.CompanyName : String.Format("{0} {1}", x.FirstName, x.LastName),
                        Description = HtmlUtil.GetText(x.Notes, 120),
                        URL         = String.Concat(_pathProvider.BaseAbsolutePath, String.Format("default.aspx?id={0}", x.Id)),
                        Date        = _tenantUtil.DateTimeFromUtc(x.CreateOn),
                        Additional  = new Dictionary <String, Object>
                        {
                            { "imageRef", _webImageSupplier.GetAbsoluteWebPath(x.IsCompany ? "companies_widget.png" : "people_widget.png", ProductEntryPoint.ID) },
                            { "relativeInfo", GetPath(
                                  0,
                                  0,
                                  0) },
                            { "typeInfo", EntityType.Contact.ToLocalizedString() }
                        }
                    });
                });
            }

            if (IncludeToSearch(EntityType.Case))
            {
                var sqlQuery = Query(CrmDbContext.Cases);

                if (_findedIDs.ContainsKey(EntityType.Case))
                {
                    sqlQuery = sqlQuery.Where(x => _findedIDs[EntityType.Case].Contains(x.Id));
                }
                else
                {
                    if (keywords.Length > 0)
                    {
                        foreach (var k in keywords)
                        {
                            sqlQuery = sqlQuery.Where(x => Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Title, k + "%"));
                        }
                    }
                }

                sqlQuery.ToList().ForEach(x =>
                {
                    if (!_crmSecurity.CanAccessTo(new Cases {
                        ID = x.Id
                    }))
                    {
                        return;
                    }

                    result.Add(new SearchResultItem
                    {
                        Name        = x.Title,
                        Description = String.Empty,
                        URL         = String.Concat(_pathProvider.BaseAbsolutePath, String.Format("cases.aspx?id={0}", x.Id)),
                        Date        = _tenantUtil.DateTimeFromUtc(x.CreateOn),
                        Additional  = new Dictionary <String, Object>
                        {
                            { "imageRef", _webImageSupplier.GetAbsoluteWebPath("cases_widget.png", ProductEntryPoint.ID) },
                            { "relativeInfo", GetPath(
                                  0,
                                  0,
                                  0) },
                            { "typeInfo", EntityType.Case.ToLocalizedString() }
                        }
                    });
                });
            }


            if (IncludeToSearch(EntityType.Invoice))
            {
                var sqlQuery = Query(CrmDbContext.Invoices);

                if (_findedIDs.ContainsKey(EntityType.Invoice))
                {
                    sqlQuery = sqlQuery.Where(x => _findedIDs[EntityType.Invoice].Contains(x.Id));
                }
                else
                {
                    if (keywords.Length > 0)
                    {
                        foreach (var k in keywords)
                        {
                            sqlQuery = sqlQuery.Where(x => Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Number, k + "%") ||
                                                      Microsoft.EntityFrameworkCore.EF.Functions.Like(x.Description, k + "%"));
                        }
                    }
                }

                sqlQuery.ToList().ForEach(x =>
                {
                    if (!_crmSecurity.CanAccessTo(new Invoice {
                        ID = x.Id
                    }))
                    {
                        return;
                    }

                    result.Add(new SearchResultItem
                    {
                        Name        = x.Number,
                        Description = String.Empty,
                        URL         = String.Concat(_pathProvider.BaseAbsolutePath, String.Format("invoices.aspx?id={0}", x.Id)),
                        Date        = _tenantUtil.DateTimeFromUtc(x.CreateOn),
                        Additional  = new Dictionary <String, Object>
                        {
                            { "imageRef", _webImageSupplier.GetAbsoluteWebPath("invoices_widget.png", ProductEntryPoint.ID) },
                            { "relativeInfo", GetPath(
                                  x.ContactId,
                                  x.EntityId,
                                  x.EntityType) },
                            { "typeInfo", EntityType.Invoice.ToLocalizedString() }
                        }
                    });
                });
            }

            return(result.ToArray());
        }