Пример #1
0
        public ActionResult UploadTempProjectIcon(HttpPostedFileBase file, int tempProjectId)
        {
            string error = "";

            _db = new ApplicationDbContext();
            var project = (from u in _db.TempProjects where u.TempProjectId == tempProjectId select u).First();

            var img = System.Drawing.Image.FromStream(file.InputStream, true, true);

            if (img.Width > 150 || img.Height > 150)
            {
                error = "Maksymalny rozmiar ikony to 150x150px.";
            }
            if (img.Width < 50 || img.Height < 50)
            {
                error = "Minimalny rozmiar ikony to 50x50px.";
            }

            file.InputStream.Seek(0, SeekOrigin.Begin);

            if (file.ContentLength > 0 && string.IsNullOrEmpty(error))
            {
                BlobConnector.UploadIcon(file, tempProjectId, false);
                project.IsIcon           = true;
                _db.Entry(project).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
            }
            else
            {
                error = "Błąd wgrywania pliku";
            }


            return(RedirectToAction("CreateTempProjectView2", new { TempProjectId = tempProjectId, error }));
        }