public ActionResult Save(SubmissionModel submissionModel, UploadFileModel [] images)
        {
            List<IImage> submissionImages = new List<IImage>();
            int imageCounter = 0;
            foreach (var image in images)
            {
                ImageModel submissionImage = new ImageModel();
                submissionImage.ImageMimeType = image.File.ContentType;
                Image img = Image.FromStream(image.File.InputStream);

                string localImgPath = ControllerContext.HttpContext.Server.MapPath(string.Format("{0}{1}{2}{3}{4}",
                                                                                             _imagePath,
                                                                                             CurrentAccount.AccountID,
                                                                                             CurrentContest.ContestID,
                                                                                             imageCounter,
                                                                                             ".jpg"));
                string imgPath = string.Format("{0}{1}{2}{3}{4}",
                                                _imagePath,
                                                CurrentAccount.AccountID,
                                                CurrentContest.ContestID,
                                                imageCounter,
                                                ".jpg");

                string localImgThumbnailPath = ControllerContext.HttpContext.Server.MapPath(string.Format("{0}{1}{2}{3}{4}",
                                                                                                    _imageThumbnailPath,
                                                                                                    CurrentAccount.AccountID,
                                                                                                    CurrentContest.ContestID,
                                                                                                    imageCounter,
                                                                                                    ".jpg"));
                string imgThumbnailPath = string.Format("{0}{1}{2}{3}{4}",
                                                        _imageThumbnailPath,
                                                        CurrentAccount.AccountID,
                                                        CurrentContest.ContestID,
                                                        imageCounter,
                                                        ".jpg");

                //Resize
                ImageUtilities.SaveImage(localImgPath, new Bitmap(img), 85L);
                submissionImage.ImageLocation = imgPath;

                //Resize to thumbnail

                Image imgThumbnail = img.GetThumbnailImage(210, 180,null,IntPtr.Zero);// ImageUtilities.ResizeImage(new Bitmap(img), new Size(210, 180));
                ImageUtilities.SaveImage(localImgThumbnailPath, new Bitmap(imgThumbnail), 85L);
                submissionImage.ImageThumbnailLocation = imgThumbnailPath;

                submissionImages.Add(submissionImage);
                imageCounter++;
            }

            submissionModel.SubmissionImages = submissionImages;
            submissionModel.SubmissionDate = DateTime.Now;
            submissionModel.AccountID = CurrentAccount.AccountID;
            submissionModel.ContestID = CurrentContest.ContestID;
            submissionModel.ApprovalDate = null;

            _accountService.AddSubmission(submissionModel);

            return View("Success");
        }
Esempio n. 2
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var files = controllerContext.HttpContext.Request.Files;
            var list = new List<UploadFileModel>();

            for (int i = 0; i < files.Count; i++)
            {
                var file = files[i];

                if(file.ContentLength == 0)
                    continue;

                var name = files.AllKeys[i];
                var fileInfo = new UploadFileModel(name, file);
                list.Add(fileInfo);
            }

            return list.ToArray();
        }