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 SetProvider(int nodeId, string providerName, string providerOrderId, string providerInformation, string newFollowUpDate, bool updateStatusAndFollowUpDate = true) { var json = new ResultResponse(); try { var eventType = PROVIDER_DATA_UPDATED_EVENT_TYPE; if (updateStatusAndFollowUpDate) { eventType = EVENT_TYPE; } var eventId = _orderItemManager.GenerateEventId(eventType); if (updateStatusAndFollowUpDate) { _orderItemManager.SetFollowUpDate(nodeId, Convert.ToDateTime(newFollowUpDate), eventId, false, false); } _orderItemManager.SetProviderName(nodeId, providerName, eventId, false, false); _orderItemManager.SetProviderOrderId(nodeId, providerOrderId, eventId, false, false); _orderItemManager.SetProviderInformation(nodeId, providerInformation, eventId, false, false); if (updateStatusAndFollowUpDate) { _orderItemManager.SetStatus(nodeId, "03:Beställd", eventId, false, false); } _orderItemManager.SaveWithoutEventsAndWithSynchronousReindexing(nodeId); json.Success = true; json.Message = "Sparade data för beställning."; } 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)); }