Esempio n. 1
0
        public ActionResult SetOrderItemStatus(int orderNodeId, int statusId, int cancellationReasonId = -1, int purchasedMaterialId = -1)
        {
            var json = new ResultResponse();

            try
            {
                var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE);

                if (cancellationReasonId != -1)
                {
                    _orderItemManager.SetCancellationReason(orderNodeId, cancellationReasonId, eventId, false, false);
                }

                if (purchasedMaterialId != -1)
                {
                    _orderItemManager.SetPurchasedMaterial(orderNodeId, purchasedMaterialId, eventId, false, false);
                }

                // Use internal method to set status property and log the result
                _orderItemManager.SetStatus(orderNodeId, statusId, eventId);

                // Construct JSON response for client (ie jQuery/getJSON)
                json.Success = true;
                json.Message = "Changed status to " + statusId;
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Error: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult WriteLogItem(int nodeId, string Type, string Message, string newFollowUpDate, int statusId, int cancellationReasonId, int purchasedMaterialId)
        {
            // Json response
            var json = new ResultResponse();

            try
            {
                var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE);

                // Set FollowUpDate property if it differs from current
                DateTime currentFollowUpDate = _orderItemManager.GetOrderItem(nodeId).FollowUpDate;

                if (!String.IsNullOrEmpty(newFollowUpDate))
                {
                    DateTime parsedNewFollowUpDate = Convert.ToDateTime(newFollowUpDate);
                    if (currentFollowUpDate != parsedNewFollowUpDate)
                    {
                        _orderItemManager.SetFollowUpDate(nodeId, parsedNewFollowUpDate, eventId, false, false);
                    }
                }

                if (statusId != -1)
                {
                    _orderItemManager.SetStatus(nodeId, statusId, eventId, false, false);
                }

                if (cancellationReasonId != -1)
                {
                    _orderItemManager.SetCancellationReason(nodeId, cancellationReasonId, eventId, false, false);
                }

                if (purchasedMaterialId != -1)
                {
                    _orderItemManager.SetPurchasedMaterial(nodeId, purchasedMaterialId, eventId, false, false);
                }

                // Use internal method to set type property and log the result
                _orderItemManager.AddLogItem(nodeId, Type, Message, eventId);

                // Construct JSON response for client (ie jQuery/getJSON)
                json.Success = true;
                json.Message = "Wrote log entry to node" + nodeId;
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Error: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SendMail(OutgoingMailPackageModel m)
        {
            var json = new ResultResponse();

            try
            {
                // Read current values that can be affected
                var orderItem          = _orderItemManager.GetOrderItem(m.nodeId);
                var currentPatronEmail = orderItem.PatronEmail;
                var currentStatus      = orderItem.Status;

                var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE);

                // Send mail to recipient
                _mailService.SendMail(new OutgoingMailModel(orderItem.OrderId, m));

                _orderItemManager.AddLogItem(m.nodeId, "MAIL_NOTE", "Skickat mail till " + m.recipientEmail, eventId, false, false);
                _orderItemManager.AddLogItem(m.nodeId, "MAIL", m.message, eventId, false, false);

                // Set PatronEmail property if it differs from recipientEmail
                if (currentPatronEmail != m.recipientEmail)
                {
                    _orderItemManager.SetPatronEmail(m.nodeId, m.recipientEmail, eventId, false, false);
                }

                // Set FollowUpDate property if it differs from current
                DateTime currentFollowUpDate = orderItem.FollowUpDate;

                if (!String.IsNullOrEmpty(m.newFollowUpDate))
                {
                    DateTime parsedNewFollowUpDate = Convert.ToDateTime(m.newFollowUpDate);
                    if (currentFollowUpDate != parsedNewFollowUpDate)
                    {
                        _orderItemManager.SetFollowUpDate(m.nodeId, parsedNewFollowUpDate, eventId, false, false);
                    }
                }

                // Set status property if it differs from newStatus and if it is not -1 (no change)
                if (orderItem.StatusId != m.newStatusId && orderItem.StatusId != -1)
                {
                    _orderItemManager.SetStatus(m.nodeId, m.newStatusId, eventId, false, false);
                }

                // Update cancellation reason if we have a value that is not -1 (no change)
                if (orderItem.CancellationReasonId != m.newCancellationReasonId && m.newCancellationReasonId != -1)
                {
                    _orderItemManager.SetCancellationReason(m.nodeId, m.newCancellationReasonId, eventId, false, false);
                }

                // Update purchased material if we have a value that is not -1 (no change)
                if (orderItem.PurchasedMaterialId != m.newPurchasedMaterialId && m.newPurchasedMaterialId != -1)
                {
                    _orderItemManager.SetPurchasedMaterial(m.nodeId, m.newPurchasedMaterialId, eventId, false, false);
                }

                _orderItemManager.SaveWithoutEventsAndWithSynchronousReindexing(m.nodeId);

                // Construct JSON response for client (ie jQuery/getJSON)
                json.Success = true;
                json.Message = "Sent mail and eventually changed some properties.";
            }
            catch (Exception e)
            {
                json.Success = false;
                json.Message = "Error: " + e.Message;
            }

            return(Json(json, JsonRequestBehavior.AllowGet));
        }