Esempio n. 1
0
        public async Task <IActionResult> Insert(ImgManageViewModel imgManageViewModel)
        {
            if (!_session.ChkSession())
            {
                return(RedirectToAction("Login", "Auth"));
            }
            if (!ModelState.IsValid)
            {
                return(View(imgManageViewModel));
            }
            string filename  = Path.GetFileNameWithoutExtension(imgManageViewModel.formFile.FileName);
            string extension = Path.GetExtension(imgManageViewModel.formFile.FileName);

            filename = filename + DateTime.Now.ToString("yymmssfff") + extension;
            imgManageViewModel.img.path = "/img/" + filename;
            filename = Path.Combine(_host.WebRootPath + "/img/", filename);
            using (var fileStream = new FileStream(filename, FileMode.Create))
            {
                await imgManageViewModel.formFile.CopyToAsync(fileStream);
            }
            if (!_img.Insert(imgManageViewModel.img))
            {
                ModelState.AddModelError("", "Ошибка загрузки файла");
                return(View(imgManageViewModel));
            }
            return(RedirectToAction("List", new { msg = "Объект добавлен" }));
        }
Esempio n. 2
0
        public IActionResult Insert()
        {
            if (!_session.ChkSession())
            {
                return(RedirectToAction("Login", "Auth"));
            }
            var obj = new ImgManageViewModel
            {
                modelName = "Добавление изображения",
                btnName   = "Загрузить"
            };

            return(View(obj));
        }