예제 #1
0
        public bool Equals(SupplierViewModel other)
        {
            var equals = ((Sizes != null && other.Sizes != null) && Sizes.Count == other.Sizes.Count) || ((other.Sizes == null && Sizes == null));

            if (equals && Sizes != null && other.Sizes != null && Sizes.Where((t, i) => !t.Equals(other.Sizes[i])).Any())
            {
                equals = false;
            }
            return(Id == other.Id && Name == other.Name && AgreementDate == other.AgreementDate && Rank == other.Rank && equals);
        }
 public void DeleteImageSize(int id)
 {
     try
     {
         ImageSize size = Sizes.Where <ImageSize>(x => x.Id == id).First();
         ObservableCollection <ImageSize> imageSizes = Sizes;
         imageSizes.Remove(size);
         Sizes = imageSizes;
         OnPropertyChanged("Sizes");
     }
     catch
     {
     }
 }
        public bool Equals(TestViewModel other)
        {
            var sizes = true;

            if (Sizes != null && other.Sizes != null)
            {
                if (Sizes.Count == other.Sizes.Count)
                {
                    if (Sizes.Where((t, i) => !t.Equals(other.Sizes[i])).Any())
                    {
                        sizes = false;
                    }
                }
            }

            return(Id == other.Id && Name == other.Name && Age == other.Age && NotNullable == other.NotNullable && Nullable.GetValueOrDefault() == other.Nullable.GetValueOrDefault() && Weight == other.Weight && BoolValue == other.BoolValue && Gender == other.Gender && NullableGender == other.NullableGender && GenderIndex == other.GenderIndex && CaSeInSeNsItIvE == other.CaSeInSeNsItIvE &&
                   Created == other.Created && ((Country == null && other.Country == null) || Country.Equals(other.Country)) && sizes);
        }
        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);
        }
        public List <MessageString> Validate(IUnitOfWork db,
                                             ILogService log,
                                             DateTime when)
        {
            var messages = new List <MessageString>();

            if (IncomeType == (int)BoxIncomePackType.PPK)
            {
                var existBoxes = db.SealedBoxes.GetAllAsDto().Where(b => b.StyleId == StyleId &&
                                                                    b.BoxQuantity == BoxQuantity)
                                 .ToList();

                foreach (var existBox in existBoxes)
                {
                    var boxItems = db.SealedBoxItems.GetByBoxIdAsDto(existBox.Id);
                    var isEqual  = Sizes.Count(s => s.Breakdown > 0) == boxItems.Count;
                    foreach (var boxItem in boxItems)
                    {
                        var size = Sizes.FirstOrDefault(s => s.Id == boxItem.StyleItemId);
                        if (size == null || size.Breakdown != boxItem.BreakDown)
                        {
                            isEqual = false;
                        }
                    }

                    if (isEqual)
                    {
                        messages.Add(new MessageString()
                        {
                            Message = "A similar boxes already exist (created on " + DateHelper.ToDateString(existBox.CreateDate) + "). Are you sure you would like to create them?",
                            Status  = MessageStatus.Info,
                        });

                        return(messages);
                    }
                }
            }

            if (IncomeType == (int)BoxIncomePackType.PolyBagged)
            {
                foreach (var size in Sizes.Where(si => si.Quantity > 0))
                {
                    var totalQuantity = UnitsPerBox * size.Quantity;

                    var existBoxes = db.SealedBoxes.GetAllAsDto().Where(b => b.StyleId == StyleId &&
                                                                        b.BoxQuantity == size.Quantity)
                                     .ToList();

                    foreach (var existBox in existBoxes)
                    {
                        var boxItems           = db.SealedBoxItems.GetByBoxIdAsDto(existBox.Id);
                        var existTotalQuantity = boxItems.Sum(bi => bi.BreakDown) * existBox.BoxQuantity;
                        if (existTotalQuantity == totalQuantity && boxItems.Count == 1)
                        {
                            messages.Add(new MessageString()
                            {
                                Message = "A similar boxes already exist (created on " + DateHelper.ToDateString(existBox.CreateDate) + "). Are you sure you would like to create them?",
                                Status  = MessageStatus.Info,
                            });

                            return(messages);
                        }
                    }
                }
            }

            if (IncomeType == (int)BoxIncomePackType.Other)
            {
                var existBoxes = db.OpenBoxes.GetAllAsDto().Where(b => b.StyleId == StyleId &&
                                                                  b.BoxQuantity == 1)
                                 .ToList();

                foreach (var existBox in existBoxes)
                {
                    var boxItems = db.OpenBoxItems.GetByBoxIdAsDto(existBox.Id);

                    var isEqual = Sizes.Count(s => s.Quantity > 0) == boxItems.Count;
                    foreach (var boxItem in boxItems)
                    {
                        var size = Sizes.FirstOrDefault(s => s.Id == boxItem.StyleItemId);
                        if (size == null || size.Quantity != boxItem.Quantity)
                        {
                            isEqual = false;
                        }
                    }

                    if (isEqual)
                    {
                        messages.Add(new MessageString()
                        {
                            Message = "A similar box already exists (created on " +
                                      DateHelper.ToDateString(existBox.CreateDate) + "). Are you sure you would like to create one?",
                            Status = MessageStatus.Info,
                        });

                        return(messages);
                    }
                }
            }

            return(messages);
        }