Exemplo n.º 1
0
        public IActionResult CreateSocialData(AppDataCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueSocialFileName = ProcessUploadAppSocialImage(model);

                AppSocialAddress newAppSocialAddress = new AppSocialAddress
                {
                    UrlAddress   = model.UrlAddress,
                    AppSocialImg = uniqueSocialFileName
                };

                _appRepository.Add(newAppSocialAddress);

                TempData["message"] = $"Address {model.UrlAddress} was created.";
                return(RedirectToAction("SocialList"));
            }
            return(View());
        }
Exemplo n.º 2
0
        private string ProcessUploadAppSocialImage(AppDataCreateViewModel model)
        {
            string uniqueFileName = null;

            if (model.AppSocialImgs != null && model.AppSocialImgs.Count > 0)
            {
                foreach (IFormFile photo in model.AppSocialImgs)
                {
                    var uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    var filePath = Path.Combine(uploadsFolder, uniqueFileName);

                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        photo.CopyTo(fileStream);
                    }
                }
            }

            return(uniqueFileName);
        }