public RegistrationQuickTaskModel(IORunEntities dc, Task task)
 {
     Id = task.Task_GUID;
     Caption = task.Task_Caption;
     Company = task.Task_CompanyGUID != null ? dc.Kunders.Single(c => c.Kunde_GUID == task.Task_CompanyGUID).Kunde_Navn_1 : string.Empty;
     IsToday = task.Task_StartDate.HasValue ? task.Task_StartDate.Value.Date == DateTime.Today.Date : false;
 }
        public static Task CreateTask(Guid companyId, Guid? contactId, string caption,string description, IORunEntities dc, Guid? invoiceType, TaskType systemArbejdeTaskLog, Guid? contextBrugerGuid, Guid? contextContactId)
        {
            var now = DateTime.Now;

            var newTask = new Task
            {
                Task_GUID = Guid.NewGuid(),
                Task_CompanyGUID = companyId,
                Task_ContactGUID = contactId,
                Task_Caption = caption.Truncate(100),
                Task_Description =  description.Truncate(512),
                Task_Notes = description,
                Task_StartDate = DateTime.Today,
                Task_EndDate = DateTime.Today,
                Task_CreatedDate = now,
                Task_CreatedByUserGUID = contextBrugerGuid,
                Task_InvoiceTypeGUID = invoiceType,
                Task_Status = (int)TaskStatus.NotStartet,
                Task_FromUserGUID = contextBrugerGuid,
                Task_ToUserGUID = contextBrugerGuid,
                Task_TaskTypeGUID = systemArbejdeTaskLog.TT_GUID,
                Task_StatusText = TaskStatus.NotStartet.ToString(),
                Task_UpdatedByUserDate = contextBrugerGuid.HasValue ? now : new Nullable<DateTime>(),
                Task_UpdatedByUserGUID = contextBrugerGuid,
                Task_CreatedByContactGUID = contextContactId,
                Task_UpdatedByContactDate = contextContactId.HasValue ? now : new Nullable<DateTime>()
            };

            return newTask;
        }
        public static EmailQueue CreateTicketOpdateretMail(Contact contact, string subject, int ticketNumber, string siteUrl, Bruger tekniker,  Task task)
        {
            var ticketUrl = $"{siteUrl.TrimEnd('/')}/ticket/edit/{ticketNumber}";

            var technician = tekniker != null ? tekniker.Bruger_Initialer : "(Ingen)";
            var taskStatus = (TaskStatus)(task.Task_Status ?? 0);

            string taskStatusText;
            switch (taskStatus)
            {
                case TaskStatus.NotStartet:
                    taskStatusText = "Endnu ikke påbegyndt";
                    break;
                case TaskStatus.WaitingFor:
                    taskStatusText = "Venter";
                    break;
                case TaskStatus.InProgress:
                    taskStatusText = "Under behandling";
                    break;
                case TaskStatus.Complete:
                    taskStatusText = "Afsluttet";
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            var newMail = new EmailQueue()
            {
                Created = DateTime.Now, FromEmailAddress = "*****@*****.**", FromName = "IT Forum A/S - Support", ToEmailAddress = contact.Contact_Work_EMail, ToName = contact.Contact_Name, Subject = $"[#{ticketNumber}] Opdateret '{subject}'", BodyText = $"Din sag er blevet opdateret\r\n\r\nAnsvarlig tekniker: {technician}\r\nStatus på sag: {taskStatusText}\r\n\r\nDu kan navigere til supportsiden for at se flere detaljer om den nye status\r\n\r\nLink: {ticketUrl}\r\n\r\n Med venlig hilsen\r\nIT Forum Support"
            };

            return newMail;
        }
        public TicketIndexItemModel(IORunEntities dc, Task ta)
        {
            Id = ta.Task_GUID;
            IssueId = ta.Task_IssueIdentifier;
            Caption = ta.Task_Caption;
            CreatedDate = ta.Task_CreatedDate.ToString("g");
            CreatedByUserName = ta.Task_CreatedByUserGUID.HasValue
                ? dc.Brugers.Single(b => b.Bruger_GUID == ta.Task_CreatedByUserGUID).Bruger_Initialer
                : "";
            CreatedByContactName = ta.Task_CreatedByContactGUID.HasValue
                ? dc.Contacts.Single(b => b.Contact_GUID == ta.Task_CreatedByContactGUID).Contact_Name
                : "";
            UpdatedByUserName = ta.Task_UpdatedByUserGUID.HasValue
                ? dc.Brugers.Single(b => b.Bruger_GUID == ta.Task_UpdatedByUserGUID).Bruger_Initialer
                : "";
            UpdatedByContactName = ta.Task_UpdatedByContactGUID.HasValue
                ? dc.Contacts.Single(b => b.Contact_GUID == ta.Task_UpdatedByContactGUID).Contact_Name
                : "";

            if ((ta.Task_UpdatedByUserDate.HasValue &&
                    ta.Task_UpdatedByContactDate.HasValue &&
                    ta.Task_UpdatedByUserDate > ta.Task_UpdatedByContactDate) ||
                (ta.Task_UpdatedByUserDate.HasValue))
            {
                UpdatedDate = ta.Task_UpdatedByUserDate?.ToString("g");
                UpdatedBy = UpdatedByUserName;
            }
            else
            {
                UpdatedDate = ta.Task_UpdatedByContactDate?.ToString("g");
                UpdatedBy = UpdatedByContactName;
            }

            if (ta.Task_CreatedByContactGUID.HasValue)
            {
                CreatedBy = CreatedByContactName;
            }
            else
            {
                CreatedBy = CreatedByUserName;
            }

            NyesteTekst = ta.TaskLogs.Any()
                ? ta.TaskLogs.OrderByDescending(tl => tl.TaskLog_CreatedDate).First().TaskLog_ExternalText : string.Empty;

            Status = ta.Task_IsClosed == 1 ? "Lukket" :
                ta.Task_StatusText;
        }
        public TaskSelectionModel(IORunEntities dc, Task k)
        {
            // Har oplevet at finde opgaver der peger på kontakt der ikke findes :(
            var contact = k.Task_ContactGUID.HasValue ? dc.Contacts.SingleOrDefault(tt => tt.Contact_GUID == k.Task_ContactGUID.Value) : null;

            // Har oplevet at finde opgaver der peger på task type der ikke findes :(
            var taskType = k.Task_TaskTypeGUID.HasValue
                ? dc.TaskTypes.SingleOrDefault(tt =>
                    tt.TT_GUID == k.Task_TaskTypeGUID.Value) : null;

            Id = k.Task_GUID;
            Name = k.Task_Caption;
            TaskType = taskType != null ? taskType.TT_Name : string.Empty;
            ContactName = contact != null ? contact.Contact_Name : string.Empty;
            ContactId = contact != null ? contact.Contact_GUID.ToString() : null;
            IsClosed = k.Task_IsClosed == 1;
        }
        private TaskLog LogSupport(IORunEntities dc, Task task, Contact contact, EmailMessage exchangeMail, int ticketNumber)
        {
            var logText = $"{exchangeMail.Subject}:\n\n{exchangeMail.Body.Text}";

            var newTaskLog = TaskRepository.CreateTaskLog(task.Task_GUID, dc, null, contact.Contact_GUID);
            newTaskLog.TaskLog_WebVisible = 1;
            newTaskLog.TaskLog_InternalText = logText.AsEol();
            newTaskLog.TaskLog_ExternalText = logText.AsEol();

            dc.TaskLogs.Add(newTaskLog);

            task.Task_UpdatedByContactGUID = contact.Contact_GUID;
            task.Task_UpdatedByContactDate = DateTime.Now;

            log.Info($"Logget support {logText} på ticket {ticketNumber}");

            return newTaskLog;
        }
示例#7
0
 public TaskModel(IORunEntities dc, Task task)
 {
     Id = task.Task_GUID;
     IsClosed = task.Task_IsClosed == 1;
     Caption = task.Task_Caption;
 }
        private static void CheckTask(Task checkTask, IORunEntities dc)
        {
            var taskCompany = checkTask.Task_CompanyGUID.HasValue
                ? dc.Kunders.SingleOrDefault(k => k.Kunde_GUID == checkTask.Task_CompanyGUID.Value)
                : null;

            if (taskCompany != null && taskCompany.IsSupportSiteEnabled == true)
            {
                // Find tasklogs der endnu ikke er rapporteret som ændring på task
                var unreportedTasklogs =
                    checkTask.TaskLogs.Where(tl =>
                        checkTask.TasklogChangeReporteds.Any(r =>
                            r.TasklogId == tl.TaskLog_GUID) == false);

                // Hvis der er en eller flere nye tasklogs
                if (unreportedTasklogs.Any())
                {
                    // Find kontakt personer der er involveret i denne task
                    var contactsDerSkalNotificeres =
                        checkTask.TaskLogs.Where(tl =>
                            tl.IsThrash == 0 &&
                            tl.TaskLog_CreatedByContactGUID.HasValue)
                            .Select(tl => tl.TaskLog_CreatedByContactGUID.Value)
                            .Union(
                                checkTask.TaskLogs.Where(tl =>
                                    tl.IsThrash == 0 &&
                                    tl.TaskLog_UpdatedByContactDate.HasValue)
                                    .Select(tl => tl.TaskLog_UpdatedByContactGUID.Value)
                            ).Distinct();

                    // Notificer involverede kontakt personer
                    foreach (var thisNotifcerContactId in contactsDerSkalNotificeres)
                    {
                        var contact = dc.Contacts.Single(c => c.Contact_GUID == thisNotifcerContactId);

                        var technician = checkTask.Task_ToUserGUID.HasValue
                            ? dc.Brugers.Single(b => b.Bruger_GUID == checkTask.Task_ToUserGUID.Value)
                            : null;

                        var email = MailRepository.CreateTicketOpdateretMail(
                            contact,
                            checkTask.Task_Caption,
                            checkTask.Task_IssueIdentifier,
                            Properties.Settings.Default.SiteRootUrl,
                            technician,
                            checkTask);

                        dc.EmailQueues.Add(email);

                        log.Info($"Oprettede notifikation email til {email.ToEmailAddress}");
                    }

                    // Registrer at vi har rapporteret om disse tasklogs
                    foreach (var unreportedTasklog in unreportedTasklogs)
                    {
                        var tasklogReported = new TasklogChangeReported()
                        {
                            NewestChange = DateTime.Now,
                            TasklogId = unreportedTasklog.TaskLog_GUID
                        };

                        checkTask.TasklogChangeReporteds.Add(tasklogReported);
                    }
                } // Any unreported tasklogs?
            } // Task company != null && company.supportenabled
        }