public override string ToString()
 {
     return("StyleId=" + StyleId
            + ", IncomeType=" + IncomeType
            + ", BoxBarcode=" + BoxBarcode
            + ", BoxQuantity=" + BoxQuantity
            + ", Printed=" + Printed
            + ", PolyBags=" + PolyBags
            + ", Owned=" + Owned
            + ", Price=" + Price
            + ", Sizes=" + (Sizes == null
                ? "[null]"
                : String.Join(",\r\n", Sizes.Select(s => s.ToString()).ToList())));
 }
Beispiel #2
0
 internal void CacheMeta(FieldInfo field)
 {
     Initialized = true;
     FieldInfo   = field;
     Types       = field.FieldType.RepeatAggregated(Math.Max(ElementsCount.Count, 2), NextType).ToArray();
     Rank        = Types.Count - 1;
     Meta        = Types[Rank].GetIOAttribute();
     Sizes       = Meta.GetSize().RepeatAggregated(Rank, NextRankSize).Reverse().ToArray();
     Offsets     = Sizes.Select((size, rank) => Sizes[rank].Scale(1 - (rank & 1), rank & 1)).ToArray();
     if (!string.IsNullOrEmpty(Meta?.SheetName) && FieldInfo.GetCustomAttribute <IOPlacementAttribute>() != null)
     {
         throw new Exception($"Remove IOPlacement attribute from a field {FieldInfo.Name}. " +
                             $"Instances of type {Types[Rank].Name} can't be arranged, because they are placed on separate sheets.");
     }
 }
Beispiel #3
0
 public static IEnumerable <SelectListItem> SizesToSelectListItems()
 {
     return(Sizes.Select(x => new SelectListItem(x.Name, x.Id.ToString())));
 }
Beispiel #4
0
 public override string ToString()
 {
     return(string.Format("TLPhoto Sizes=[{0}]", string.Join(", ", Sizes.Select(x => x.ToString()))));
 }
        public void Apply(IUnitOfWork db,
                          IQuantityManager quantityManager,
                          ILogService log,
                          ICacheService cache,
                          ISystemActionService actionService,
                          DateTime when,
                          long?by)
        {
            log.Info("AddSealedBoxWizardViewModel.Apply, StyleId=" + StyleId);

            if (IncomeType == (int)BoxIncomePackType.PPK)
            {
                var box = new SealedBoxViewModel();
                box.StyleId     = StyleId;
                box.BoxBarcode  = BoxBarcode;
                box.BoxQuantity = BoxQuantity;
                box.Price       = Price ?? 0;

                box.Owned    = Owned;
                box.PolyBags = false;
                box.Printed  = Printed;

                box.CreateDate = CreateDate.HasValue ? DateHelper.ConvertUtcToApp(CreateDate.Value.ToUniversalTime()) : when;

                box.StyleItems = new StyleItemCollection()
                {
                    Items = Sizes.Select(s => new StyleItemViewModel()
                    {
                        Id        = s.Id,
                        Breakdown = s.Breakdown,
                    }).ToList()
                };

                box.Apply(db, quantityManager, when, by);
            }

            if (IncomeType == (int)BoxIncomePackType.PolyBagged)
            {
                foreach (var size in Sizes.Where(si => si.Quantity > 0))
                {
                    var box = new SealedBoxViewModel();
                    box.StyleId     = StyleId;
                    box.BoxBarcode  = BoxBarcode;
                    box.BoxQuantity = size.Quantity ?? 0;
                    box.Price       = Price ?? 0;

                    box.Owned    = Owned;
                    box.PolyBags = true;
                    box.Printed  = Printed;

                    box.CreateDate = CreateDate.HasValue ? DateHelper.ConvertUtcToApp(CreateDate.Value.ToUniversalTime()) : when;

                    box.StyleItems = new StyleItemCollection()
                    {
                        Items = new List <StyleItemViewModel>()
                        {
                            new StyleItemViewModel()
                            {
                                Id        = size.Id,
                                Breakdown = UnitsPerBox
                            }
                        }
                    };

                    box.Apply(db, quantityManager, when, by);
                }
            }

            if (IncomeType == (int)BoxIncomePackType.Other)
            {
                var box = new OpenBoxViewModel();
                box.StyleId     = StyleId;
                box.BoxBarcode  = BoxBarcode;
                box.BoxQuantity = 1;
                box.Price       = Price ?? 0;

                box.Owned    = Owned;
                box.PolyBags = false;
                box.Printed  = Printed;

                box.CreateDate = CreateDate.HasValue ? DateHelper.ConvertUtcToApp(CreateDate.Value.ToUniversalTime()) : when;

                box.StyleItems = new StyleItemCollection()
                {
                    Items = Sizes.Select(s => new StyleItemViewModel()
                    {
                        Id       = s.Id,
                        Quantity = s.Quantity,
                    }).ToList()
                };

                box.Apply(db, quantityManager, when, by);
            }

            foreach (var size in Sizes)
            {
                var styleItem = db.StyleItems.Get(size.Id);
                if (size.UseBoxQuantity &&
                    styleItem.Quantity.HasValue)
                {
                    log.Info("Switch to box quantity, styleItemId=" + size.Id);

                    var oldQuantity = styleItem.Quantity;

                    styleItem.Quantity        = null;
                    styleItem.QuantitySetBy   = null;
                    styleItem.QuantitySetDate = null;
                    styleItem.RestockDate     = null;

                    db.Commit();

                    quantityManager.LogStyleItemQuantity(db,
                                                         styleItem.Id,
                                                         null,
                                                         oldQuantity,
                                                         QuantityChangeSourceType.UseBoxQuantity,
                                                         null,
                                                         null,
                                                         BoxBarcode,
                                                         when,
                                                         by);
                }
            }

            cache.RequestStyleIdUpdates(db,
                                        new List <long>()
            {
                StyleId
            },
                                        UpdateCacheMode.IncludeChild,
                                        by);

            SystemActionHelper.RequestQuantityDistribution(db, actionService, StyleId, by);
        }