Пример #1
0
        public void UpdateTag(Ticket ticket, TicketTagGroup tagGroup, TicketTag ticketTag)
        {
            ticket.SetTagValue(tagGroup.Name, ticketTag.Name);

            if (tagGroup.FreeTagging && tagGroup.SaveFreeTags)
            {
                SaveFreeTicketTag(tagGroup.Id, ticketTag.Name);
            }

            var tagData = new TicketTagData
            {
                Ticket         = ticket,
                TicketTagGroup = tagGroup,
                TagName        = tagGroup.Name,
                TagValue       = ticketTag.Name
            };

            _automationService.NotifyEvent(RuleEventNames.TicketTagSelected,
                                           new
            {
                Ticket = ticket,
                tagData.TagName,
                tagData.TagValue,
                NumericValue = tagGroup.IsNumeric ? Convert.ToDecimal(ticketTag.Name) : 0,
                TicketTag    = ticket.GetTagData()
            });

            tagData.PublishEvent(EventTopicNames.TicketTagSelected);
        }
Пример #2
0
        private void OnSelectTicketTagGroup(TicketTagGroup obj)
        {
            var ticketTagData = new TicketTagData
            {
                TicketTagGroup = obj,
                Ticket         = _selectedTicket
            };

            ticketTagData.PublishEvent(EventTopicNames.SelectTicketTag);
        }
Пример #3
0
        private void OnShowTicketsTagExecute(TicketTagGroup tagGroup)
        {
            if (SelectedTicket == Ticket.Empty)
            {
                tagGroup.PublishEvent(EventTopicNames.ActivateTicketList);
                return;
            }
            var ticketTagData = new TicketTagData
            {
                TicketTagGroup = tagGroup,
                Ticket         = SelectedTicket
            };

            ticketTagData.PublishEvent(EventTopicNames.SelectTicketTag);
        }
Пример #4
0
 private void OnShowTicketsTagExecute(TicketTagGroup tagGroup)
 {
     if (SelectedTicket == Ticket.Empty)
     {
         tagGroup.PublishEvent(EventTopicNames.ActivateTicketList);
         return;
     }
     var ticketTagData = new TicketTagData
                             {
                                 TicketTagGroup = tagGroup,
                                 Ticket = SelectedTicket
                             };
     ticketTagData.PublishEvent(EventTopicNames.SelectTicketTag);
 }
        private static void HandleEvents()
        {
            EventServiceFactory.EventService.GetEvent<GenericEvent<ActionData>>().Subscribe(x =>
            {
                if (x.Value.Action.ActionType == "UpdateApplicationSubTitle")
                {
                    var title = x.Value.GetAsString("Title");
                    PresentationServices.SubTitle.ApplicationTitle = title;
                    var fontSize = x.Value.GetAsInteger("FontSize");
                    if (fontSize > 0) PresentationServices.SubTitle.ApplicationTitleFontSize = fontSize;
                    var fontColor = x.Value.GetAsString("Color");
                    if (!string.IsNullOrEmpty(fontColor))
                        PresentationServices.SubTitle.ApplicationTitleColor = fontColor;
                }
                if (x.Value.Action.ActionType == "RemoveLastModifier")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket == null) return;
                    var ti = x.Value.GetDataValue<TicketItem>("TicketItem");
                    if (ti == null) return;
                    if (ti.Properties.Count > 0)
                    {
                        var prop = ti.LastSelectedProperty ?? ti.Properties.Last();
                        prop.Quantity--;
                        if (prop.Quantity < 1)
                            ti.Properties.Remove(prop);
                    }
                    TicketViewModel.RecalculateTicket(ticket);
                }

                if (x.Value.Action.ActionType == "UpdateTicketItemPriceTag")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket == null) return;

                    var ti = x.Value.GetDataValue<TicketItem>("TicketItem");
                    if (ti == null) return;

                    var priceTag = x.Value.GetAsString("PriceTag");
                    var mi = AppServices.DataAccessService.GetMenuItem(ti.MenuItemId);
                    if (mi == null) return;

                    var portion = mi.Portions.SingleOrDefault(y => y.Name == ti.PortionName);
                    if (portion == null) return;

                    ti.UpdatePortion(portion, priceTag, null);

                    TicketViewModel.RecalculateTicket(ticket);
                    EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                }

                if (x.Value.Action.ActionType == "UpdateTicketItemTag")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket == null) return;

                    var ti = x.Value.GetDataValue<TicketItem>("TicketItem");
                    if (ti == null) return;

                    var tag = x.Value.GetAsString("Tag");
                    ti.Tag = tag;
                    decimal val;
                    decimal.TryParse(tag, out val);
                }

                if (x.Value.Action.ActionType == "UpdateLastTicketItemPriceTag")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket == null) return;

                    var ti = ticket.TicketItems.LastOrDefault();
                    if (ti == null) return;

                    var priceTag = x.Value.GetAsString("PriceTag");
                    var mi = AppServices.DataAccessService.GetMenuItem(ti.MenuItemId);
                    if (mi == null) return;

                    var portion = mi.Portions.SingleOrDefault(y => y.Name == ti.PortionName);
                    if (portion == null) return;

                    ti.UpdatePortion(portion, priceTag, null);

                    TicketViewModel.RecalculateTicket(ticket);
                    EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                }

                if (x.Value.Action.ActionType == "GiftLastTicketItem")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var ti = ticket.TicketItems.LastOrDefault();
                        if (ti != null)
                        {
                            decimal quantity;
                            decimal.TryParse(x.Value.Action.GetParameter("Quantity"), out quantity);
                            if (quantity > 0 && ti.Quantity > quantity)
                            {
                                ti.UpdateSelectedQuantity(quantity);
                                ti = ticket.ExtractSelectedTicketItems(new List<TicketItem> { ti }).FirstOrDefault();
                                if (ti == null) return;
                                AppServices.MainDataContext.AddItemToSelectedTicket(ti);
                            }
                            var reasonId = 0;
                            var giftReason = x.Value.Action.GetParameter("GiftReason");
                            if (!string.IsNullOrEmpty(giftReason))
                            {
                                var reason = Dao.SingleWithCache<Reason>(u => u.Name == giftReason);
                                if (reason != null) reasonId = reason.Id;
                            }
                            ticket.GiftItem(ti, reasonId, AppServices.CurrentLoggedInUser.Id);
                            TicketViewModel.RecalculateTicket(ticket);
                            EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                        }
                    }
                }

                if (x.Value.Action.ActionType == "UpdateTicketAccount")
                {
                    Expression<Func<Customer, bool>> qFilter = null;

                    var phoneNumber = x.Value.GetAsString("AccountPhone");
                    var accountName = x.Value.GetAsString("AccountName");
                    var note = x.Value.GetAsString("Note");

                    if (!string.IsNullOrEmpty(phoneNumber))
                    {
                        qFilter = y => y.PhoneNumber == phoneNumber;
                    }

                    if (!string.IsNullOrEmpty(accountName))
                    {
                        if (qFilter == null) qFilter = y => y.Name == accountName;
                        else qFilter = qFilter.And(y => y.Name == accountName);
                    }

                    if (!string.IsNullOrEmpty(note))
                    {
                        if (qFilter == null) qFilter = y => y.Note == note;
                        else qFilter = qFilter.And(y => y.Note == note);
                    }

                    if (qFilter != null)
                    {
                        var customer = Dao.Query(qFilter).FirstOrDefault();
                        if (customer != null)
                            AppServices.MainDataContext.AssignCustomerToSelectedTicket(customer);
                    }
                    else AppServices.MainDataContext.AssignCustomerToSelectedTicket(Customer.Null);
                }

                if (x.Value.Action.ActionType == "UpdateProgramSetting")
                {
                    SettingAccessor.ResetCache();

                    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
                            ? AppServices.SettingService.ReadLocalSetting(settingName)
                            : AppServices.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 == "Multiply")
                        {
                            if (string.IsNullOrEmpty(setting.StringValue))
                                setting.DecimalValue = 0;
                            else
                                setting.DecimalValue = setting.DecimalValue * x.Value.GetAsDecimal("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) AppServices.SettingService.SaveChanges();
                    }
                }

                if (x.Value.Action.ActionType == "RefreshCache")
                {
                    MethodQueue.Queue("ResetCache", ResetCache);
                }

                if (x.Value.Action.ActionType == "SendMessage")
                {
                    AppServices.MessagingService.SendMessage("ActionMessage", x.Value.GetAsString("Command"));
                }

                if (x.Value.Action.ActionType == "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("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 == "ExecuteTicketEvent")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var operationName = x.Value.GetAsString("TicketOperation");
                        if (operationName == Resources.Refresh)
                            EventServiceFactory.EventService.PublishEvent(EventTopicNames.DisplayTicketView);
                        if (operationName == Resources.Close)
                            ticket.PublishEvent(EventTopicNames.PaymentSubmitted);
                    }
                }

                if (x.Value.Action.ActionType == "UpdateTicketVat")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var vatTemplateName = x.Value.GetAsString("VatTemplate");
                        var vatTemplate = AppServices.MainDataContext.VatTemplates.FirstOrDefault(y => y.Name == vatTemplateName);
                        if (vatTemplate != null)
                        {
                            ticket.UpdateVat(vatTemplate);
                            TicketViewModel.RecalculateTicket(ticket);
                            EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                        }
                    }
                }

                if (x.Value.Action.ActionType == "UpdateTicketTaxService")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var taxServiceTemplateName = x.Value.GetAsString("TaxServiceTemplate");
                        var taxServiceTemplate =
                            AppServices.MainDataContext.TaxServiceTemplates.FirstOrDefault(
                                y => y.Name == taxServiceTemplateName);
                        if (taxServiceTemplate != null)
                        {
                            var amount = x.Value.GetAsDecimal("Amount");
                            ticket.AddTaxService(taxServiceTemplate.Id, taxServiceTemplate.CalculationMethod, amount);
                            TicketViewModel.RecalculateTicket(ticket);
                        }
                    }
                }

                if (x.Value.Action.ActionType == "RegenerateTicketVat")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        TicketViewModel.RegenerateVatRates(ticket);
                        TicketViewModel.RecalculateTicket(ticket);
                        EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                    }
                }

                if (x.Value.Action.ActionType == "AddTicketDiscount")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var percentValue = x.Value.GetAsDecimal("DiscountPercentage");
                        ticket.AddTicketDiscount(DiscountType.Percent, percentValue, AppServices.CurrentLoggedInUser.Id);
                        TicketViewModel.RecalculateTicket(ticket);
                    }
                }

                if (x.Value.Action.ActionType == "AddTicketItem")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");

                    if (ticket != null)
                    {
                        var menuItemName = x.Value.GetAsString("MenuItemName");
                        var menuItem = AppServices.DataAccessService.GetMenuItemByName(menuItemName);
                        var portionName = x.Value.GetAsString("PortionName");
                        var quantity = x.Value.GetAsDecimal("Quantity");
                        var gifted = x.Value.GetAsBoolean("Gift");
                        var giftReason = x.Value.GetAsString("GiftReason");
                        var tag = x.Value.GetAsString("Tag");

                        var departmentId = AppServices.CurrentTerminal.DepartmentId > 0
                               ? AppServices.MainDataContext.SelectedDepartment.Id
                               : ticket.DepartmentId;

                        var ti = ticket.AddTicketItem(AppServices.CurrentLoggedInUser.Id,
                            departmentId, menuItem, portionName,
                            AppServices.MainDataContext.SelectedDepartment.PriceTag, "");

                        ti.Quantity = quantity;
                        ti.Gifted = gifted;
                        if (gifted && !string.IsNullOrEmpty(giftReason))
                        {
                            var reason = Dao.SingleWithCache<Reason>(u => u.Name == giftReason);
                            if (reason != null) ti.ReasonId = reason.Id;
                        }
                        else
                        {
                            ti.ReasonId = 0;
                        }
                        ti.Tag = tag;

                        TicketViewModel.RecalculateTicket(ticket);
                        EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                    }
                }

                if (x.Value.Action.ActionType == "VoidTicketItems")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var menuItemName = x.Value.GetAsString("MenuItemName");
                        var tag = x.Value.GetAsString("Tag");
                        if (!string.IsNullOrEmpty(menuItemName) && !string.IsNullOrEmpty(tag))
                        {
                            var lines = ticket.TicketItems.Where(y => !y.Voided &&
                                (string.IsNullOrEmpty(menuItemName) || y.MenuItemName.Contains(menuItemName)) &&
                                (y.Tag.Contains(tag) || string.IsNullOrEmpty(tag))).ToList();
                            lines.ForEach(y => ticket.VoidItem(y, 0, AppServices.CurrentLoggedInUser.Id));
                            TicketViewModel.RecalculateTicket(ticket);
                            EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                        }
                    }
                }

                if (x.Value.Action.ActionType == "UpdateTicketTag")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var tagName = x.Value.GetAsString("TagName");
                        var tagValue = x.Value.GetAsString("TagValue");
                        if (tagValue.Contains(","))
                        {
                            var ctag = ticket.GetTagValue(tagName);
                            if (!string.IsNullOrEmpty(ctag))
                            {
                                var nextTag = tagValue.Split(',').SkipWhile(y => y != ctag).Skip(1).FirstOrDefault();
                                if (string.IsNullOrEmpty(nextTag)) nextTag = tagValue.Split(',')[0];
                                tagValue = nextTag;
                            }
                        }
                        ticket.SetTagValue(tagName, tagValue);
                        var tagData = new TicketTagData { TagName = tagName, TagValue = tagValue };
                        tagData.PublishEvent(EventTopicNames.TagSelectedForSelectedTicket);
                    }
                }

                if (x.Value.Action.ActionType == "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 == "ExecutePrintJob")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    var pjName = x.Value.GetAsString("PrintJobName");
                    var ticketItemTag = x.Value.GetAsString("TicketItemTag");

                    if (!string.IsNullOrEmpty(pjName))
                    {
                        var j = AppServices.CurrentTerminal.PrintJobs.SingleOrDefault(y => y.Name == pjName);

                        if (j != null)
                        {
                            if (ticket != null)
                            {
                                AppServices.MainDataContext.UpdateTicketNumber(ticket);
                                if (j.LocksTicket) ticket.RequestLock();

                                var clonedTicket = ObjectCloner.Clone(ticket);
                                clonedTicket.CopyPaidItemsCache(ticket);
                                if (!string.IsNullOrEmpty(ticketItemTag))
                                    clonedTicket.TicketItems =
                                        clonedTicket.TicketItems.Where(y => !string.IsNullOrEmpty(y.Tag) &&
                                                y.Tag.ToLower().Contains(ticketItemTag.Trim().ToLower())).ToList();
                                AppServices.PrintService.ManualPrintTicket(clonedTicket, j);
                            }
                            else
                                AppServices.PrintService.ExecutePrintJob(j);
                        }
                    }
                }
            });
        }
Пример #6
0
        public void UpdateTag(TicketTagGroup tagGroup, TicketTag ticketTag)
        {
            Model.SetTagValue(tagGroup.Name, ticketTag.Name);
            if (tagGroup.Numerator != null)
            {
                Model.TicketNumber = "";
                AppServices.MainDataContext.UpdateTicketNumber(Model, tagGroup.Numerator);
            }

            if (ticketTag.AccountId > 0)
                AppServices.MainDataContext.AssignCustomerToTicket(Model,
                    Dao.SingleWithCache<Customer>(x => x.Id == ticketTag.AccountId));

            ClearSelectedItems();

            var tagData = new TicketTagData { Action = tagGroup.Action, TagName = tagGroup.Name, TagValue = ticketTag.Name, NumericValue = tagGroup.NumericTags || tagGroup.PriceTags ? Convert.ToDecimal(ticketTag.Name) : 0 };

            RuleExecutor.NotifyEvent(RuleEventNames.TicketTagSelected,
                        new
                        {
                            Ticket = Model,
                            tagData.TagName,
                            tagData.TagValue,
                            tagData.NumericValue,
                            TicketTag = Model.Tag
                        });

            tagData.PublishEvent(EventTopicNames.TagSelectedForSelectedTicket);
        }
Пример #7
0
        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);
                        }
                    }
                }
            });
        }
        private static void HandleEvents()
        {
            EventServiceFactory.EventService.GetEvent<GenericEvent<IActionData>>().Subscribe(x =>
            {
                if (x.Value.Action.ActionType == "DisplayPaymentScreen")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        ticket.PublishEvent(EventTopicNames.MakePayment);
                    }
                }

                if (x.Value.Action.ActionType == "LockTicket")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        ticket.LockTicket();
                    }
                }

                if (x.Value.Action.ActionType == "DisplayTicket")
                {
                    var ticketId = x.Value.GetAsInteger("TicketId");
                    if (ticketId > 0)
                        ExtensionMethods.PublishIdEvent(ticketId, EventTopicNames.DisplayTicket);
                }

                if (x.Value.Action.ActionType == "CreateTicket")
                {
                    EventServiceFactory.EventService.PublishEvent(EventTopicNames.CreateTicket);
                }

                if (x.Value.Action.ActionType == "UnlockTicket")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null) ticket.Locked = false;
                    EventServiceFactory.EventService.PublishEvent(EventTopicNames.UnlockTicketRequested);
                }

                if (x.Value.Action.ActionType == "CloseActiveTicket")
                {
                    EventServiceFactory.EventService.PublishEvent(EventTopicNames.CloseTicketRequested);
                }

                if (x.Value.Action.ActionType == "UpdateResourceState")
                {
                    var resourceId = x.Value.GetDataValueAsInt("ResourceId");
                    var resourceTemplateId = x.Value.GetDataValueAsInt("ResourceTemplateId");
                    var stateName = x.Value.GetAsString("ResourceState");
                    var state = CacheService.GetResourceStateByName(stateName);
                    if (state != null)
                    {
                        if (resourceId > 0 && resourceTemplateId > 0)
                        {
                            ResourceService.UpdateResourceState(resourceId, state.Id);
                        }
                        else
                        {
                            var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                            if (ticket != null)
                            {
                                var resourceTemplateName = x.Value.GetDataValueAsString("ResourceTemplateName");
                                foreach (var ticketResource in ticket.TicketResources)
                                {
                                    var resourceTemplate = CacheService.GetResourceTemplateById(ticketResource.ResourceTemplateId);
                                    if (string.IsNullOrEmpty(resourceTemplateName.Trim()) || resourceTemplate.Name == resourceTemplateName)
                                        ResourceService.UpdateResourceState(ticketResource.ResourceId, state.Id);
                                }
                            }
                        }
                    }
                }

                if (x.Value.Action.ActionType == "UpdateTicketAccount")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        Expression<Func<Resource, bool>> qFilter = null;

                        var phoneNumber = x.Value.GetAsString("AccountPhone");
                        var accountName = x.Value.GetAsString("AccountName");
                        var note = x.Value.GetAsString("Note");

                        if (!string.IsNullOrEmpty(phoneNumber))
                        {
                            qFilter = y => y.SearchString == phoneNumber;
                        }

                        if (!string.IsNullOrEmpty(accountName))
                        {
                            if (qFilter == null) qFilter = y => y.Name == accountName;
                            else qFilter = qFilter.And(y => y.Name == accountName);
                        }

                        if (qFilter != null)
                        {
                            var account = Dao.Query(qFilter).FirstOrDefault();
                            if (account != null)
                                TicketService.UpdateResource(ticket, account);
                        }
                        else TicketService.UpdateResource(ticket, Resource.Null);
                    }
                }

                if (x.Value.Action.ActionType == "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 == "RefreshCache")
                {
                    MethodQueue.Queue("ResetCache", ResetCache);
                }

                if (x.Value.Action.ActionType == "SendMessage")
                {
                    AppServices.MessagingService.SendMessage("ActionMessage", x.Value.GetAsString("Command"));
                }

                if (x.Value.Action.ActionType == "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 == "UpdateTicketTax")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var taxTemplateName = x.Value.GetAsString("TaxTemplate");
                        var taxTemplate = SettingService.GetTaxTemplateByName(taxTemplateName);
                        if (taxTemplate != null)
                        {
                            ticket.UpdateTax(taxTemplate);
                            TicketService.RecalculateTicket(ticket);
                            EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                        }
                    }
                }

                if (x.Value.Action.ActionType == "UpdateTicketService")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        var calculationTemplateName = x.Value.GetAsString("CalculationTemplate");
                        var calculationTemplate = SettingService.GetCalculationTemplateByName(calculationTemplateName);
                        if (calculationTemplate != null)
                        {
                            var amount = x.Value.GetAsDecimal("Amount");
                            ticket.AddCalculation(calculationTemplate, amount);
                            TicketService.RecalculateTicket(ticket);
                        }
                    }
                }

                if (x.Value.Action.ActionType == "RegenerateTicketTax")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    if (ticket != null)
                    {
                        TicketService.RegenerateTaxRates(ticket);
                        TicketService.RecalculateTicket(ticket);
                        EventServiceFactory.EventService.PublishEvent(EventTopicNames.RefreshSelectedTicket);
                    }
                }

                if (x.Value.Action.ActionType == "AddTicketDiscount")
                {
                    //var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    //if (ticket != null)
                    //{
                    //    var percentValue = x.Value.GetAsDecimal("DiscountPercentage");
                    //    ticket.AddTicketDiscount(DiscountType.Percent, percentValue, ApplicationState.CurrentLoggedInUser.Id);
                    //    TicketService.RecalculateTicket(ticket);
                    //}
                }

                if (x.Value.Action.ActionType == "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 == "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.TagSelectedForSelectedTicket);
                    }
                }

                if (x.Value.Action.ActionType == "TagOrder" || x.Value.Action.ActionType == "UntagOrder" || x.Value.Action.ActionType == "RemoveOrderTag")
                {
                    var order = x.Value.GetDataValue<Order>("Order");
                    if (order != null)
                    {
                        var tagName = x.Value.GetAsString("OrderTagName");
                        var orderTag = CacheService.GetOrderTagGroupByName(tagName);

                        if (orderTag != null)
                        {
                            if (x.Value.Action.ActionType == "RemoveOrderTag")
                            {
                                var tags = order.OrderTagValues.Where(y => y.OrderTagGroupId == orderTag.Id);
                                tags.ToList().ForEach(y => order.OrderTagValues.Remove(y));
                                return;
                            }
                            var tagValue = x.Value.GetAsString("OrderTagValue");
                            var orderTagValue = orderTag.OrderTags.SingleOrDefault(y => y.Name == tagValue);
                            if (orderTagValue != null)
                            {
                                if (x.Value.Action.ActionType == "TagOrder")
                                    order.TagIfNotTagged(orderTag, orderTagValue, ApplicationState.CurrentLoggedInUser.Id);
                                if (x.Value.Action.ActionType == "UntagOrder")
                                    order.UntagIfTagged(orderTag, orderTagValue, ApplicationState.CurrentLoggedInUser.Id);
                            }
                        }
                    }
                }

                if (x.Value.Action.ActionType == "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 == "ExecutePrintJob")
                {
                    var ticket = x.Value.GetDataValue<Ticket>("Ticket");
                    var pjName = x.Value.GetAsString("PrintJobName");
                    if (!string.IsNullOrEmpty(pjName))
                    {
                        TicketService.UpdateTicketNumber(ticket, ApplicationState.CurrentDepartment.TicketTemplate.TicketNumerator);
                        var j = CacheService.GetPrintJobByName(pjName);

                        if (j != null)
                        {
                            if (ticket != null)
                                PrinterService.PrintTicket(ticket, j);
                            else
                                PrinterService.ExecutePrintJob(j);
                        }
                    }
                }
            });
        }
Пример #9
0
        public void UpdateTag(Ticket ticket, TicketTagGroup tagGroup, TicketTag ticketTag)
        {
            ticket.SetTagValue(tagGroup.Name, ticketTag.Name);

            if (tagGroup.FreeTagging && tagGroup.SaveFreeTags)
            {
                SaveFreeTicketTag(tagGroup.Id, ticketTag.Name);
            }

            var tagData = new TicketTagData
            {
                Ticket = ticket,
                TicketTagGroup = tagGroup,
                TagName = tagGroup.Name,
                TagValue = ticketTag.Name
            };

            _automationService.NotifyEvent(RuleEventNames.TicketTagSelected,
                        new
                        {
                            Ticket = ticket,
                            tagData.TagName,
                            tagData.TagValue,
                            NumericValue = tagGroup.IsNumeric ? Convert.ToDecimal(ticketTag.Name) : 0,
                            TicketTag = ticket.GetTagData()
                        });

            tagData.PublishEvent(EventTopicNames.TicketTagSelected);
        }
Пример #10
0
 private void OnShowTicketsTagExecute(TicketTagGroup tagGroup)
 {
     if (SelectedTicket != null)
     {
         var ticketTagData = new TicketTagData
                                 {
                                     TicketTagGroup = tagGroup,
                                     Ticket = SelectedTicket.Model
                                 };
         ticketTagData.PublishEvent(EventTopicNames.SelectTicketTag);
     }
     else if (ShowAllOpenTickets.CanExecute(""))
     {
         SelectedDepartment.PublishEvent(EventTopicNames.ActivateOpenTickets);
         //todo bi çözüm bulalým
         //if ((OpenTickets != null && OpenTickets.Count() > 0))
         //{
         //    SelectedTicketView = OpenTicketListView;
         //    RaisePropertyChanged(() => OpenTickets);
         //}
         //else InteractionService.UserIntraction.GiveFeedback(string.Format(Resources.NoTicketsFoundForTag, tagGroup.Name));
     }
 }
Пример #11
0
 private void OnSelectTicketTagGroup(TicketTagGroup obj)
 {
     var ticketTagData = new TicketTagData
     {
         TicketTagGroup = obj,
         Ticket = _selectedTicket
     };
     ticketTagData.PublishEvent(EventTopicNames.SelectTicketTag);
 }