示例#1
0
文件: Product.cs 项目: adamm931/Shopy
        public void AddSize(SizeType sizeType)
        {
            if (Sizes.Any(size => size.Id == sizeType.Id))
            {
                return;
            }

            Sizes.Add(sizeType);
        }
示例#2
0
        public override T GetElement()
        {
            if (Sizes.Any(s => s != 1))
            {
                throw new InvalidOperationException("Data does not describe a single point.");
            }

            return(ElementAt(new int[Rank]));
        }
示例#3
0
        public string GetQueryString()
        {
            var @params = new Dictionary <string, object>();

            if (Brands != null && Brands.Any())
            {
                @params.Add("brands", string.Join(",", Brands));
            }

            if (Sizes != null && Sizes.Any())
            {
                @params.Add("sizes", string.Join(",", Sizes));
            }

            if (MinPrice.HasValue)
            {
                @params.Add("minPrice", MinPrice.Value);
            }

            if (MaxPrice.HasValue)
            {
                @params.Add("maxPrice", MaxPrice.Value);
            }

            if (PageIndex.HasValue && PageSize.HasValue)
            {
                @params.Add("pageIndex", PageIndex.Value);
                @params.Add("pageSize", PageSize.Value);
            }

            if (CategoryUid.HasValue)
            {
                @params.Add("categoryUid", CategoryUid.Value);
            }

            if ([email protected]())
            {
                return(string.Empty);
            }

            var query = string.Join(
                "&", @params.Select(kvp => $"{kvp.Key}={kvp.Value}"));

            return($"?{query}");
        }
        private void EditRatios()
        {
            var tmp = new SMLRatioEditor
            {
                RatiosGrid =
                {
                    ItemsSource = Sizes
                }
            };

            tmp.SubmitRatios += (s, e) =>
            {
                if (!Sizes.Any())
                {
                    return;
                }
                SaveSizeRatios();
            };
            tmp.Show();
        }
        private void EditRow()
        {
            var tmp = new SMLRowEditor
            {
                LayoutRoot =
                {
                    DataContext        = new SmlRowEditorViewModel
                    {
                        ColorCode    = ColorCode,
                        StyleCode    = StyleCode,
                        Description  = Description,
                        DeliveryDate = DeliveryDate,
                        SizeRange    = SizeRange,
                        Qty          = Qty,
                        SeasonCode   = SeasonCode,
                        BrandCode    = BrandCode,
                        //Seasons = new List<TblLkpSeason>(ParentObj.Seasons),
                        Brands         = new List <Brand>(ParentObj.Brands),
                        StatusList     = new List <GenericViewModel>(ParentObj.StatusList),
                        StatusSerial   = StatusSerial,
                        SelectedStatus = SelectedStatus
                    }
                }
            };

            tmp.InitiateCustomeEvents();
            tmp.Submit += (s, e) =>
            {
                var vm = (tmp.LayoutRoot.DataContext as SmlRowEditorViewModel);
                if (vm == null)
                {
                    return;
                }
                StyleCode      = vm.StyleCode;
                ColorCode      = vm.ColorCode;
                StyleCode      = vm.StyleCode;
                Description    = vm.Description;
                DeliveryDate   = vm.DeliveryDate;
                SizeRange      = vm.SizeRange;
                Qty            = vm.Qty;
                SeasonCode     = vm.SeasonCode;
                BrandCode      = vm.BrandCode;
                SelectedStatus = vm.SelectedStatus;
                if (!Sizes.Any())
                {
                    if (vm.SizeRangeWithSizes != null)
                    {
                        var sze = (from x in vm.SizeRangeWithSizes
                                   select x.SizeCode).Distinct()
                                  .Select(x => new SmlSizeDetails
                        {
                            ParentObject = this,
                            ParentSerial = Iserial,
                            SizeCode     = x
                        }).ToList();
                        foreach (var item in sze)
                        {
                            Sizes.Add(item);
                        }
                    }
                }

                // if (ObjStatus.IsNew)
                //Client.UpdateOrInsertTblSmlAsync(new tblSeasonalMasterList
                //    {
                //        BrandCode = BrandCode,
                //        ColorCode = ColorCode,
                //        CreationDate = DateTime.Now,
                //        DelivaryDate = DeliveryDate,
                //        Description = Description,
                //        SeasonCode = SeasonCode,
                //        SizeRange = SizeRange,
                //        StyleCode = StyleCode,
                //        Qty = Qty,
                //        StatusID = SelectedStatus.Iserial
                //    }, true, 0);
                //    else if (ObjStatus.IsSavedDBItem)
                //        Client.UpdateOrInsertTblSmlAsync(new tblSeasonalMasterList
                //        {
                //            Iserial = Iserial,
                //            BrandCode = BrandCode,
                //            ColorCode = ColorCode,
                //            CreationDate = CraetionDate,
                //            DelivaryDate = DeliveryDate,
                //            Description = Description,
                //            SeasonCode = SeasonCode,
                //            SizeRange = SizeRange,
                //            StyleCode = StyleCode,
                //            Qty = Qty,
                //            StatusID = SelectedStatus.Iserial
                //        }, false, 0);
                //};
                //tmp.Show();
            };
        }
示例#6
0
        public long Apply(IUnitOfWork db,
                          ICacheService cache,
                          IQuantityManager quantityManager,
                          IStyleHistoryService styleHistory,
                          ISystemActionService actionService,
                          DateTime when,
                          long?by)
        {
            var style = db.Styles.Get(StyleId);

            style.UpdateDate = when;
            style.UpdatedBy  = by;

            style.ReSaveDate = when;
            style.ReSaveBy   = by;

            StyleViewModel.UpdateLocations(db, styleHistory, StyleId, Locations, when, by);

            var wasAnyChanges = false;

            if (Sizes != null && Sizes.Any())
            {
                var styleItems      = db.StyleItems.GetFiltered(si => si.StyleId == StyleId).ToList();
                var styleItemCaches = db.StyleItemCaches.GetFiltered(si => si.StyleId == StyleId).ToList();

                foreach (var size in Sizes)  //Update quantity (marking when/by)
                {
                    //int? oldQuantity = null;
                    //int? newQuantity = null;
                    string tag        = null;
                    bool   wasChanged = false;

                    var styleItem      = styleItems.FirstOrDefault(si => si.Id == size.StyleItemId);
                    var styleItemCache = styleItemCaches.FirstOrDefault(sic => sic.Id == size.StyleItemId);

                    if (styleItem != null)
                    {
                        if (size.UseBoxQuantity)
                        {
                            if (styleItem.Quantity != null)
                            {
                                var oldQuantity = styleItem.Quantity;
                                var newQuantity = size.BoxQuantity;
                                tag = size.BoxQuantitySetDate.ToString();

                                styleItem.Quantity        = null;
                                styleItem.QuantitySetDate = null;
                                styleItem.QuantitySetBy   = null;
                                //styleItem.RestockDate = null;
                                wasChanged = true;

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

                        if (size.NewRestockDate.HasValue &&
                            styleItem.RestockDate != size.NewRestockDate)
                        {
                            styleHistory.AddRecord(styleItem.StyleId,
                                                   StyleHistoryHelper.RestockDateKey,
                                                   DateHelper.ToDateTimeString(styleItem.RestockDate),
                                                   StringHelper.JoinTwo("-", styleItem.Size, styleItem.Color),
                                                   DateHelper.ToDateTimeString(size.NewRestockDate),
                                                   styleItem.Id.ToString(),
                                                   by);

                            styleItem.RestockDate = size.NewRestockDate;
                            wasChanged            = true;
                        }

                        if (size.NewManuallyQuantity.HasValue)
                        {
                            var operationType = size.NewManuallyQuantity.Value < 0 ? QuantityOperationType.Lost : QuantityOperationType.AddManually;

                            var quantityOperation = new QuantityOperationDTO()
                            {
                                Type            = (int)operationType,
                                QuantityChanges = new List <QuantityChangeDTO>()
                                {
                                    new QuantityChangeDTO()
                                    {
                                        StyleId     = style.Id,
                                        StyleItemId = styleItem.Id,
                                        Quantity    = -1 * size.NewManuallyQuantity.Value,
                                        //NOTE: we need to change sign to opposite because we substract quantity operataions from inventory
                                    }
                                },
                                Comment = "From style quantity dialog",
                            };

                            quantityManager.AddQuantityOperation(db,
                                                                 quantityOperation,
                                                                 when,
                                                                 by);

                            //NOTE: Hot updating the cache (only for first few seconds to display the updates before recalculation)
                            if (styleItemCache != null)
                            {
                                styleItemCache.SpecialCaseQuantityFromDate += -1 * size.NewManuallyQuantity.Value;
                                styleItemCache.TotalSpecialCaseQuantity    += -1 * size.NewManuallyQuantity.Value;
                            }

                            wasChanged = true;
                        }

                        if (size.IsRemoveRestockDate == true)
                        {
                            styleItem.RestockDate = null;

                            wasChanged = true;
                        }

                        if (size.OnHold != styleItem.OnHold)
                        {
                            quantityManager.LogStyleItemQuantity(db,
                                                                 styleItem.Id,
                                                                 size.OnHold ? 0 : styleItem.Quantity,
                                                                 size.OnHold ? styleItem.Quantity : 0,
                                                                 QuantityChangeSourceType.OnHold,
                                                                 size.OnHold.ToString(),
                                                                 null,
                                                                 null,
                                                                 when,
                                                                 by);
                            styleItem.OnHold = size.OnHold;

                            wasChanged = true;
                        }
                    }

                    if (wasChanged)
                    {
                        db.Commit();
                        wasAnyChanges = true;
                    }
                }
            }

            //NOTE: always update cache
            cache.RequestStyleIdUpdates(db,
                                        new List <long>()
            {
                StyleId
            },
                                        UpdateCacheMode.IncludeChild,
                                        AccessManager.UserId);

            if (wasAnyChanges)
            {
                db.Commit();

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

            return(StyleId);
        }