public ActionResult UploadSolution(SimpleFileView simpleFileView)
        {
            if (!Directory.Exists(WebConstants.BasePath + WebConstants.RelativeSolutionsPath))
            {
                Directory.CreateDirectory(WebConstants.BasePath + WebConstants.RelativeSolutionsPath);
            }
            if (simpleFileView.UploadedFile == null)
            {
                ViewBag.Message = "Ошибка: Выберете файл для загрузки!";
                return(View(simpleFileView));
            }
            if (simpleFileView.UploadedFile.ContentLength > 7 * 512 * 1024) // 3.5 MB
            {
                ViewBag.Message = "Ошибка: Файл слишком большой! Максимальный размер 3.5 МБ. Попробуйте удалить все бинарные файлы из архива.";
                return(View(simpleFileView));
            }
            var path      = WebConstants.BasePath + WebConstants.RelativeSolutionsPath;
            var extention = simpleFileView.UploadedFile.FileName.Split('.').Last();

            if (extention != "zip")
            {
                ViewBag.Message = "Ошибка: вы должны предоставить архив с решением в формате *.zip";
                return(View(simpleFileView));
            }
            var expectedFileName = User.Identity.Name + "." + extention;

            simpleFileView.UploadedFile.SaveAs(path + expectedFileName);
            var context = new UnityContext();

            context.UserProfiles.First(u => u.UserName == User.Identity.Name).SolutionLoaded = WebConstants.GetCurrentTime();
            context.SaveChanges();
            ViewBag.Message = "Решение было загружено успешно!";
            return(View(simpleFileView));
        }
Exemple #2
0
        public ActionResult UploadImage(SimpleFileView fileView, int charId)
        {
            if (!IsAdmin())
            {
                return(RedirectToAction("Login", "Account"));
            }
            var basePath = AppDomain.CurrentDomain.BaseDirectory + @"Content\Images\";
            var fileName = fileView.UploadedFile.FileName;

            fileView.UploadedFile.SaveAs(basePath + fileName);
            db.Characters.First(c => c.Id == charId).ImageName = fileName;
            db.SaveChanges();
            return(RedirectToAction("UploadImage"));
        }
Exemple #3
0
 public ActionResult Index(SimpleFileView simpleFileView)
 {
     return(View(simpleFileView));
 }