コード例 #1
0
        private void Copy(TicketPart source, ContentItemPermissionPart sourcePermissionPart, task destination, TicketContext context)
        {
            destination.name     = source.Record.Title.Length > 50 ? source.Record.Title.Substring(0, 50) : source.Record.Title;
            destination.date_due = source.Record.DueDate;

            // status
            if (source.Record.StatusRecord != null)
            {
                var status = context.StatusList.FirstOrDefault(c => c.Id == source.Record.StatusRecord.Id);
                if (status != null)
                {
                    destination.status = status.Name;
                }
            }

            // priority
            if (source.Record.PriorityRecord != null)
            {
                var priority = context.Priorities.FirstOrDefault(c => c.Id == source.Record.PriorityRecord.Id);
                if (priority != null)
                {
                    destination.priority = priority.Name;
                }
            }

            CommonPart commonPart = source.As <CommonPart>();

            if (commonPart != null && commonPart.ModifiedUtc.HasValue)
            {
                destination.date_modified = commonPart.ModifiedUtc;
            }

            destination.assigned_user_id = this.GetAssigneeUserExternalId(sourcePermissionPart);
            destination.created_by       = this.GetOwnerUserExternalId(commonPart);
        }
コード例 #2
0
        protected override void OnDisplay(ContentItem contentItem, dynamic model)
        {
            TicketPart ticketPart = contentItem.As <TicketPart>();

            if (ticketPart.Record.RelatedContentItem != null)
            {
                var        relatedContentItem = this.contentManager.Get(ticketPart.Record.RelatedContentItem.Id, VersionOptions.AllVersions);
                TitlePart  titlePart          = relatedContentItem.As <TitlePart>();
                CommonPart commonPart         = relatedContentItem.As <CommonPart>();

                if (titlePart != null && commonPart != null)
                {
                    model.RelatedContentItem = new
                    {
                        Owner       = commonPart.Owner,
                        Title       = titlePart.Title,
                        Id          = relatedContentItem.Id,
                        ContentType = relatedContentItem.ContentType
                    };
                }
            }

            model.IsCurrentUserCustomer          = this.crmContentOwnershipService.IsCurrentUserCustomer();
            model.CurrentUserCanEditContent      = this.crmContentOwnershipService.CurrentUserCanEditContent(contentItem);
            model.CurrentUserCanChangePermission = this.crmContentOwnershipService.CurrentUserCanChangePermission(contentItem, new ModelStateDictionary());
        }
コード例 #3
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            CommonPart contentPart = value as CommonPart;

            // CreatedUtc
            Utility.WriteProperty("CreatedUtc", contentPart.CreatedUtc, writer, serializer);

            // PublishedUtc
            Utility.WriteProperty("PublishedUtc", contentPart.PublishedUtc, writer, serializer);

            // ModifiedUtc
            Utility.WriteProperty("ModifiedUtc", contentPart.ModifiedUtc, writer, serializer);

            // VersionCreatedUtc
            Utility.WriteProperty("VersionCreatedUtc", contentPart.VersionCreatedUtc, writer, serializer);

            // VersionModifiedUtc
            Utility.WriteProperty("VersionModifiedUtc", contentPart.VersionModifiedUtc, writer, serializer);

            // VersionPublishedUtc
            Utility.WriteProperty("VersionPublishedUtc", contentPart.VersionPublishedUtc, writer, serializer);

            this.WriteCommonFields(writer, contentPart, serializer);

            writer.WriteEnd();
        }
コード例 #4
0
        private void AssignRemovingDates(RemoveContentContext context, CommonPart part)
        {
            var utcNow = _clock.UtcNow;

            part.ModifiedUtc        = utcNow;
            part.VersionModifiedUtc = utcNow;
        }
コード例 #5
0
        protected void AssignPublishingDates(PublishContentContext context, CommonPart part)
        {
            var utcNow = _clock.UtcNow;

            part.PublishedUtc        = utcNow;
            part.VersionPublishedUtc = utcNow;
        }
コード例 #6
0
        private void AssignUpdateDates(UpdateEditorContext context, CommonPart part)
        {
            var utcNow = _clock.UtcNow;

            part.ModifiedUtc        = utcNow;
            part.VersionModifiedUtc = utcNow;
        }
コード例 #7
0
        protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part)
        {
            // add handlers that will update records when part properties are set

            part.OwnerField.Setter(user => {
                part.Record.OwnerId = user == null
                                           ? 0
                                           : user.ContentItem.Id;
                return(user);
            });

            // Force call to setter if we had already set a value
            if (part.OwnerField.Value != null)
            {
                part.OwnerField.Value = part.OwnerField.Value;
            }

            part.ContainerField.Setter(container => {
                part.Record.Container = container == null
                                               ? null
                                               : container.ContentItem.Record;
                return(container);
            });

            // Force call to setter if we had already set a value
            if (part.ContainerField.Value != null)
            {
                part.ContainerField.Value = part.ContainerField.Value;
            }
        }
コード例 #8
0
        public FieldCreatortHandler(
            IOrchardServices orchardServices,
            IDraftFieldIndexService draftFieldIndexService)
        {
            _orchardServices        = orchardServices;
            _draftFieldIndexService = draftFieldIndexService;

            OnUpdated <CommonPart>((context, CommonPart) => {
                if (CommonPart != null && _orchardServices.WorkContext != null)
                {
                    var currentUser = _orchardServices.WorkContext.CurrentUser;
                    if (currentUser != null)
                    {
                        var currentUserId = Convert.ToDecimal((decimal)currentUser.Id);
                        var dynCommonPart = (dynamic)CommonPart;

                        // Set the values for the infoset
                        dynCommonPart.LastModifier.Value = currentUserId;
                        if (dynCommonPart.Creator.Value == null)
                        {
                            dynCommonPart.Creator.Value = currentUserId;
                        }
                        // Set the values in the records for the projections
                        var fieldIndexPart = CommonPart.As <FieldIndexPart>();
                        if (fieldIndexPart != null)
                        {
                            _draftFieldIndexService.Set(fieldIndexPart,
                                                        "CommonPart", "LastModifier",
                                                        null, currentUserId, typeof(decimal));
                            if (_draftFieldIndexService.Get <decimal>(fieldIndexPart,
                                                                      "CommonPart", "Creator", null) == default(decimal))
                            {
                                _draftFieldIndexService.Set(fieldIndexPart,
                                                            "CommonPart", "Creator",
                                                            null, currentUserId, typeof(decimal));
                            }
                        }
                    }
                }
            });

            OnCreated <CommonPart>((context, CommonPart) => {
                if (context.ContentItem.As <CommonPart>() != null && _orchardServices.WorkContext != null)
                {
                    var currentUser = _orchardServices.WorkContext.CurrentUser;
                    if (currentUser != null)
                    {
                        var currentUserId = Convert.ToDecimal((decimal)currentUser.Id);
                        var dynCommonPart = (dynamic)context.ContentItem.As <CommonPart>();
                        // Set the values for the infoset
                        if (dynCommonPart.Creator.Value == null)
                        {
                            dynCommonPart.Creator.Value = currentUserId;
                        }
                        // Don't set the values in the records because, at creation, there is no record, yet.
                    }
                }
            });
        }
コード例 #9
0
            private void _read()
            {
                _commonPart = new CommonPart(m_io, this, m_root);
                __raw_typeSpecificPartRawWithIo = m_io.ReadBytes((CommonPart.LenHeader - 12));
                var io___raw_typeSpecificPartRawWithIo = new KaitaiStream(__raw_typeSpecificPartRawWithIo);

                _typeSpecificPartRawWithIo = new BytesWithIo(io___raw_typeSpecificPartRawWithIo);
            }
コード例 #10
0
 protected void AssignCreatingDates(InitializingContentContext context, CommonPart part) {
     // assign default create/modified dates
     var utcNow = _clock.UtcNow;
     part.CreatedUtc = utcNow;
     part.ModifiedUtc = utcNow;
     part.VersionCreatedUtc = utcNow;
     part.VersionModifiedUtc = utcNow;
 }
コード例 #11
0
 protected void AssignCreatingOwner(InitializingContentContext context, CommonPart part)
 {
     // and use the current user as Owner
     if (part.Record.OwnerId == 0)
     {
         part.Owner = _authenticationService.GetAuthenticatedUser();
     }
 }
コード例 #12
0
        private void AssignUpdatingDates(UpdateContentContext context, CommonPart part)
        {
            var utcNow = _clock.UtcNow;

            part.ModifiedUtc        = utcNow;
            part.VersionModifiedUtc = utcNow;
            part.VersionModifiedBy  = GetUserName();
        }
コード例 #13
0
        private string DeterminePartType(CommonPart part, ICollection <PartType> partTypes)
        {
            var possiblePartTypes = GetMatchingPartTypes(part, partTypes);

            return(possiblePartTypes
                   .OrderByDescending(x => x.Value)
                   .Select(x => x.Key?.Name)
                   .FirstOrDefault());
        }
コード例 #14
0
        private void ProcessCasePostsCount(CasePostPart CasePostPart)
        {
            CommonPart commonPart = CasePostPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                _CaseService.ProcessCasePostsCount(commonPart.Container.Id);
            }
        }
コード例 #15
0
        protected void AssignCreatingDates(InitializingContentContext context, CommonPart part)
        {
            // assign default create/modified dates
            var utcNow = _clock.UtcNow;

            part.CreatedUtc         = utcNow;
            part.ModifiedUtc        = utcNow;
            part.VersionCreatedUtc  = utcNow;
            part.VersionModifiedUtc = utcNow;
        }
コード例 #16
0
        private void ProcessBlogPostsCount(BlogPostPart blogPostPart)
        {
            CommonPart commonPart = blogPostPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                _blogService.ProcessBlogPostsCount(commonPart.Container.Id);
            }
        }
コード例 #17
0
        private ContentPart CreateCommonPart(CommonPartDto commonPartDto)
        {
            var commonPart = new CommonPart();

            commonPart.Id            = commonPartDto.Id;
            commonPart.ResourceUrl   = commonPartDto.ResourceUrl;
            commonPart.CreatedDate   = DateTime.Parse(commonPartDto.CreatedUtc);
            commonPart.PublishedDate = DateTime.Parse(commonPartDto.PublishedUtc);

            return(commonPart);
        }
コード例 #18
0
        public void Copy(ProjectPart source, project destination)
        {
            destination.name        = source.Record.Title.Length > 50 ? source.Record.Title.Substring(0, 50) : source.Record.Title;
            destination.description = source.Record.Description;

            CommonPart commonPart = source.As <CommonPart>();

            if (commonPart != null && commonPart.ModifiedUtc.HasValue)
            {
                destination.date_modified = commonPart.ModifiedUtc;
            }
        }
コード例 #19
0
        private ICollection <string> DetermineKeywords(CommonPart part, ICollection <PartType> partTypes)
        {
            // part type
            // important parts from description
            // alternate series numbers etc
            var keywords          = new List <string>();
            var possiblePartTypes = GetMatchingPartTypes(part, partTypes);

            foreach (var possiblePartType in possiblePartTypes)
            {
                if (!keywords.Contains(possiblePartType.Key.Name, StringComparer.InvariantCultureIgnoreCase))
                {
                    keywords.Add(possiblePartType.Key.Name.ToLower());
                }
            }

            if (!keywords.Contains(part.ManufacturerPartNumber, StringComparer.InvariantCultureIgnoreCase))
            {
                keywords.Add(part.ManufacturerPartNumber.ToLower());
            }
            var desc = part.Description.ToLower().Split(new string[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            // add the first 4 words of desc
            var wordCount    = 0;
            var ignoredWords = new string[] { "and", "the", "in", "or", "in", "a", };

            foreach (var word in desc)
            {
                if (!ignoredWords.Contains(word, StringComparer.InvariantCultureIgnoreCase) && !keywords.Contains(word, StringComparer.InvariantCultureIgnoreCase))
                {
                    keywords.Add(word.ToLower());
                    wordCount++;
                }
                if (wordCount >= 4)
                {
                    break;
                }
            }
            foreach (var basePart in part.AdditionalPartNumbers)
            {
                if (basePart != null && !keywords.Contains(basePart, StringComparer.InvariantCultureIgnoreCase))
                {
                    keywords.Add(basePart.ToLower());
                }
            }
            var mountingType = (MountingType)part.MountingTypeId;

            if (!string.IsNullOrEmpty(mountingType.ToString()) && !keywords.Contains(mountingType.ToString(), StringComparer.InvariantCultureIgnoreCase))
            {
                keywords.Add(mountingType.ToString().ToLower());
            }

            return(keywords.Distinct().ToList());
        }
コード例 #20
0
        private void UpdateBlogPostCount(BlogPostPart blogPostPart)
        {
            CommonPart commonPart = blogPostPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                BlogPart blogPart = blogPostPart.BlogPart ??
                                    _blogService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As <BlogPart>();

                // Ensure the "right" set of published posts for the blog is obtained
                blogPart.PostCount = _blogPostService.PostCount(blogPart);
            }
        }
コード例 #21
0
        protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building)
        {
            var utcNow = _clock.UtcNow;

            // assign the created date
            building.VersionCreatedUtc = utcNow;
            // assign modified date for the new version
            building.VersionModifiedUtc = utcNow;
            // publish date should be null until publish method called
            building.VersionPublishedUtc = null;

            // assign the created
            building.CreatedUtc = existing.CreatedUtc ?? _clock.UtcNow;
            // persist any published dates
            building.PublishedUtc = existing.PublishedUtc;
            // assign modified date for the new version
            building.ModifiedUtc = _clock.UtcNow;
        }
コード例 #22
0
        private string GetOwnerUserExternalId(CommonPart commonPart)
        {
            // assignee user
            if (commonPart.Owner != null)
            {
                var user = this.services.ContentManager.Get <IUser>(commonPart.Owner.Id);
                if (user != null)
                {
                    SuiteCRMUserPart userPart = user.As <SuiteCRMUserPart>();

                    if (userPart != null && !string.IsNullOrEmpty(userPart.ExternalId))
                    {
                        return(userPart.ExternalId);
                    }
                }
            }

            return(null);
        }
コード例 #23
0
        private IDictionary <PartType, int> GetMatchingPartTypes(CommonPart part, ICollection <PartType> partTypes)
        {
            // load all part types
            var possiblePartTypes = new Dictionary <PartType, int>();

            foreach (var partType in partTypes)
            {
                if (string.IsNullOrEmpty(partType.Name))
                {
                    continue;
                }
                var addPart = false;
                if (part.Description?.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    addPart = true;
                }
                if (part.ManufacturerPartNumber?.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    addPart = true;
                }
                foreach (var datasheet in part.DatasheetUrls)
                {
                    if (datasheet.IndexOf(partType.Name, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        addPart = true;
                    }
                }
                if (addPart)
                {
                    if (possiblePartTypes.ContainsKey(partType))
                    {
                        possiblePartTypes[partType]++;
                    }
                    else
                    {
                        possiblePartTypes.Add(partType, 1);
                    }
                }
            }
            return(possiblePartTypes);
        }
コード例 #24
0
        protected void FillStatusTimes(TicketViewModel model, TicketPart part, IEnumerable <StatusRecordViewModel> statusRecords)
        {
            CommonPart commonPart = part.As <CommonPart>();
            List <KeyValuePair <int, DateTime> > output = new List <KeyValuePair <int, DateTime> >();

            // creation time
            if (commonPart != null && commonPart.CreatedUtc.HasValue)
            {
                output.Add(new KeyValuePair <int, DateTime>(StatusRecord.NewStatus, CRMHelper.SetSiteTimeZone(this.orchardServices.WorkContext, commonPart.CreatedUtc.Value)));
            }

            var statusTimes = part.StatusTimes;

            foreach (var item in statusTimes)
            {
                var statusRecord = statusRecords.FirstOrDefault(c => c.Id == item.Key);
                if (statusRecord == null)
                {
                    continue;
                }

                int?statusTypeId = statusRecord.StatusTypeId.HasValue?
                                   statusRecord.StatusTypeId.Value:
                                   statusRecords
                                   .Where(c => c.OrderId <= statusRecord.OrderId && c.StatusTypeId.HasValue)
                                   .Select(c => c.StatusTypeId)
                                   .OrderByDescending(c => c)
                                   .FirstOrDefault();

                statusTypeId = statusTypeId ?? StatusRecord.NewStatus;
                output.Add(new KeyValuePair <int, DateTime>(statusTypeId.Value, CRMHelper.SetSiteTimeZone(this.orchardServices.WorkContext, item.Value)));
            }

            model.StatusTimes.Clear();
            model.StatusTimes.AddRange(output.OrderBy(c => c.Value));
        }
コード例 #25
0
        public IEnumerable <SuiteCRMTaskDetailViewModel> CopyOrchardTicketsToSuite(CopyOrchardTasksToSuiteViewModel model)
        {
            List <SuiteCRMTaskDetailViewModel> returnValue = new List <SuiteCRMTaskDetailViewModel>();

            using (var connection = Helper.GetConnection(this.services, this.Logger))
                using (SuiteCRMTaskUnitOfWork taskRepository = new SuiteCRMTaskUnitOfWork(connection))
                    using (SuiteCRMEmailAddressBeanUnitOfWork suiteCRMEmailAddressBeanUnitOfWork = new SuiteCRMEmailAddressBeanUnitOfWork(taskRepository))
                        using (SuiteCRMEmailAddressUnitOfWork suiteCRMEmailAddressUnitOfWork = new SuiteCRMEmailAddressUnitOfWork(taskRepository))
                            using (SuiteCRMProjectTaskUnitOfWork projectTasksRepository = new SuiteCRMProjectTaskUnitOfWork(taskRepository))
                                using (var suiteCRMTransaction = taskRepository.BeginTransaction())
                                {
                                    TicketContext context = new TicketContext();
                                    context.ProjectTaskUnitOfWork = projectTasksRepository;
                                    context.Priorities            = this.priorityRepository.Table.ToList();
                                    context.StatusList            = this.statusRepository.Table.ToList();

                                    try
                                    {
                                        var taskIds           = model.Tasks.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)).Select(c => c.SuiteCRMId).ToArray();
                                        var suiteTasks        = taskRepository.GetTasks(taskIds);
                                        var suiteProjectTasks = projectTasksRepository.GetTasks(taskIds);
                                        var orchardTickets    = this.services
                                                                .ContentManager
                                                                .GetMany <SuiteCRMTaskPart>(
                                            model.Tasks.Where(c => c.OrchardCollaborationTicketId.HasValue).Select(c => c.OrchardCollaborationTicketId.Value),
                                            VersionOptions.Published,
                                            new QueryHints().ExpandParts <TicketPart>());

                                        foreach (var item in model.Tasks)
                                        {
                                            if (item.OrchardCollaborationTicketId == null)
                                            {
                                                continue;
                                            }

                                            var ticket = orchardTickets.FirstOrDefault(c => c.Id == item.OrchardCollaborationTicketId.Value);

                                            var        suiteCRMTaskPart = ticket.As <SuiteCRMTaskPart>();
                                            TicketPart ticketPart       = ticket.As <TicketPart>();
                                            ContentItemPermissionPart permissionPart      = ticket.As <ContentItemPermissionPart>();
                                            AttachToProjectPart       attachToProjectPart = ticket.As <AttachToProjectPart>();
                                            SuiteCRMProjectPart       projectPart         = null;

                                            if (!this.IsSyncingTicketValid(item, ticket, out projectPart))
                                            {
                                                continue;
                                            }

                                            project_task suiteCRMProjectTask = null;
                                            task         suiteCRMTask        = null;

                                            if (!string.IsNullOrEmpty(suiteCRMTaskPart.ExternalId) && item.IsProjectTask)
                                            {
                                                suiteCRMProjectTask = suiteProjectTasks.FirstOrDefault(c => c.id == suiteCRMTaskPart.ExternalId);
                                            }

                                            if (!string.IsNullOrEmpty(suiteCRMTaskPart.ExternalId) && !item.IsProjectTask)
                                            {
                                                suiteCRMTask = suiteTasks.FirstOrDefault(c => c.id == suiteCRMTaskPart.ExternalId);
                                            }

                                            if (suiteCRMProjectTask == null && item.IsProjectTask)
                                            {
                                                suiteCRMProjectTask            = new project_task();
                                                suiteCRMProjectTask.project_id = item.SuiteCRMId;
                                                projectTasksRepository.Add(suiteCRMProjectTask);
                                            }

                                            if (suiteCRMTask == null && !item.IsProjectTask)
                                            {
                                                suiteCRMTask = new task();
                                                taskRepository.Add(suiteCRMTask);
                                            }

                                            CommonPart commonPart = ticketPart.As <CommonPart>();
                                            DateTime?  lastOrchardTicketChangeDate = commonPart.ModifiedUtc ?? commonPart.CreatedUtc;
                                            if (suiteCRMProjectTask != null &&
                                                (
                                                    !item.DoNotOverrideNewerValues ||
                                                    suiteCRMProjectTask.date_modified == null ||
                                                    (lastOrchardTicketChangeDate.HasValue &&
                                                     suiteCRMProjectTask.date_modified.Value <= lastOrchardTicketChangeDate.Value)
                                                ))
                                            {
                                                this.Copy(ticketPart, permissionPart, suiteCRMProjectTask, context);
                                                suiteCRMProjectTask.project_id = projectPart.ExternalId;
                                                projectTasksRepository.Save();
                                            }

                                            if (suiteCRMTask != null &&
                                                (
                                                    !item.DoNotOverrideNewerValues ||
                                                    suiteCRMTask.date_modified == null ||
                                                    (lastOrchardTicketChangeDate.HasValue &&
                                                     suiteCRMTask.date_modified.Value <= lastOrchardTicketChangeDate.Value)
                                                ))
                                            {
                                                this.Copy(ticketPart, permissionPart, suiteCRMTask, context);

                                                // set  contact
                                                if (string.IsNullOrEmpty(suiteCRMTask.created_by) && commonPart.Owner != null)
                                                {
                                                    var emailAddress = suiteCRMEmailAddressUnitOfWork.GetByEmail(commonPart.Owner.Email);
                                                    if (emailAddress != null)
                                                    {
                                                        var contact = suiteCRMEmailAddressBeanUnitOfWork.GetBeanIdOfEmailAddress(Helper.ContactsModuleName, new[] { emailAddress.id }).FirstOrDefault();

                                                        if (contact != null)
                                                        {
                                                            suiteCRMTask.parent_id   = contact.id;
                                                            suiteCRMTask.parent_type = Helper.ContactsModuleName;
                                                        }
                                                    }
                                                }

                                                projectTasksRepository.Save();
                                            }

                                            suiteCRMTaskPart.ExternalId   = item.IsProjectTask ? suiteCRMProjectTask.id : suiteCRMTask.id;
                                            suiteCRMTaskPart.LastSyncTime = DateTime.UtcNow;
                                            suiteCRMTaskPart.TaskType     = item.IsProjectTask ? SuiteCRMTaskPart.SuiteCRMProjectTaskTypeValue : SuiteCRMTaskPart.SuiteCRMTaskTypeValue;
                                            this.services.ContentManager.Publish(ticket.ContentItem);

                                            SuiteCRMTaskDetailViewModel returnValueItem = new SuiteCRMTaskDetailViewModel();
                                            returnValueItem.OrchardCollaborationTicket = ticket.ContentItem;
                                            returnValueItem.IsSync         = true;
                                            returnValueItem.IsProjectTask  = item.IsProjectTask;
                                            returnValueItem.LastSyncTime   = suiteCRMTaskPart.LastSyncTime;
                                            returnValueItem.SuiteCRMTaskId = suiteCRMTaskPart.ExternalId;
                                            returnValue.Add(returnValueItem);
                                        }

                                        suiteCRMTransaction.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        suiteCRMTransaction.Rollback();
                                        throw ex;
                                    }
                                }

            return(returnValue);
        }
コード例 #26
0
 protected void LazyLoadHandlers(CommonPart part)
 {
     // add handlers that will load content for id's just-in-time
     part.OwnerField.Loader(() => _contentManager.Get <IUser>(part.Record.OwnerId));
     part.ContainerField.Loader(() => part.Record.Container == null ? null : _contentManager.Get(part.Record.Container.Id));
 }
コード例 #27
0
ファイル: CommonPartHandler.cs プロジェクト: wezmag/Coevery
 private void AssignUpdateDates(UpdateEditorContext context, CommonPart part) {
     var utcNow = _clock.UtcNow;
     part.ModifiedUtc = utcNow;
     part.VersionModifiedUtc = utcNow;
 }
コード例 #28
0
ファイル: CommonPartHandler.cs プロジェクト: wezmag/Coevery
        protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) {
            var utcNow = _clock.UtcNow;

             // assign the created date
            building.VersionCreatedUtc = utcNow;
            // assign modified date for the new version
            building.VersionModifiedUtc = utcNow;
            // publish date should be null until publish method called
            building.VersionPublishedUtc = null;

            // assign the created
            building.CreatedUtc = existing.CreatedUtc ?? _clock.UtcNow;
            // persist any published dates
            building.PublishedUtc = existing.PublishedUtc;
            // assign modified date for the new version
            building.ModifiedUtc = _clock.UtcNow;
        }
コード例 #29
0
ファイル: CommonPartHandler.cs プロジェクト: wezmag/Coevery
 protected void LazyLoadHandlers(CommonPart part) {
     // add handlers that will load content for id's just-in-time
     part.OwnerField.Loader(() => _contentManager.Get<IUser>(part.Record.OwnerId));
     part.ContainerField.Loader(() => part.Record.Container == null ? null : _contentManager.Get(part.Record.Container.Id));            
 }
コード例 #30
0
ファイル: CommonPartHandler.cs プロジェクト: wezmag/Coevery
        protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part) {
            // add handlers that will update records when part properties are set

            part.OwnerField.Setter(user => {
                                       part.Record.OwnerId = user == null
                                           ? 0
                                           : user.ContentItem.Id;
                                       return user;
                                   });

            // Force call to setter if we had already set a value
            if (part.OwnerField.Value != null)
                part.OwnerField.Value = part.OwnerField.Value;

            part.ContainerField.Setter(container => {
                                           part.Record.Container = container == null
                                               ? null
                                               : container.ContentItem.Record;
                                           return container;
                                       });

            // Force call to setter if we had already set a value
            if (part.ContainerField.Value != null)
                part.ContainerField.Value = part.ContainerField.Value;
        }
コード例 #31
0
ファイル: CommonPartHandler.cs プロジェクト: anycall/Orchard
        private void AssignRemovingDates(RemoveContentContext context, CommonPart part) {
            var utcNow = _clock.UtcNow;

            part.ModifiedUtc = utcNow;
            part.VersionModifiedUtc = utcNow;
        }
コード例 #32
0
        private void CopySuiteCRMTasksToOrchardTickets(TicketContext context, CopyOrchardProjectToSuiteViewModel.ProjectIdentifiers syncSettings)
        {
            if (syncSettings.OrchardCollaborationProjectId == null)
            {
                throw new ArgumentNullException("OrchardCollaborationProjectId must not be null");
            }

            if (string.IsNullOrEmpty(syncSettings.SuiteCRMId))
            {
                throw new ArgumentNullException("SuiteCRMId must not be null");
            }

            List <project_task> suiteCRMTasks = context.ProjectTaskUnitOfWork.GetProjectTasks(syncSettings.SuiteCRMId).ToList();
            var orchardTickets = this.searchTicketService.SearchByDatabase(
                new PagerParametersWithSortFields()
            {
                PageSize = 0
            },
                new PostedTicketSearchViewModel {
                ProjectId = syncSettings.OrchardCollaborationProjectId
            })
                                 .Select(c => c.As <SuiteCRMTaskPart>())
                                 .Where(c => c != null)
                                 .ToList();

            foreach (var suiteCRMTask in suiteCRMTasks)
            {
                var     orchardTicket  = orchardTickets.FirstOrDefault(c => c.ExternalId == suiteCRMTask.id);
                dynamic ticketSnapshot = null;

                ContentItem ticketContentItem = null;
                bool        isNew             = false;
                if (orchardTicket == null)
                {
                    isNew             = true;
                    ticketContentItem = this.services.ContentManager.Create("Ticket");
                }
                else
                {
                    ticketContentItem = orchardTicket.ContentItem;
                    ticketSnapshot    = this.streamService.TakeSnapshot(ticketContentItem);
                }

                TicketPart          ticketPart          = ticketContentItem.As <TicketPart>();
                SuiteCRMTaskPart    taskPart            = ticketContentItem.As <SuiteCRMTaskPart>();
                AttachToProjectPart attachToProjectPart = ticketContentItem.As <AttachToProjectPart>();

                // the values will be overridde in case user doesn't care about update time (item.DoNotOverrideNewerValues == false) or
                // the target modified date is less than source modified date
                DateTime?  lastSuiteCRMChangeDate = suiteCRMTask.date_modified ?? suiteCRMTask.date_entered;
                CommonPart commonPart             = ticketPart.As <CommonPart>();
                if (!syncSettings.DoNotOverrideNewerValues ||
                    isNew ||
                    (lastSuiteCRMChangeDate.HasValue && commonPart.ModifiedUtc <= lastSuiteCRMChangeDate.Value))
                {
                    if (attachToProjectPart != null)
                    {
                        attachToProjectPart.Record.Project = new ProjectPartRecord {
                            Id = syncSettings.OrchardCollaborationProjectId.Value
                        };
                    }

                    this.Copy(suiteCRMTask, ticketPart, context);
                    this.services.ContentManager.Publish(ticketContentItem);
                    this.streamService.WriteChangesToStreamActivity(ticketContentItem, ticketSnapshot, null);
                }

                taskPart.ExternalId   = suiteCRMTask.id;
                taskPart.LastSyncTime = DateTime.UtcNow;
                taskPart.TaskType     = SuiteCRMTaskPart.SuiteCRMProjectTaskTypeValue;
            }
        }
コード例 #33
0
ファイル: CommonPartHandler.cs プロジェクト: wezmag/Coevery
 protected void AssignCreatingOwner(InitializingContentContext context, CommonPart part) {
     // and use the current user as Owner
     if (part.Record.OwnerId == 0) {
         part.Owner = _authenticationService.GetAuthenticatedUser();
     }
 }
コード例 #34
0
        public bool CurrentUserCanEditContent(IContent item)
        {
            bool isCustomer = this.IsCurrentUserCustomer();
            bool isOperator = this.orchardServices.Authorizer.Authorize(Permissions.OperatorPermission);
            bool isAdmin    = this.orchardServices.Authorizer.Authorize(Permissions.AdvancedOperatorPermission);

            if (isAdmin)
            {
                return(true);
            }

            var contentPermissionPart = item.As <ContentItemPermissionPart>();

            if (this.orchardServices.WorkContext.CurrentUser == null)
            {
                return(false);
            }

            if (contentPermissionPart == null)
            {
                // if there is no ContentItemPermissionPart, then operator users can edit the item as well as
                // the creator of the item
                if (isOperator || isAdmin)
                {
                    return(true);
                }

                CommonPart commonPart = item.As <CommonPart>();
                if (commonPart.Owner != null && commonPart.Owner.Id == this.orchardServices.WorkContext.CurrentUser.Id)
                {
                    return(true);
                }

                return(false);
            }

            foreach (var extension in this.contentOwnershipServiceExtensions)
            {
                if (extension.CanApply(item, this))
                {
                    if (!extension.HasAccessTo(item, this))
                    {
                        return(false);
                    }
                }
            }

            bool isAssignee =
                contentPermissionPart.Record.Items != null &&
                contentPermissionPart.Record.Items.Count > 0 &&
                contentPermissionPart.Record.Items.Any(c => c.AccessType == ContentItemPermissionAccessTypes.Assignee);

            if (!isAssignee && CRMContentOwnershipService.ContentTypesThatOperatorsHasAcceesToUnAssigneds.Any(c => c == item.ContentItem.ContentType))
            {
                if (isOperator || isAdmin)
                {
                    return(true);
                }
            }

            int userId = this.orchardServices.WorkContext.CurrentUser.Id;
            var allCurrentUserPermissions = this.GetUserPermissionRecordsForItem(item, userId);

            if (allCurrentUserPermissions.Count(c => c.AccessType == ContentItemPermissionAccessTypes.Assignee ||
                                                c.AccessType == ContentItemPermissionAccessTypes.SharedForEdit) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #35
0
        public IEnumerable <SuiteCRMProjectDetailViewModel> CopyOrchardProjectsToSuite(CopyOrchardProjectToSuiteViewModel model)
        {
            List <SuiteCRMProjectDetailViewModel> returnValue = new List <SuiteCRMProjectDetailViewModel>();

            using (var connection = Helper.GetConnection(this.services, this.Logger))
                using (SuiteCRMProjectUnitOfWork projectRepository = new SuiteCRMProjectUnitOfWork(connection))
                    using (SuiteCRMProjectTaskUnitOfWork projectTasksRepository = new SuiteCRMProjectTaskUnitOfWork(projectRepository))
                        using (var suiteCRMTransaction = projectRepository.BeginTransaction())
                        {
                            try
                            {
                                var suiteProjects   = projectRepository.GetProjects(model.Projects.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)).Select(c => c.SuiteCRMId).ToArray());
                                var orchardProjects = this.services
                                                      .ContentManager
                                                      .GetMany <SuiteCRMProjectPart>(
                                    model.Projects.Where(c => c.OrchardCollaborationProjectId.HasValue).Select(c => c.OrchardCollaborationProjectId.Value),
                                    VersionOptions.Published,
                                    new QueryHints().ExpandParts <ProjectPart>());

                                foreach (var item in model.Projects.Where(c => c.OrchardCollaborationProjectId.HasValue))
                                {
                                    var suiteCRMProjectPart = orchardProjects.FirstOrDefault(c => c.Id == item.OrchardCollaborationProjectId.Value);

                                    if (suiteCRMProjectPart == null)
                                    {
                                        continue;
                                    }

                                    var orchardProject = suiteCRMProjectPart.As <ProjectPart>();

                                    project suiteCRMProject = null;
                                    if (!string.IsNullOrEmpty(item.SuiteCRMId))
                                    {
                                        suiteCRMProject = suiteProjects.FirstOrDefault(c => c.id == item.SuiteCRMId);

                                        if (suiteCRMProject == null)
                                        {
                                            suiteCRMProject = new project();
                                            projectRepository.Add(suiteCRMProject);
                                        }
                                    }
                                    else
                                    {
                                        suiteCRMProject = new project();
                                        projectRepository.Add(suiteCRMProject);
                                    }

                                    // the values will be overridde in case user doesn't care about update time (item.DoNotOverrideNewerValues == false) or
                                    // the target modified date is smaller than source modified date
                                    CommonPart commonPart = orchardProject.As <CommonPart>();
                                    DateTime?  lastOrchardTicketChangeDate = commonPart.ModifiedUtc ?? commonPart.CreatedUtc;
                                    if (!item.DoNotOverrideNewerValues ||
                                        suiteCRMProject.date_modified == null ||
                                        (lastOrchardTicketChangeDate.HasValue &&
                                         suiteCRMProject.date_modified.Value <= lastOrchardTicketChangeDate.Value))
                                    {
                                        this.Copy(orchardProject, suiteCRMProject);
                                        projectRepository.Save();
                                    }

                                    suiteCRMProjectPart.LastSyncTime = DateTime.UtcNow;
                                    suiteCRMProjectPart.ExternalId   = suiteCRMProject.id;
                                    item.SuiteCRMId = suiteCRMProject.id;

                                    if (item.SyncTasks)
                                    {
                                        TicketContext context = new TicketContext();
                                        context.ProjectTaskUnitOfWork = projectTasksRepository;
                                        context.Priorities            = this.priorityRepository.Table.ToList();
                                        context.StatusList            = this.statusRepository.Table.ToList();
                                        this.CopyOrchardTicketsToSuiteCRM(context, item);
                                    }

                                    this.services.ContentManager.Publish(suiteCRMProjectPart.ContentItem);

                                    SuiteCRMProjectDetailViewModel projectModel = new SuiteCRMProjectDetailViewModel();
                                    projectModel.OrchardCollaborationProject = suiteCRMProjectPart.ContentItem;
                                    projectModel.IsSync                    = true;
                                    projectModel.LastSyncTime              = suiteCRMProjectPart.LastSyncTime;
                                    projectModel.SuiteCRMProject           = this.Convert(suiteCRMProject);
                                    projectModel.OrchardCollaborationTitle = orchardProject.Record.Title;
                                    returnValue.Add(projectModel);
                                }

                                suiteCRMTransaction.Commit();
                            }
                            catch (Exception ex)
                            {
                                suiteCRMTransaction.Rollback();
                                throw ex;
                            }
                        }

            return(returnValue);
        }
コード例 #36
0
        public IEnumerable <SuiteCRMProjectDetailViewModel> CopySuiteCRMProjectsToOrchard(CopyOrchardProjectToSuiteViewModel model)
        {
            List <SuiteCRMProjectDetailViewModel> returnValue = new List <SuiteCRMProjectDetailViewModel>();

            using (var connection = Helper.GetConnection(this.services, this.Logger))
                using (SuiteCRMProjectUnitOfWork projectRepository = new SuiteCRMProjectUnitOfWork(connection))
                    using (SuiteCRMProjectTaskUnitOfWork projectTasksRepository = new SuiteCRMProjectTaskUnitOfWork(projectRepository))
                    {
                        var suiteProjects   = projectRepository.GetProjects(model.Projects.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)).Select(c => c.SuiteCRMId).ToArray());
                        var orchardProjects = this.services
                                              .ContentManager
                                              .GetMany <SuiteCRMProjectPart>(
                            model.Projects.Where(c => c.OrchardCollaborationProjectId.HasValue).Select(c => c.OrchardCollaborationProjectId.Value),
                            VersionOptions.Published,
                            new QueryHints().ExpandParts <ProjectPart>());

                        foreach (var item in model.Projects.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)))
                        {
                            var suiteCRMProject = suiteProjects.FirstOrDefault(c => c.id.ToLower() == item.SuiteCRMId.ToLower());

                            if (suiteCRMProject == null)
                            {
                                continue;
                            }

                            ContentItem orchardProject  = null;
                            dynamic     projectSnapshot = null;
                            bool        isNew           = false;
                            if (item.OrchardCollaborationProjectId.HasValue)
                            {
                                var part = orchardProjects.FirstOrDefault(c => c.Id == item.OrchardCollaborationProjectId.Value);
                                if (part != null)
                                {
                                    orchardProject  = part.ContentItem;
                                    projectSnapshot = this.streamService.TakeSnapshot(orchardProject);
                                }
                                else
                                {
                                    isNew          = true;
                                    orchardProject = this.services.ContentManager.New("ProjectItem");
                                }
                            }
                            else
                            {
                                isNew          = true;
                                orchardProject = this.services.ContentManager.New("ProjectItem");
                            }

                            if (isNew)
                            {
                                ProjectDashboardEditorPart editorPart = orchardProject.As <ProjectDashboardEditorPart>();
                                var portletTemplates = this.projectService.GetPortletsTemplates();
                                editorPart.PortletList = this.projectService.GetDefaultPortletIds(portletTemplates).ToArray();
                                this.services.ContentManager.Create(orchardProject);
                            }

                            // by building editor, we can be sure that the default values will be set
                            this.services.ContentManager.BuildEditor(orchardProject);

                            SuiteCRMProjectPart suiteCRMProjectPart = orchardProject.As <SuiteCRMProjectPart>();
                            ProjectPart         projectPart         = orchardProject.As <ProjectPart>();
                            suiteCRMProjectPart.ExternalId   = suiteCRMProject.id;
                            suiteCRMProjectPart.LastSyncTime = DateTime.UtcNow;

                            // the values will be overridde in case user doesn't care about update time (item.DoNotOverrideNewerValues == false) or
                            // the target modified date is less than source modified date
                            DateTime?  lastSuiteCRMChangeDate = suiteCRMProject.date_modified ?? suiteCRMProject.date_entered;
                            CommonPart commonPart             = orchardProject.As <CommonPart>();
                            if (!item.DoNotOverrideNewerValues ||
                                isNew ||
                                (lastSuiteCRMChangeDate.HasValue && commonPart.ModifiedUtc <= lastSuiteCRMChangeDate.Value))
                            {
                                this.Copy(suiteCRMProject, projectPart);
                                this.services.ContentManager.Publish(orchardProject);
                                item.OrchardCollaborationProjectId = orchardProject.Id;
                                this.streamService.WriteChangesToStreamActivity(orchardProject, projectSnapshot, null);
                            }

                            if (item.SyncTasks)
                            {
                                TicketContext context = new TicketContext();
                                context.ProjectTaskUnitOfWork = projectTasksRepository;
                                context.Priorities            = this.priorityRepository.Table.ToList();
                                context.StatusList            = this.statusRepository.Table.ToList();
                                this.CopySuiteCRMTasksToOrchardTickets(context, item);
                            }

                            SuiteCRMProjectDetailViewModel projectModel = new SuiteCRMProjectDetailViewModel();
                            projectModel.SuiteCRMProject             = this.Convert(suiteCRMProject);
                            projectModel.LastSyncTime                = suiteCRMProjectPart.LastSyncTime;
                            projectModel.OrchardCollaborationProject = orchardProject;
                            projectModel.OrchardCollaborationTitle   = projectPart.Title;

                            returnValue.Add(projectModel);
                        }
                    }

            return(returnValue);
        }
コード例 #37
0
ファイル: CommonPartHandler.cs プロジェクト: wezmag/Coevery
 protected void AssignPublishingDates(PublishContentContext context, CommonPart part) {
     var utcNow = _clock.UtcNow;
     part.PublishedUtc = utcNow;
     part.VersionPublishedUtc = utcNow;
 }
コード例 #38
0
        private void CopyOrchardTicketsToSuiteCRM(TicketContext context, CopyOrchardProjectToSuiteViewModel.ProjectIdentifiers syncSettings)
        {
            if (syncSettings.OrchardCollaborationProjectId == null)
            {
                throw new ArgumentNullException("OrchardCollaborationProjectId must not be null");
            }

            if (string.IsNullOrEmpty(syncSettings.SuiteCRMId))
            {
                throw new ArgumentNullException("SuiteCRMId must not be null");
            }

            var orchardTickets = this.searchTicketService.SearchByDatabase(new PagerParametersWithSortFields()
            {
                PageSize = 0
            }, new PostedTicketSearchViewModel {
                ProjectId = syncSettings.OrchardCollaborationProjectId
            });
            List <project_task> suiteCRMTasks = new List <project_task>();

            if (!string.IsNullOrEmpty(syncSettings.SuiteCRMId))
            {
                suiteCRMTasks.AddRange(context.ProjectTaskUnitOfWork.GetProjectTasks(syncSettings.SuiteCRMId));
            }

            foreach (var ticket in orchardTickets)
            {
                var suiteCRMTaskPart = ticket.As <SuiteCRMTaskPart>();

                if (suiteCRMTaskPart == null)
                {
                    continue;
                }

                TicketPart ticketPart = ticket.As <TicketPart>();
                ContentItemPermissionPart permissionPart = ticket.As <ContentItemPermissionPart>();

                if (ticketPart == null)
                {
                    continue;
                }

                if (!syncSettings.SyncSubTasks && ticketPart.Record.Parent != null)
                {
                    continue;
                }

                project_task suiteCRMProjectTask = null;

                if (!string.IsNullOrEmpty(suiteCRMTaskPart.ExternalId))
                {
                    suiteCRMProjectTask = suiteCRMTasks.FirstOrDefault(c => c.id == suiteCRMTaskPart.ExternalId);
                }

                if (suiteCRMProjectTask == null)
                {
                    suiteCRMProjectTask            = new project_task();
                    suiteCRMProjectTask.project_id = syncSettings.SuiteCRMId;
                    context.ProjectTaskUnitOfWork.Add(suiteCRMProjectTask);
                }

                CommonPart commonPart = ticketPart.As <CommonPart>();
                DateTime?  lastOrchardTicketChangeDate = commonPart.ModifiedUtc ?? commonPart.CreatedUtc;
                if (!syncSettings.DoNotOverrideNewerValues ||
                    suiteCRMProjectTask.date_modified == null ||
                    (lastOrchardTicketChangeDate.HasValue &&
                     suiteCRMProjectTask.date_modified.Value <= lastOrchardTicketChangeDate.Value))
                {
                    this.Copy(ticketPart, permissionPart, suiteCRMProjectTask, context);
                    context.ProjectTaskUnitOfWork.Save();
                }

                suiteCRMTaskPart.ExternalId   = suiteCRMProjectTask.id;
                suiteCRMTaskPart.LastSyncTime = DateTime.UtcNow;
                suiteCRMTaskPart.TaskType     = SuiteCRMTaskPart.SuiteCRMProjectTaskTypeValue;
                this.services.ContentManager.Publish(ticket.ContentItem);
            }
        }