Beispiel #1
0
        public DTO.ProductSize[] GetProductSizes(DTO.Product product, string filter)
        {
            CheckHelper.ArgumentNotNull(product, "product");
            CheckHelper.ArgumentWithinCondition(!product.IsNew(), "!product.IsNew()");

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

            var query =
                Container
                .Get <IPersistentService>()
                .GetEntitySet <DataAccess.ProductSize>()
                .Where(ps => ps.ProductId == product.Id)
                .AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter))
            {
                query = query.Where(ps => ps.Size.Name.Contains(filter));
            }

            var dtoService = Container.Get <IDtoService>();

            return
                (query
                 .OrderBy(ps => ps.Size.Name)
                 .ToArray()
                 .Select(ps => dtoService.CreateProductSize(ps, false))
                 .ToArray());
        }
Beispiel #2
0
        public void CreateProduct(DTO.Product createdProduct)
        {
            CheckHelper.ArgumentNotNull(createdProduct, "createdProduct");
            CheckHelper.ArgumentWithinCondition(createdProduct.IsNew(), "Product is not new.");
            Container.Get<IValidateService>().CheckIsValid(createdProduct);
            CheckHelper.ArgumentWithinCondition(!createdProduct.SubCategory.IsNew(), "SubCategory of Product is new.");
            CheckHelper.ArgumentWithinCondition(!createdProduct.Brand.IsNew(), "Brand of Product is new.");

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

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

            var subCategory = persistentService.GetEntityById<SubCategory>(createdProduct.SubCategory.Id);
            CheckHelper.NotNull(subCategory, "SubCategory does not exist.");
            var brand = persistentService.GetEntityById<DataAccess.Brand>(createdProduct.Brand.Id);
            CheckHelper.NotNull(brand, "Brand does not exist.");

            var httpService = Container.Get<IHttpService>();

            var product =
                new DataAccess.Product
                {
                    Name = createdProduct.Name,
                    SubCategoryId = subCategory.Id,
                    SubCategory = subCategory,
                    BrandId = brand.Id,
                    Brand = brand,
                    Active = brand.Active,
                    Description = createdProduct.Description,
                    VendorShopURL = createdProduct.VendorShopURL,
                    FullPictureURL = httpService.GetRelativeURLFromAbsoluteURL(createdProduct.FullPictureURL),
                    PreviewPictureURL = httpService.GetRelativeURLFromAbsoluteURL(createdProduct.PreviewPictureURL)
                };
            product.UpdateTrackFields(Container);
            
            persistentService.Add(product);
            persistentService.SaveChanges();

            createdProduct.Id = product.Id;
            createdProduct.CreateDate = product.CreateDate;
            createdProduct.CreateUser = product.CreatedBy.GetFullName();
            createdProduct.ChangeDate = product.ChangeDate;
            createdProduct.ChangeUser = product.ChangedBy.GetFullName();
        }
Beispiel #3
0
        public void UpdateProduct(DTO.Product updatedProduct)
        {
            CheckHelper.ArgumentNotNull(updatedProduct, "updatedProduct");
            CheckHelper.ArgumentWithinCondition(!updatedProduct.IsNew(), "Product is new.");
            Container.Get<IValidateService>().CheckIsValid(updatedProduct);
            CheckHelper.ArgumentWithinCondition(!updatedProduct.SubCategory.IsNew(), "SubCategory of Product is new.");
            CheckHelper.ArgumentWithinCondition(!updatedProduct.Brand.IsNew(), "SubCategory of Product is new.");

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

            var persistentService = Container.Get<IPersistentService>();
            var product = persistentService.GetEntityById<DataAccess.Product>(updatedProduct.Id);
            CheckHelper.NotNull(product, "Product does not exist.");

            var subCategory = persistentService.GetEntityById<SubCategory>(updatedProduct.SubCategory.Id);
            CheckHelper.NotNull(subCategory, "SubCategory does not exist.");
            var brand = persistentService.GetEntityById<DataAccess.Brand>(updatedProduct.Brand.Id);
            CheckHelper.NotNull(brand, "Brand does not exist.");

            var httpService = Container.Get<IHttpService>();

            product.Name = updatedProduct.Name;
            product.Active = updatedProduct.Active;
            product.SubCategoryId = subCategory.Id;
            product.SubCategory = subCategory;
            product.BrandId = brand.Id;
            product.Brand = brand;
            product.Description = updatedProduct.Description;
            product.VendorShopURL = updatedProduct.VendorShopURL;
            product.FullPictureURL = httpService.GetRelativeURLFromAbsoluteURL(updatedProduct.FullPictureURL);
            product.PreviewPictureURL = httpService.GetRelativeURLFromAbsoluteURL(updatedProduct.PreviewPictureURL);

            product.UpdateTrackFields(Container);

            persistentService.SaveChanges();
        }