Exemplo n.º 1
0
        public ActionResult Edit(TicketEditModel model)
        {
            var contactId = this.GetContactId();

            using (var dc = new IORunEntities())
            {
                var contact = dc.Contacts.Single(c => c.Contact_GUID == contactId);
                var task = dc.Tasks.Single(t => t.Task_GUID == model.TaskId);

                if (task.Task_CompanyGUID != contact.Contact_CompanyGUID)
                    throw new SecurityException("Unauthorized");

                var newTaskLog = TaskRepository.CreateTaskLog(task.Task_GUID, dc, null, contactId);
                newTaskLog.TaskLog_WebVisible = 1;
                newTaskLog.TaskLog_InternalText = model.NewMessage;
                newTaskLog.TaskLog_ExternalText = model.NewMessage;

                dc.TaskLogs.Add(newTaskLog);

                task.Task_UpdatedByContactGUID = contactId;
                task.Task_UpdatedByContactDate = DateTime.Now;

                dc.SaveChanges();

                var newModel = BuildEditModel(task.Task_IssueIdentifier);

                return View(newModel);
            }
        }
Exemplo n.º 2
0
        private TicketEditModel BuildEditModel(int id)
        {
            var contactId = this.GetContactId();

            using (var dc = new IORunEntities())
            {
                var contact = dc.Contacts.Single(c => c.Contact_GUID == contactId);
                var task = dc.Tasks.Single(t => t.Task_IssueIdentifier == id);

                if (task.Task_CompanyGUID != contact.Contact_CompanyGUID)
                    throw new SecurityException("Unauthorized");

                var model = new TicketEditModel();
                model.TicketGuid = task.Task_GUID;
                model.Overskrift = task.Task_Caption;
                model.Beskrivelse = task.Task_Description;
                model.TicketNumber = task.Task_IssueIdentifier;

                model.Messages = task.TaskLogs.Where(tl =>
                    tl.IsThrash == 0).
                    ToList().
                    OrderByDescending(tl => tl.TaskLog_CreatedDate).
                    Select(tl => new TaskEditItemModel(tl, dc)).
                    ToList();

                model.TaskId = task.Task_GUID;
                model.IsClosed = task.Task_IsClosed == 1;
                model.Status = task.Task_IsClosed == 1 ? $"Lukket" :
                task.Task_StatusText;
                model.AsignedTo = task.Task_ToUserGUID.HasValue
                    ? dc.Brugers.Single(b => b.Bruger_GUID == task.Task_ToUserGUID.Value).Bruger_Navn
                    : "Ingen";

                return model;
            }
        }