Пример #1
0
        public ShoppingListItemReadModel(ItemId id, string name, bool isDeleted, string comment,
                                         bool isTemporary, float pricePerQuantity, QuantityTypeReadModel quantityType, float quantityInPacket,
                                         QuantityTypeInPacketReadModel quantityTypeInPacket,
                                         ItemCategoryReadModel itemCategory, ManufacturerReadModel manufacturer,
                                         bool isInBasket, float quantity)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new System.ArgumentException($"'{nameof(name)}' cannot be null or whitespace", nameof(name));
            }

            Id                   = id ?? throw new System.ArgumentNullException(nameof(id));
            Name                 = name;
            IsDeleted            = isDeleted;
            Comment              = comment;
            IsTemporary          = isTemporary;
            PricePerQuantity     = pricePerQuantity;
            QuantityType         = quantityType ?? throw new System.ArgumentNullException(nameof(quantityType));
            QuantityInPacket     = quantityInPacket;
            QuantityTypeInPacket = quantityTypeInPacket ?? throw new System.ArgumentNullException(nameof(quantityTypeInPacket));
            ItemCategory         = itemCategory;
            Manufacturer         = manufacturer;
            IsInBasket           = isInBasket;
            Quantity             = quantity;
        }
 public ItemSearchReadModel(ItemId id, string name, int defaultQuantity, float price,
                            ManufacturerReadModel manufacturer, ItemCategoryReadModel itemCategory,
                            StoreSectionReadModel defaultSection)
 {
     Id              = id;
     Name            = name;
     DefaultQuantity = defaultQuantity;
     Price           = price;
     Manufacturer    = manufacturer;
     ItemCategory    = itemCategory;
     DefaultSection  = defaultSection;
 }
            public IEnumerable <ItemSearchReadModel> ToSimpleReadModels(IEnumerable <IStoreItem> items,
                                                                        IStore store, Dictionary <ItemCategoryId, IItemCategory> itemCategories,
                                                                        Dictionary <ManufacturerId, IManufacturer> manufacturers)
            {
                foreach (IStoreItem item in items)
                {
                    ManufacturerReadModel manufacturerReadModel = null;
                    ItemCategoryReadModel itemCategoryReadModel = null;

                    if (item.ManufacturerId != null)
                    {
                        var manufacturer = manufacturers[item.ManufacturerId];

                        manufacturerReadModel = new ManufacturerReadModel(
                            manufacturer.Id,
                            manufacturer.Name,
                            manufacturer.IsDeleted);
                    }

                    if (item.ItemCategoryId != null)
                    {
                        var itemCategory = itemCategories[item.ItemCategoryId];

                        itemCategoryReadModel = new ItemCategoryReadModel(
                            itemCategory.Id,
                            itemCategory.Name,
                            itemCategory.IsDeleted);
                    }

                    var availability     = item.Availabilities.Single(av => av.StoreId == store.Id);
                    var section          = store.Sections.Single(s => s.Id == availability.DefaultSectionId);
                    var sectionReadModel = new StoreSectionReadModel(section.Id, section.Name,
                                                                     section.SortingIndex, section.IsDefaultSection);

                    yield return(new ItemSearchReadModel(
                                     item.Id,
                                     item.Name,
                                     item.QuantityType.GetAttribute <DefaultQuantityAttribute>().DefaultQuantity,
                                     availability.Price,
                                     manufacturerReadModel,
                                     itemCategoryReadModel,
                                     sectionReadModel));
                }
            }
        public StoreItemReadModel(ItemId id, string name, bool isDeleted, string comment, bool isTemporary,
                                  QuantityTypeReadModel quantityType, float quantityInPacket, QuantityTypeInPacketReadModel quantityTypeInPacket,
                                  ItemCategoryReadModel itemCategory, ManufacturerReadModel manufacturer,
                                  IEnumerable <StoreItemAvailabilityReadModel> availabilities)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new System.ArgumentException($"'{nameof(name)}' cannot be null or empty", nameof(name));
            }

            Id                   = id ?? throw new System.ArgumentNullException(nameof(id));
            Name                 = name;
            IsDeleted            = isDeleted;
            Comment              = comment;
            IsTemporary          = isTemporary;
            QuantityType         = quantityType ?? throw new System.ArgumentNullException(nameof(quantityType));
            QuantityInPacket     = quantityInPacket;
            QuantityTypeInPacket = quantityTypeInPacket ?? throw new System.ArgumentNullException(nameof(quantityTypeInPacket));
            ItemCategory         = itemCategory;
            Manufacturer         = manufacturer;
            this.availabilities  = availabilities ?? throw new System.ArgumentNullException(nameof(availabilities));
        }