Example #1
0
        public ActionResult New([EntityBind(Fetch = false)] Category category)
        {
            Image image = null;

            Validator.Validate(ModelState, () =>
                               image = httpFileService.GetUploadedImages(Request, ImageDefinition.CategoryImage).SingleOrDefault());

            if (!ModelState.IsValid)
            {
                return(View("Edit", EditViewData.WithCategory(category)));
            }

            if (image != null)
            {
                category.Image = image;
            }

            categoryRepository.SaveOrUpdate(category);
            Message = "New category has been added.";

            return(this.RedirectToAction(c => c.Index()));
        }
Example #2
0
        public void ContributeTo(ProductBuildingContext context)
        {
            IEnumerable <Image> images = null;

            if (Validator.ValidateFails(context.ModelStateDictionary, () =>
                                        images = httpFileService.GetUploadedImages(context.HttpRequestBase, ImageDefinition.ProductImage, ImageDefinition.ProductThumbnail)
                                        ))
            {
                return;
            }

            var position = productOrderableService.NextPosition;

            foreach (var image in images)
            {
                context.Product.AddProductImage(image, position);
                position++;
            }
        }