protected override DriverResult Editor(TicketPart part, IUpdateModel updater, dynamic shapeHelper) { if (this.contentOwnershipService.CurrentUserCanEditContent(part.ContentItem)) { EditTicketViewModel model = new EditTicketViewModel(); updater.TryUpdateModel(model, Prefix, null, null); // Requesting User if (part.Record.RequestingUser == null) { int userId = this.orchardServices.WorkContext.CurrentUser.Id; part.Record.RequestingUser = new UserPartRecord { Id = userId }; } // Title part.Record.Title = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title.Trim(); // statusId part.Record.StatusRecord = model.StatusId.HasValue ? new StatusRecord { Id = model.StatusId.Value } : null; // Priority part.Record.PriorityRecord = model.PriorityId.HasValue ? new PriorityRecord { Id = model.PriorityId.Value } : null; // TicketType part.Record.TicketType = model.TypeId.HasValue ? new TicketTypeRecord { Id = model.TypeId.Value } : null; // Service part.Record.Service = model.ServiceId.HasValue ? new ServiceRecord { Id = model.ServiceId.Value } : null; // DueDate part.Record.DueDate = model.DueDate; // Description part.Description = model.Text; // RelatedContentItemId if (model.RelatedContentItemId.HasValue) { part.Record.RelatedContentItem = new ContentItemRecord { Id = model.RelatedContentItemId.Value }; } // Parent TicketId if (model.ParentTicketId.HasValue) { var parentTicket = this.orchardServices.ContentManager.Get(model.ParentTicketId.Value); if (parentTicket.ContentType == "Ticket" && this.contentOwnershipService.CurrentUserCanViewContent(parentTicket)) { part.Record.Parent = new TicketPartRecord { Id = model.ParentTicketId.Value }; } } if (part.Record.Identity == null) { TicketIdentityRecord identity = new TicketIdentityRecord(); this.ticketIdentityRecordRepository.Create(identity); part.Record.Identity = identity; } return(Editor(part, shapeHelper)); } else { throw new Security.OrchardSecurityException(T("You don't have permission to view the item")); } }
public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) { ContentItem contentItem = workflowContext.Content.ContentItem; var ticket = this.contentManager.New("Ticket"); this.contentManager.Create(ticket, VersionOptions.Draft); var ticketPart = ticket.As <TicketPart>(); var parentTicket = contentItem.As <TicketPart>(); if (parentTicket != null) { ticketPart.Record.Parent = parentTicket.Record; } // requesting user if (parentTicket != null) { ticketPart.Record.RequestingUser = parentTicket.Record.RequestingUser; } else if (contentItem != null) { var commonPart = contentItem.As <CommonPart>(); if (commonPart != null && commonPart.Record.OwnerId != default(int)) { ticketPart.Record.RequestingUser = new UserPartRecord { Id = commonPart.Record.OwnerId }; } } // service int?serviceId = GetValueFromActivityContext(activityContext, CreateTicketActivityForm.ServiceId); if (serviceId.HasValue) { ticketPart.Record.Service = new ServiceRecord { Id = serviceId.Value }; } // status int?statusId = GetValueFromActivityContext(activityContext, CreateTicketActivityForm.StatusId); if (statusId.HasValue) { ticketPart.Record.StatusRecord = new StatusRecord { Id = statusId.Value }; } // Project AttachToProjectPart attachToProjectPart = ticket.As <AttachToProjectPart>(); if (attachToProjectPart != null) { int?projectId = GetValueFromActivityContext(activityContext, CreateTicketActivityForm.ProjectId); if (projectId.HasValue) { attachToProjectPart.Record.Project = new ProjectPartRecord { Id = projectId.Value }; } } // priority int?priorityId = GetValueFromActivityContext(activityContext, CreateTicketActivityForm.PriorityId); if (priorityId.HasValue) { ticketPart.Record.PriorityRecord = new PriorityRecord { Id = priorityId.Value }; } // Due date int?dueDateDays = GetValueFromActivityContext(activityContext, CreateTicketActivityForm.DueDateId); if (dueDateDays.HasValue) { ticketPart.Record.DueDate = DateTime.UtcNow.AddDays(dueDateDays.Value); } // Title string title = activityContext.GetState <string>(CreateTicketActivityForm.TicketTitle); if (!string.IsNullOrEmpty(title)) { title = title.Length > 100 ? title.Substring(0, 100) : title; } ticketPart.Record.Title = title; // Description string description = activityContext.GetState <string>(CreateTicketActivityForm.TicketDescription); if (!string.IsNullOrEmpty(description)) { description = description.Length > 3000 ? description.Substring(0, 3000) : description; } ticketPart.Record.Description = description; // Received email is not a RelatedContentItem if (contentItem.ContentType != IMAPEmailPart.ContentItemTypeName) { ticketPart.Record.RelatedContentItem = workflowContext.Content.ContentItem.Record; } // Identity var identityRecord = new TicketIdentityRecord(); this.ticketIdentityRecordRepository.Create(identityRecord); ticketPart.Record.Identity = identityRecord; // Permission this.SetPermissions(workflowContext, activityContext, ticket, ticketPart); this.AddEmailAttachmentAndRequestingUser(workflowContext, activityContext, ticket); this.contentManager.Publish(ticket); this.activityStreamService.WriteChangesToStreamActivity(ticket, null, true, StreamWriters.TicketStreamWriter); return(new[] { T("Done") }); }