Beispiel #1
0
        public ActionResult Upload(HttpPostedFileBase imagefile, int CollectionID)
        {
            if (imagefile != null)
            {
                string strExtension = System.IO.Path.GetExtension(imagefile.FileName);

                if (strExtension.ToLower() == ".gif" || strExtension.ToLower() == ".jpg" || strExtension.ToLower() == ".jpeg" || strExtension.ToLower() == ".png")
                {
                    CollectionImage obj = new CollectionImage();
                    obj.CollectionID = CollectionID;
                    obj.ImageExt     = strExtension;
                    AddValuesOnCreate(obj);

                    service.Add(obj);
                    service.Save();

                    string strSaveFileName        = obj.ID + strExtension;
                    string strSaveFullPath        = System.IO.Path.Combine(Server.MapPath(Url.Content("~/Content")), Constants.COLLECTION_IMAGE_FOLDER, strSaveFileName);
                    string strSavePreviewFullPath = System.IO.Path.Combine(Server.MapPath(Url.Content("~/Content")), Constants.COLLECTION_IMAGE_FOLDER, Constants.COLLECTION_IMAGE_PREVIEW_FOLDER, strSaveFileName);

                    if (System.IO.File.Exists(strSaveFullPath))
                    {
                        System.IO.File.Delete(strSaveFullPath);
                    }
                    if (System.IO.File.Exists(strSavePreviewFullPath))
                    {
                        System.IO.File.Delete(strSavePreviewFullPath);
                    }

                    imagefile.ResizeAndSave(Constants.COLLECTION_IMAGE_HEIGHT, Constants.COLLECTION_IMAGE_WIDTH, strSaveFullPath);
                    imagefile.ResizeAndSave(Constants.COLLECTION_IMAGE_PREVIEW_HEIGHT, Constants.COLLECTION_IMAGE_PREVIEW_WIDTH, strSavePreviewFullPath);
                }
            }

            Collection coll = CollectionServiceFactory.Create().Get(CollectionID);

            return(RedirectToAction("GetCollectionInCategory", "Collection", new { category = coll.Category.ShortName, collection = coll.ShortName }));
        }
 public CollectionController() : this(CollectionServiceFactory.Create())
 {
 }