コード例 #1
0
        public ActionResult AddImages(RegisterViewModel viewModel)
        {
            if (viewModel.uploadImagesFormFile.Count != 0)
            {
                List <FilePath> imagesFilesPath = new List <FilePath>();
                foreach (var imageFormFile in viewModel.uploadImagesFormFile)
                {
                    var uniqueFileName = GetUniqueFileName(imageFormFile.FileName);
                    var uploads        = Path.Combine(hostingEnvironment.WebRootPath, "uploads");
                    var filePath       = Path.Combine(uploads, uniqueFileName);
                    imageFormFile.CopyTo(new FileStream(filePath, FileMode.Create));
                    FilePath newImageFile = new FilePath();
                    //newImageFile.Path = filePath;
                    newImageFile.Path = "~/uploads/" + uniqueFileName;
                    imagesFilesPath.Add(newImageFile);
                }
                int userId = _session.GetInt32("UserID").Value;
                _businessService.AddNewImages(userId, imagesFilesPath);

                //to do : Save uniqueFileName  to your db table
            }
            return(RedirectToAction("ViewProfile"));
        }