InsertImage() public method

public InsertImage ( int galleryId, int userId, string fileTitle, string fileExtension, string imageFormat, int length, byte image ) : int
galleryId int
userId int
fileTitle string
fileExtension string
imageFormat string
length int
image byte
return int
Beispiel #1
0
        public ActionResult Upload()
        {
            var db = new PhotoGalleryRepository();

            int id = Request.Url.Segments[3].AsInt();
            var numFiles = Request.Files.Count;
            int imageId = 0;

            for (int i = 0; i < numFiles; i++)
            {
                var file = Request.Files[i];
                if (file.ContentLength > 0)
                {
                    var fileUpload = new WebImage(file.InputStream);
                    var fileTitle = Path.GetFileNameWithoutExtension(file.FileName).Trim();
                    if (fileTitle.IsEmpty())
                    {
                        fileTitle = "Untitled";
                    }
                    var fileExtension = Path.GetExtension(file.FileName).Trim();
                    var fileBytes = fileUpload.GetBytes();

                    imageId = db.InsertImage(id, WebSecurity.CurrentUserId, fileTitle,
                        fileExtension, fileUpload.ImageFormat, fileBytes.Length, fileBytes);
                }
            }

            return RedirectToAction("View", "Photo", new { id = imageId });
        }