Exemplo n.º 1
0
        public ActionResult RenderPatronDataView(int nodeId)
        {
            // Get a new OrderItem populated with values for this node
            var orderItem = _orderItemManager.GetOrderItem(nodeId);

            return(PartialView("Chalmers.ILL.Action.PatronData", orderItem));
        }
Exemplo n.º 2
0
        public ActionResult RenderReferenceAction(int nodeId)
        {
            // Get a new OrderItem populated with values for this node
            var orderItem = _orderItemManager.GetOrderItem(nodeId);

            // The return format depends on the client's Accept-header
            return(PartialView("Chalmers.ILL.Action.Reference", orderItem));
        }
Exemplo n.º 3
0
        public ActionResult RenderLogEntryAction(int nodeId)
        {
            var pageModel = new ChalmersILLActionLogEntryModel(_orderItemManager.GetOrderItem(nodeId));

            _dataTypes.PopulateModelWithAvailableValues(pageModel);

            // The return format depends on the client's Accept-header
            return(PartialView("Chalmers.ILL.Action.LogEntry", pageModel));
        }
        public ActionResult RenderMailAction(int nodeId)
        {
            var model = new ChalmersILLActionMailModel(_orderItemManager.GetOrderItem(nodeId));

            _dataTypes.PopulateModelWithAvailableValues(model);
            model.SignatureTemplate = _templateService.GetTemplateData("SignatureTemplate", model.OrderItem);
            model.Templates         = _templateService.GetManualTemplates();

            // The return format depends on the client's Accept-header
            return(PartialView("Chalmers.ILL.Action.Mail", model));
        }
Exemplo n.º 5
0
        /*
         * This notifier is a simple helper, to send notifications to a SignalR hub
         * It takes a document as a parameter and then passes that data on to signalR
         * Which then sends it to all connected browsers.
         * Finally, in the browser, a javascript method is executed based on the data from the server
         */
        public void ReportNewOrderItemUpdate(IContent d)
        {
            // get the NotificationHub
            var context = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();

            // Parse out the integer of status and type
            int      OrderStatusId = 0;
            int      OrderTypeId   = 0;
            DateTime followUpDate  = DateTime.MaxValue;

            if (d.GetValue("status") != null)
            {
                Int32.TryParse(d.GetValue("status").ToString(), out OrderStatusId);
            }

            if (d.GetValue("type") != null)
            {
                Int32.TryParse(d.GetValue("type").ToString(), out OrderTypeId);
            }

            if (d.GetValue("followUpDate") != null)
            {
                followUpDate = Convert.ToDateTime(d.GetValue("followUpDate").ToString());
            }

            // Extract the real chillin order status id from the umbraco id.
            int      chillinOrderStatusId = 0;
            var      ds = new Umbraco.Core.Services.DataTypeService();
            PreValue iter;

            foreach (DictionaryEntry pv in _umbraco.GetPreValues(ConfigurationManager.AppSettings["umbracoOrderStatusDataTypeDefinitionName"]))
            {
                iter = ((PreValue)pv.Value);
                if (iter.Id == OrderStatusId)
                {
                    chillinOrderStatusId = Convert.ToInt32(iter.Value.Split(':').First());
                    break;
                }
            }

            // create a notication object to send to the clients
            var n = new OrderItemNotification
            {
                NodeId             = d.Id,
                EditedBy           = _orderItemManager.GetOrderItem(d.Id).EditedBy,
                EditedByMemberName = _orderItemManager.GetOrderItem(d.Id).EditedByMemberName,
                SignificantUpdate  = true,
                IsPending          = chillinOrderStatusId == 1 || chillinOrderStatusId == 2 || chillinOrderStatusId == 9 || (chillinOrderStatusId > 2 && chillinOrderStatusId <5 && DateTime.Now> followUpDate),
                UpdateFromMail     = false
            };

            // this calls the javascript method updateStream(message) in all connected browsers
            context.Clients.All.updateStream(n);
        }
Exemplo n.º 6
0
        public ActionResult ImportFromUrl(int orderItemNodeId, string url)
        {
            // Json response
            var json = new ResultResponse();

            Stream stream = null;

            try
            {
                HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(url);
                fileReq.CookieContainer   = new CookieContainer();
                fileReq.AllowAutoRedirect = true;
                HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
                stream = fileResp.GetResponseStream();

                var    orderItem         = _orderItemManager.GetOrderItem(orderItemNodeId);
                var    cdPattern         = new Regex("filename=\"?(.*)\"?(?:;|$)");
                var    fileEndingPattern = new Regex("(?i)\\.(?:pdf|txt|tif|tiff)$");
                string name = "";
                if (fileEndingPattern.IsMatch(url))
                {
                    name = fileResp.ResponseUri.AbsoluteUri.Substring(fileResp.ResponseUri.AbsoluteUri.LastIndexOf("/") + 1);
                }
                else
                {
                    name = cdPattern.Match(fileResp.Headers["Content-Disposition"]).Groups[1].Value;
                }

                if (String.IsNullOrEmpty(name))
                {
                    throw new Exception("Not a valid document.");
                }
                else
                {
                    var savedMediaItem = _mediaItemManager.CreateMediaItem(name, orderItem.NodeId, orderItem.OrderId, stream, fileResp.ContentType);

                    var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE);
                    _orderItemManager.AddExistingMediaItemAsAnAttachment(orderItem.NodeId, savedMediaItem.Id, name, savedMediaItem.Url, eventId);

                    json.Success = true;
                    json.Message = "Document imported successfully.";
                }
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Failed to import document: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RenderDeliveryAction(int nodeId)
        {
            var pageModel = new ChalmersILLActionDeliveryModel(_orderItemManager.GetOrderItem(nodeId));

            _umbraco.PopulateModelWithAvailableValues(pageModel);
            return(PartialView("Chalmers.ILL.Action.Delivery", pageModel));
        }
        public ActionResult ReindexOrderItem(string orderId)
        {
            var json = new ResultResponse();

            try
            {
                var orderItem = _orderItemManager.GetOrderItem(orderId);

                if (orderItem != null)
                {
                    _orderItemSearcher.Modified(orderItem);

                    json.Success = true;
                    json.Message = "Indexerade order item '" + orderId + "' i sökindexet.";
                }
                else
                {
                    json.Success = false;
                    json.Message = "Kunde inte hitta någon order item med '" + orderId + "' som orderId och ingen indexering har därför genomförts.";
                }
            }
            catch (Exception e)
            {
                LogHelper.Error <OrderItemSearchSurfaceController>("Failed to reindex order item.", e);
                json.Success = false;
                json.Message = "Error: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        public ActionResult RenderOrderItem(int nodeId)
        {
            // Get current member.
            int memberId = _memberInfoManager.GetCurrentMemberId(Request, Response);

            // Get a new OrderItem populated with values for this node
            var pageModel = new ChalmersILLOrderItemModel(_orderItemManager.GetOrderItem(nodeId));

            // Check if the current user has the lock for the item.
            pageModel.OrderItem.EditedByCurrentMember = pageModel.OrderItem.EditedBy != "" && pageModel.OrderItem.EditedBy == memberId.ToString();

            _umbraco.PopulateModelWithAvailableValues(pageModel);

            // Return Partial View to the client
            return(PartialView("Chalmers.ILL.OrderItem", pageModel));
        }
Exemplo n.º 10
0
 private void FixLegacyNodeIds(MailQueueModel mailModel)
 {
     if (mailModel.OrderItemNodeId < 100000)
     {
         var order = _orderItemManager.GetOrderItem(mailModel.OrderId);
         mailModel.OrderItemNodeId = order.NodeId;
     }
 }
Exemplo n.º 11
0
        public ActionResult RenderProviderAction(int nodeId)
        {
            // Get a new OrderItem populated with values for this node
            var pageModel = new ChalmersILLActionProviderModel(_orderItemManager.GetOrderItem(nodeId));

            pageModel.Providers = _providerService.FetchAndCreateListOfUsedProviders().ToList();
            var deliveryTimeInHours = _providerService.GetSuggestedDeliveryTimeInHoursForProvider(pageModel.OrderItem.ProviderName);

            pageModel.EstimatedDeliveryCurrentProvider = DateTime.Now.AddHours(deliveryTimeInHours);

            // The return format depends on the client's Accept-header
            return(PartialView("Chalmers.ILL.Action.Provider", pageModel));
        }
        public ActionResult GetPopulatedTemplateData(int templateId, int orderItemNodeId)
        {
            var json = new ResultResponseWithStringData();

            try
            {
                var orderItem = _orderItemManager.GetOrderItem(orderItemNodeId);
                json.Success = true;
                json.Message = "Populerade malldata.";
                json.Data    = _templateService.GetTemplateData(templateId, orderItem);
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Misslyckades med att populera malldata: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public ActionResult MigrateOrderItem(int nodeId)
        {
            var json = new ResultResponse();

            try
            {
                var orderItemToBeMoved = _legacyOrderItemManager.GetOrderItem(nodeId);

                // There is an item to move.
                if (orderItemToBeMoved != null)
                {
                    var existingOrderItem = _orderItemManager.GetOrderItem(orderItemToBeMoved.OrderId);

                    // There is no item with the same order id already in the store.
                    if (existingOrderItem == null)
                    {
                        // Copy and clear attachments and create the order item without attachments in the storage.
                        var attachmentsToCopy = new List <OrderAttachment>();
                        foreach (var attachmentToBeMoved in orderItemToBeMoved.AttachmentList)
                        {
                            attachmentsToCopy.Add(attachmentToBeMoved);
                        }
                        orderItemToBeMoved.AttachmentList.Clear();
                        orderItemToBeMoved.Attachments = JsonConvert.SerializeObject(orderItemToBeMoved.AttachmentList);

                        var newOrderItemNodeId = _orderItemManager.CreateOrderItemInDbFromOrderItemModel(orderItemToBeMoved);
                        var newOrderItem       = _orderItemManager.GetOrderItem(newOrderItemNodeId);

                        if (newOrderItem != null)
                        {
                            // Create all the connected media items in the media storage.
                            var    newMediaItems = new List <MediaItemModel>();
                            bool   successfullyAddedAllMediaItems = true;
                            string failedMediaItemId   = "";
                            string failedMediaItemName = "";
                            foreach (var attachmentToCopy in attachmentsToCopy)
                            {
                                var mediaItemToBeMoved = _legacyMediaItemManager.GetOne(attachmentToCopy.MediaItemNodeId);

                                // Calculate the content type.
                                string contentType = "";
                                if (attachmentToCopy.Title.EndsWith(".pdf"))
                                {
                                    contentType = "application/pdf";
                                }
                                else if (attachmentToCopy.Title.EndsWith(".txt"))
                                {
                                    contentType = "text/plain";
                                }
                                else if (attachmentToCopy.Title.EndsWith(".tif"))
                                {
                                    contentType = "image/tiff";
                                }
                                else if (attachmentToCopy.Title.EndsWith(".tiff"))
                                {
                                    contentType = "image/tiff";
                                }

                                if (!String.IsNullOrEmpty(contentType))
                                {
                                    var newMediaItem = _mediaItemManager.CreateMediaItem(attachmentToCopy.Title, newOrderItem.NodeId, newOrderItem.OrderId, mediaItemToBeMoved.Data, contentType);
                                    newMediaItems.Add(newMediaItem);
                                }
                                else
                                {
                                    successfullyAddedAllMediaItems = false;
                                    failedMediaItemId   = mediaItemToBeMoved.Id;
                                    failedMediaItemName = mediaItemToBeMoved.Name;
                                    break;
                                }
                            }

                            // Connect all the newly created media items.
                            if (successfullyAddedAllMediaItems)
                            {
                                foreach (var newMediaItem in newMediaItems)
                                {
                                    _orderItemManager.AddExistingMediaItemAsAnAttachmentWithoutLogging(newOrderItemNodeId, newMediaItem.Id, newMediaItem.Name, newMediaItem.Url, true, false);
                                }
                            }
                            else
                            {
                                throw new Exception("Failed to create media items connected to order item with ID = " + orderItemToBeMoved.NodeId +
                                                    ". The troublesome media item has ID = " + failedMediaItemId + " and name '" + failedMediaItemName + "'.");
                            }
                        }
                        else
                        {
                            throw new Exception("Failed to read back order item with ID = " + newOrderItem.NodeId + " after creating it in the current storage.");
                        }
                    }
                    else
                    {
                        throw new Exception("There is already an order item with order ID = " + orderItemToBeMoved.OrderId + " in the current storage. Skipping move.");
                    }
                }
                else
                {
                    throw new Exception("There was no order item with node ID = " + nodeId + ". Nothing to move.");
                }

                json.Success = true;
                json.Message = "Successfully moved order with node ID = " + nodeId + ".";
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Something went horribly wrong: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
 public OrderItemDto GetItem(string id)
 {
     return(orderItemManager.GetOrderItem(Convert.ToInt32(id)));
 }
        public IEnumerable <MailOperationResult> SendOutMailsThatAreDue()
        {
            var res = new List <MailOperationResult>();

            // Grab the date and use it for all e-mails during this run.
            var now = DateTime.Now;

            var orderItems = GetOrderItemsThatAreRelevantForAutomaticMailSending();

            var delayedMailOperations = new List <DelayedMailOperation>();

            foreach (var orderItem in orderItems)
            {
                var dueDate      = orderItem.DueDate;
                var deliveryDate = orderItem.DeliveryDate;
                var status       = orderItem.Status;

                var delayedMailOperation = new DelayedMailOperation(
                    orderItem.NodeId,
                    orderItem.OrderId,
                    orderItem.PatronName,
                    orderItem.PatronEmail);

                if (status.Contains("Utlånad") || status.Contains("Krävd"))
                {
                    if (status.Contains("Utlånad") && now.Date == dueDate.AddDays(-5).Date)
                    {
                        delayedMailOperation.Mail.message = _templateService.GetTemplateData("CourtesyNoticeMailTemplate", _orderItemManager.GetOrderItem(orderItem.NodeId));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL_NOTE", "Skickat automatiskt \"courtesy notice\" till " + delayedMailOperation.Mail.recipientEmail));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL", delayedMailOperation.Mail.message));
                        delayedMailOperation.ShouldBeProcessed = true;
                    }
                    else if (status.Contains("Utlånad") && now.Date == dueDate.AddDays(1).Date)
                    {
                        delayedMailOperation.Mail.message = _templateService.GetTemplateData("LoanPeriodOverMailTemplate", _orderItemManager.GetOrderItem(orderItem.NodeId));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL_NOTE", "Skickat automatiskt påminnelsemail nummer ett till " + delayedMailOperation.Mail.recipientEmail));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL", delayedMailOperation.Mail.message));
                        delayedMailOperation.ShouldBeProcessed = true;
                    }
                    else if (now.Date == dueDate.AddDays(5).Date)
                    {
                        delayedMailOperation.Mail.message = _templateService.GetTemplateData("LoanPeriodReallyOverMailTemplate", _orderItemManager.GetOrderItem(orderItem.NodeId));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL_NOTE", "Skickat automatiskt påminnelsemail nummer två till " + delayedMailOperation.Mail.recipientEmail));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL", delayedMailOperation.Mail.message));
                        delayedMailOperation.ShouldBeProcessed = true;
                    }
                    else if (now.Date == dueDate.AddDays(10).Date)
                    {
                        delayedMailOperation.Mail.message = _templateService.GetTemplateData("LoanPeriodReallyReallyOverMailTemplate", _orderItemManager.GetOrderItem(orderItem.NodeId));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL_NOTE", "Skickat automatiskt påminnelsemail nummer tre till " + delayedMailOperation.Mail.recipientEmail));
                        delayedMailOperation.LogMessages.Add(new LogMessage("MAIL", delayedMailOperation.Mail.message));
                        delayedMailOperation.ShouldBeProcessed = true;
                    }
                    else if (now.Date >= dueDate.AddDays(17).Date)
                    {
                        delayedMailOperation.LogMessages.Add(new LogMessage("LOG", "Bok mycket försenad."));
                        delayedMailOperation.Mail              = null;
                        delayedMailOperation.NewStatus         = "02:Åtgärda";
                        delayedMailOperation.ShouldBeProcessed = true;
                    }
                }

                if (delayedMailOperation.ShouldBeProcessed)
                {
                    delayedMailOperations.Add(delayedMailOperation);
                }
            }

            // Send out all the delayed mails now, so that the IndexReader is not used and gets broken.
            foreach (var delayedMailOperation in delayedMailOperations)
            {
                var mailOperationResult = new MailOperationResult()
                {
                    Success       = true,
                    Message       = "Mail operation successfull.",
                    MailOperation = delayedMailOperation
                };
                try
                {
                    var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE);

                    if (delayedMailOperation.Mail != null)
                    {
                        _mailService.SendMail(delayedMailOperation.Mail);
                    }

                    for (int i = 0; i < delayedMailOperation.LogMessages.Count; i++)
                    {
                        var logMsg = delayedMailOperation.LogMessages[i];
                        var shouldReindexAndSignal = String.IsNullOrWhiteSpace(delayedMailOperation.NewStatus) && i == delayedMailOperation.LogMessages.Count - 1;
                        _orderItemManager.AddLogItem(delayedMailOperation.InternalOrderId, logMsg.type, logMsg.message, eventId, shouldReindexAndSignal, shouldReindexAndSignal);
                    }

                    if (!String.IsNullOrWhiteSpace(delayedMailOperation.NewStatus))
                    {
                        _orderItemManager.SetStatus(delayedMailOperation.InternalOrderId, delayedMailOperation.NewStatus, eventId, true, true);
                    }
                }
                catch (Exception e)
                {
                    mailOperationResult.Success = false;
                    mailOperationResult.Message = "Delayed mail operation failed: " + e.Message;
                }
                res.Add(mailOperationResult);
            }

            return(res);
        }