public override void Process(ActionData actionData) { var ticketTagName = actionData.GetAsString("TicketTagName"); var ticketStateName = actionData.GetAsString("TicketStateName"); if (!string.IsNullOrEmpty(ticketStateName)) { var dt = new TicketStateData { StateName = ticketStateName }; dt.PublishEvent(EventTopicNames.ActivateTicketList); } else if (!string.IsNullOrEmpty(ticketTagName)) { var dt = new TicketTagGroup { Name = ticketTagName }; dt.PublishEvent(EventTopicNames.ActivateTicketList); } }
private static void HandleEvents() { EventServiceFactory.EventService.GetEvent<GenericEvent<IActionData>>().Subscribe(x => { if (x.Value.Action.ActionType == ActionNames.ChangeTicketEntity) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { var entityTypeName = x.Value.GetAsString("EntityTypeName"); var entityName = x.Value.GetAsString("EntityName"); if (!string.IsNullOrEmpty(entityTypeName)) { var entity = CacheService.GetEntityByName(entityTypeName, entityName); if (entity != null) TicketService.UpdateEntity(ticket, entity); } } } if (x.Value.Action.ActionType == ActionNames.UpdateOrder) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); var orders = GetOrders(x.Value, ticket); if (orders.Any()) { foreach (var order in orders) { if (!string.IsNullOrEmpty(x.Value.GetAsString("Quantity"))) order.Quantity = x.Value.GetAsDecimal("Quantity"); if (!string.IsNullOrEmpty(x.Value.GetAsString("Price"))) order.UpdatePrice(x.Value.GetAsDecimal("Price"), ""); if (!string.IsNullOrEmpty(x.Value.GetAsString("IncreaseInventory"))) order.IncreaseInventory = x.Value.GetAsBoolean("IncreaseInventory"); if (!string.IsNullOrEmpty(x.Value.GetAsString("DecreaseInventory"))) order.DecreaseInventory = x.Value.GetAsBoolean("DecreaseInventory"); if (!string.IsNullOrEmpty(x.Value.GetAsString("Locked"))) order.Locked = x.Value.GetAsBoolean("Locked"); if (!string.IsNullOrEmpty(x.Value.GetAsString("CalculatePrice"))) order.CalculatePrice = x.Value.GetAsBoolean("CalculatePrice"); if (!string.IsNullOrEmpty(x.Value.GetAsString("AccountTransactionType"))) TicketService.ChangeOrdersAccountTransactionTypeId(ticket, new List<Order> { order }, CacheService. GetAccountTransactionTypeIdByName (x.Value.GetAsString( "AccountTransactionType"))); } } } if (x.Value.Action.ActionType == ActionNames.ExecuteScript) { var script = x.Value.GetAsString("ScriptName"); if (!string.IsNullOrEmpty(script)) { ExpressionService.EvalCommand(script, null, x.Value.DataObject, true); } } if (x.Value.Action.ActionType == ActionNames.ExecutePowershellScript) { var script = x.Value.GetAsString("Script"); if (!string.IsNullOrEmpty(script)) { if (Utility.IsValidFile(script)) script = File.ReadAllText(script); var runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); runspace.SessionStateProxy.SetVariable("locator", ServiceLocator.Current); var pipeline = runspace.CreatePipeline(script); pipeline.Invoke(); runspace.Close(); } } if (x.Value.Action.ActionType == ActionNames.DisplayPaymentScreen) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { ticket.PublishEvent(EventTopicNames.MakePayment); } } if (x.Value.Action.ActionType == ActionNames.LockTicket) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { ticket.RequestLock(); } } if (x.Value.Action.ActionType == ActionNames.DisplayTicket) { var ticketId = x.Value.GetAsInteger("TicketId"); if (ticketId > 0) ExtensionMethods.PublishIdEvent(ticketId, EventTopicNames.DisplayTicket); else EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket); } if (x.Value.Action.ActionType == ActionNames.DisplayTicketList) { var ticketTagName = x.Value.GetAsString("TicketTagName"); var ticketStateName = x.Value.GetAsString("TicketStateName"); if (!string.IsNullOrEmpty(ticketStateName)) { var dt = new TicketStateData { StateName = ticketStateName }; dt.PublishEvent(EventTopicNames.ActivateTicketList); } else if (!string.IsNullOrEmpty(ticketTagName)) { var dt = new TicketTagGroup { Name = ticketTagName }; dt.PublishEvent(EventTopicNames.ActivateTicketList); } } if (x.Value.Action.ActionType == ActionNames.CreateTicket) { EventServiceFactory.EventService.PublishEvent(EventTopicNames.CreateTicket); } if (x.Value.Action.ActionType == ActionNames.UnlockTicket) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) ticket.UnLock(); EventServiceFactory.EventService.PublishEvent(EventTopicNames.UnlockTicketRequested); } if (x.Value.Action.ActionType == ActionNames.CloseActiveTicket) { EventServiceFactory.EventService.PublishEvent(EventTopicNames.CloseTicketRequested, true); } if (x.Value.Action.ActionType == ActionNames.UpdateEntityState) { var entityId = x.Value.GetDataValueAsInt("EntityId"); var entityTypeId = x.Value.GetDataValueAsInt("EntityTypeId"); var stateName = x.Value.GetAsString("EntityStateName"); var state = x.Value.GetAsString("EntityState"); if (state != null) { if (entityId > 0 && entityTypeId > 0) { EntityService.UpdateEntityState(entityId, entityTypeId, stateName, state); } else { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { var entityTypeName = x.Value.GetDataValueAsString("EntityTypeName"); foreach (var ticketEntity in ticket.TicketEntities) { var entityType = CacheService.GetEntityTypeById(ticketEntity.EntityTypeId); if (string.IsNullOrEmpty(entityTypeName.Trim()) || entityType.Name == entityTypeName) EntityService.UpdateEntityState(ticketEntity.EntityId, ticketEntity.EntityTypeId, stateName, state); } } } } } if (x.Value.Action.ActionType == ActionNames.UpdateProgramSetting) { var settingName = x.Value.GetAsString("SettingName"); var updateType = x.Value.GetAsString("UpdateType"); if (!string.IsNullOrEmpty(settingName)) { var isLocal = x.Value.GetAsBoolean("IsLocal"); var setting = isLocal ? SettingService.ReadLocalSetting(settingName) : SettingService.ReadGlobalSetting(settingName); if (updateType == Resources.Increase) { var settingValue = x.Value.GetAsInteger("SettingValue"); if (string.IsNullOrEmpty(setting.StringValue)) setting.IntegerValue = settingValue; else setting.IntegerValue = setting.IntegerValue + settingValue; } else if (updateType == Resources.Decrease) { var settingValue = x.Value.GetAsInteger("SettingValue"); if (string.IsNullOrEmpty(setting.StringValue)) setting.IntegerValue = settingValue; else setting.IntegerValue = setting.IntegerValue - settingValue; } else if (updateType == "Toggle") { var settingValue = x.Value.GetAsString("SettingValue"); var parts = settingValue.Split(','); if (string.IsNullOrEmpty(setting.StringValue)) { setting.StringValue = parts[0]; } else { for (var i = 0; i < parts.Length; i++) { if (parts[i] == setting.StringValue) { setting.StringValue = (i + 1) < parts.Length ? parts[i + 1] : parts[0]; break; } } } } else { var settingValue = x.Value.GetAsString("SettingValue"); setting.StringValue = settingValue; } if (!isLocal) SettingService.SaveProgramSettings(); } } if (x.Value.Action.ActionType == ActionNames.RefreshCache) { MethodQueue.Queue("ResetCache", ResetCache); } if (x.Value.Action.ActionType == ActionNames.SendMessage) { AppServices.MessagingService.SendMessage("ActionMessage", x.Value.GetAsString("Command")); } if (x.Value.Action.ActionType == ActionNames.SendEmail) { EmailService.SendEMailAsync(x.Value.GetAsString("SMTPServer"), x.Value.GetAsString("SMTPUser"), x.Value.GetAsString("SMTPPassword"), x.Value.GetAsInteger("SMTPPort"), x.Value.GetAsString("ToEMailAddress"), x.Value.GetAsString("CCEmailAddresses"), x.Value.GetAsString("FromEMailAddress"), x.Value.GetAsString("Subject"), x.Value.GetAsString("EMailMessage"), x.Value.GetAsString("FileName"), x.Value.GetAsBoolean("DeleteFile"), x.Value.GetAsBoolean("BypassSslErrors")); } if (x.Value.Action.ActionType == ActionNames.UpdateTicketCalculation) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { var calculationTypeName = x.Value.GetAsString("CalculationType"); var calculationType = SettingService.GetCalculationTypeByName(calculationTypeName); if (calculationType != null) { var amount = x.Value.GetAsDecimal("Amount"); ticket.AddCalculation(calculationType, amount); TicketService.RecalculateTicket(ticket); } } } if (x.Value.Action.ActionType == ActionNames.AddOrder) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { var menuItemName = x.Value.GetAsString("MenuItemName"); var menuItem = CacheService.GetMenuItem(y => y.Name == menuItemName); var portionName = x.Value.GetAsString("PortionName"); var quantity = x.Value.GetAsDecimal("Quantity"); var tag = x.Value.GetAsString("Tag"); var order = TicketService.AddOrder(ticket, menuItem.Id, quantity, portionName, null); if (order != null) order.Tag = tag; } } if (x.Value.Action.ActionType == ActionNames.UpdateTicketTag) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { var tagName = x.Value.GetAsString("TagName"); var tagValue = x.Value.GetAsString("TagValue"); ticket.SetTagValue(tagName, tagValue); var tagData = new TicketTagData { TagName = tagName, TagValue = tagValue }; tagData.PublishEvent(EventTopicNames.TicketTagSelected); } } if (x.Value.Action.ActionType == ActionNames.UpdateTicketState) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); if (ticket != null) { var stateName = x.Value.GetAsString("StateName"); var currentState = x.Value.GetAsString("CurrentState"); var state = x.Value.GetAsString("State"); var stateValue = x.Value.GetAsString("StateValue"); var quantity = x.Value.GetAsInteger("Quantity"); TicketService.UpdateTicketState(ticket, stateName, currentState, state, stateValue, quantity); } } if (x.Value.Action.ActionType == ActionNames.UpdateOrderState) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); var orders = GetOrders(x.Value, ticket); if (orders.Any()) { var stateName = x.Value.GetAsString("StateName"); var currentState = x.Value.GetAsString("CurrentState"); var groupOrder = x.Value.GetAsInteger("GroupOrder"); var state = x.Value.GetAsString("State"); var stateOrder = x.Value.GetAsInteger("StateOrder"); var stateValue = x.Value.GetAsString("StateValue"); TicketService.UpdateOrderStates(ticket, orders.ToList(), stateName, currentState, groupOrder, state, stateOrder, stateValue); } } if (x.Value.Action.ActionType == ActionNames.TagOrder || x.Value.Action.ActionType == ActionNames.UntagOrder || x.Value.Action.ActionType == ActionNames.RemoveOrderTag) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); var orders = GetOrders(x.Value, ticket); if (orders.Any()) { var tagName = x.Value.GetAsString("OrderTagName"); var orderTag = CacheService.GetOrderTagGroupByName(tagName); if (orderTag != null) { var tagValue = x.Value.GetAsString("OrderTagValue"); var oldTagValue = x.Value.GetAsString("OldOrderTagValue"); var tagNote = x.Value.GetAsString("OrderTagNote"); var orderTagValue = orderTag.OrderTags.SingleOrDefault(y => y.Name == tagValue); if (orderTagValue != null) { if (!string.IsNullOrEmpty(oldTagValue)) orders = orders.Where(o => o.OrderTagExists(y => y.OrderTagGroupId == orderTag.Id && y.TagValue == oldTagValue)).ToList(); if (x.Value.Action.ActionType == ActionNames.TagOrder) TicketService.TagOrders(ticket, orders, orderTag, orderTagValue, tagNote); if (x.Value.Action.ActionType == ActionNames.UntagOrder) TicketService.UntagOrders(ticket, orders, orderTag, orderTagValue); } //foreach (var order in orders) //{ // if (x.Value.Action.ActionType == ActionNames.RemoveOrderTag) // { // var tags = order.OrderTagValues.Where(y => y.OrderTagGroupId == orderTag.Id); // tags.ToList().ForEach(y => order.OrderTagValues.Remove(y)); // continue; // } //} } } } if (x.Value.Action.ActionType == ActionNames.MoveTaggedOrders) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); var orderTagName = x.Value.GetAsString("OrderTagName"); if (ticket != null && !string.IsNullOrEmpty(orderTagName)) { var orderTagValue = x.Value.GetAsString("OrderTagValue"); if (ticket.Orders.Any(y => y.OrderTagExists(z => z.TagName == orderTagName && z.TagValue == orderTagValue))) { var tid = ticket.Id; EventServiceFactory.EventService.PublishEvent(EventTopicNames.CloseTicketRequested, true); ticket = TicketService.OpenTicket(tid); var orders = ticket.Orders.Where(y => y.OrderTagExists(z => z.TagName == orderTagName && z.TagValue == orderTagValue)).ToArray(); var commitResult = TicketService.MoveOrders(ticket, orders, 0); if (string.IsNullOrEmpty(commitResult.ErrorMessage) && commitResult.TicketId > 0) { ExtensionMethods.PublishIdEvent(commitResult.TicketId, EventTopicNames.DisplayTicket); } else { ExtensionMethods.PublishIdEvent(tid, EventTopicNames.DisplayTicket); } } } } if (x.Value.Action.ActionType == ActionNames.UpdatePriceTag) { using (var workspace = WorkspaceFactory.Create()) { var priceTag = x.Value.GetAsString("PriceTag"); var departmentName = x.Value.GetAsString("DepartmentName"); var department = workspace.Single<Department>(y => y.Name == departmentName); if (department != null) { department.PriceTag = priceTag; workspace.CommitChanges(); MethodQueue.Queue("ResetCache", ResetCache); } } } if (x.Value.Action.ActionType == ActionNames.ExecutePrintJob) { var ticket = x.Value.GetDataValue<Ticket>("Ticket"); var pjName = x.Value.GetAsString("PrintJobName"); if (!string.IsNullOrEmpty(pjName)) { TicketService.UpdateTicketNumber(ticket, ApplicationState.CurrentTicketType.TicketNumerator); var j = CacheService.GetPrintJobByName(pjName); if (j != null) { if (ticket != null) { var orderTagName = x.Value.GetAsString("OrderTagName"); var orderTagValue = x.Value.GetAsString("OrderTagValue"); var orderStateName = x.Value.GetAsString("OrderStateName"); var orderState = x.Value.GetAsString("OrderState"); var orderStateValue = x.Value.GetAsString("OrderStateValue"); Expression<Func<Order, bool>> expression = ex => true; if (!string.IsNullOrWhiteSpace(orderTagName)) { expression = ex => ex.OrderTagExists(y => y.TagName == orderTagName && y.TagValue == orderTagValue); } if (!string.IsNullOrWhiteSpace(orderStateName)) { expression = expression.And(ex => ex.IsInState(orderStateName, orderState)); if (!string.IsNullOrWhiteSpace(orderStateValue)) expression = expression.And(ex => ex.IsInState(orderStateValue)); } PrinterService.PrintTicket(ticket, j, expression.Compile()); } else PrinterService.ExecutePrintJob(j); } } } }); }
public void UpdateListByTicketState(TicketStateData value) { SelectedEntity = null; var stateValue = string.Format("\"S\":\"{0}\"", value.StateName); _tickets = _ticketServiceBase.GetOpenTickets(x => x.TicketStates.Contains(stateValue)).Select(x => new TicketButtonViewModel(x, null)).ToList(); Refresh(); }