示例#1
0
        public DTO.ProductSize CreateProductSize(DataAccess.ProductSize productSize, bool includeOnlyActive = true)
        {
            CheckHelper.ArgumentNotNull(productSize, "productSize");
            CheckHelper.ArgumentWithinCondition(!productSize.IsNew(), "!productSize.IsNew()");

            return
                (_dtoCache.Get(
                     productSize,
                     ps =>
            {
                var result =
                    new DTO.ProductSize
                {
                    Id = ps.Id,
                    Price = ps.Price,
                    Active = ps.Active
                };

                CopyTrackableFields(result, ps);

                return result;
            },
                     (psDto, ps) =>
            {
                psDto.Size = CreateSize(ps.Size, includeOnlyActive);
                psDto.Product = CreateProduct(ps.Product, includeOnlyActive);
            }));
        }
        public static void Reset()
        {
            _boys_Sweater_0_3_Months  = null;
            _boys_Sweater_3_6_Months  = null;
            _girls_Sweater_0_3_Months = null;
            _girls_Sweater_3_6_Months = null;

            _productSizes = null;
        }
示例#3
0
        public void CreateProductSize(DTO.ProductSize createdProductSize)
        {
            CheckHelper.ArgumentNotNull(createdProductSize, "createdProductSize");
            CheckHelper.ArgumentWithinCondition(createdProductSize.IsNew(), "ProductSize is not new.");
            Container.Get <IValidateService>().CheckIsValid(createdProductSize);
            CheckHelper.ArgumentWithinCondition(!createdProductSize.Product.IsNew(), "Product of ProductSize is new.");
            CheckHelper.ArgumentWithinCondition(!createdProductSize.Size.IsNew(), "Size of ProductSize is new.");

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create product size.");

            var persistentService = Container.Get <IPersistentService>();

            var doesAnotherProductSizeWithTheSameProductAndSizeExist =
                persistentService
                .GetEntitySet <DataAccess.ProductSize>()
                .Any(ps =>
                     ps.ProductId == createdProductSize.Product.Id &&
                     ps.SizeId == createdProductSize.Size.Id);

            if (doesAnotherProductSizeWithTheSameProductAndSizeExist)
            {
                throw new ProductSizeServiceException("Размер товара с заданным размером уже существует для данного товара.");
            }

            var product = persistentService.GetEntityById <DataAccess.Product>(createdProductSize.Product.Id);

            CheckHelper.NotNull(product, "Product does not exist.");
            var size = persistentService.GetEntityById <DataAccess.Size>(createdProductSize.Size.Id);

            CheckHelper.NotNull(size, "Size does not exist.");

            CheckHelper.WithinCondition(product.SubCategoryId == size.SubCategoryId, "Товар и размер должны принадлежать одной подкатегории.");

            var productSize =
                new DataAccess.ProductSize
            {
                Active    = createdProductSize.Active,
                Price     = createdProductSize.Price,
                Product   = product,
                ProductId = product.Id,
                Size      = size,
                SizeId    = size.Id
            };

            productSize.UpdateTrackFields(Container);
            persistentService.Add(productSize);

            persistentService.SaveChanges();

            createdProductSize.Id         = productSize.Id;
            createdProductSize.CreateDate = productSize.CreateDate;
            createdProductSize.CreateUser = productSize.CreatedBy.GetFullName();
            createdProductSize.ChangeDate = productSize.ChangeDate;
            createdProductSize.ChangeUser = productSize.ChangedBy.GetFullName();
        }