Exemplo n.º 1
0
        public ActionResult AddImage(HttpPostedFileBase imageFile,HandleImagesViewModel handleImg,int categoryId)
        {
            //Ingen bild vald, felmeddelande
            if (imageFile == null) return RedirectToAction("Images", new { id = categoryId });

            //TODO: Felmeddelande om filen inte är en bild
            if (IsImage(imageFile) == false) return RedirectToAction("Images", new { id = categoryId });

            Service.DTO.ImageModel imageModel = new Service.DTO.ImageModel();
            imageModel.Info = handleImg.NewImage.Info;
            imageModel.ImageData = new byte[imageFile.ContentLength];
            imageModel.ImageMimeType = imageFile.ContentType;
            imageFile.InputStream.Read(imageModel.ImageData, 0, imageFile.ContentLength);
            categoryService.AddImageToCategory(imageModel, categoryId);
            return RedirectToAction("Images",new {id=categoryId});
        }
Exemplo n.º 2
0
 //TODO:Rename action method, to categoryImages??
 //Handle images in a category
 //No point of loading ImageMimeType and ImageData
 public ActionResult Images(int id)
 {
     HandleImagesViewModel handleImages = new HandleImagesViewModel();
     handleImages.Images = (from img in categoryService.GetById(id).Images
                           select new Service.DTO.ImageModel() { Id = img.Id, Info = img.Info }).ToList();
     handleImages.CategoryId = id;
     ViewBag.catId = id;
     return View(handleImages);
 }