Example #1
0
        protected override void OnHandling(SortUpPriceListLinkCommand command, CommandResult result)
        {
            var items = DataContext.PriceListLinks
                        .Where(i => !i.IsDeleted)
                        .OrderBy(i => i.OrderNumber)
                        .ToList();

            if (!items.Any())
            {
                result.ResultCode = CommandResultCode.Cancelled;
                return;
            }

            if (items.First().Id == command.Id)
            {
                result.ResultCode = CommandResultCode.Cancelled;
                return;
            }

            for (int i = 1; i < items.Count; i++)
            {
                PriceListLink item = items[i];
                item.OrderNumber = i;

                if (item.Id == command.Id)
                {
                    PriceListLink prevItem = items[i - 1];
                    item.OrderNumber     = prevItem.OrderNumber;
                    prevItem.OrderNumber = i;
                }

                DataContext.Entry(item).State = EntityState.Modified;
            }
        }
Example #2
0
        protected override void OnHandling(SortDownPriceListLinkCommand command, CommandResult result)
        {
            var items = DataContext.PriceListLinks
                        .Where(i => !i.IsDeleted)
                        .OrderBy(i => i.OrderNumber)
                        .ToList();

            if (!items.Any())
            {
                result.ResultCode = CommandResultCode.Cancelled;
                return;
            }

            if (items.Last().Id == command.Id)
            {
                result.ResultCode = CommandResultCode.Cancelled;
                return;
            }

            for (int i = items.Count - 2; i >= 0; i--)
            {
                PriceListLink item = items[i];
                item.OrderNumber = i;

                if (item.Id == command.Id)
                {
                    PriceListLink next = items[i + 1];
                    item.OrderNumber = next.OrderNumber;
                    next.OrderNumber = i;
                }

                DataContext.Entry(item).State = EntityState.Modified;
            }
        }
Example #3
0
        protected override GetPriceListLinkByIdQueryResult OnExecuting(IdCriterion criterion)
        {
            PriceListLink item = DataContext.PriceListLinks.Find(criterion.Id);

            GetPriceListLinkByIdQueryResult result = new GetPriceListLinkByIdQueryResult
            {
                Link    = item,
                IsFound = item != null
            };

            return(result);
        }
        protected override void OnHandling(AddPriceListLinkCommand command, CommandResult result)
        {
            var newItem = new PriceListLink
            {
                Text        = command.Text,
                Description = command.Description,
                Url         = command.Url,
                IsDeleted   = false
            };

            try
            {
                newItem.OrderNumber = DataContext.PriceListLinks.Count() + 1;
            }
            catch
            {
                newItem.OrderNumber = 1;
            }

            DataContext.PriceListLinks.Add(newItem);
        }
        protected EditPriceListLinkViewModel ToEditViewModel(PriceListLink model)
        {
            EditPriceListLinkViewModel vm = Mapper.Map <EditPriceListLinkViewModel>(model);

            return(vm);
        }
        protected PriceListLinkViewModel ToViewModel(PriceListLink model)
        {
            PriceListLinkViewModel vm = Mapper.Map <PriceListLinkViewModel>(model);

            return(vm);
        }