private string ProcessUploadAppAddressImage(AppAddressCreateViewModel model) { string uniqueFileName = null; if (model.AppPicture != null && model.AppPicture.Count > 0) { foreach (IFormFile photo in model.AppPicture) { 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); }
public async Task <IActionResult> CreateAppAddressData(AppAddressCreateViewModel model) { if (ModelState.IsValid) { string uniquePictureFileName = ProcessUploadAppAddressImage(model); var newAppAddress = new AppAddress { Address = model.Address, Picture = uniquePictureFileName, Phone = model.Phone, City = model.City, Description = model.Description, Email = model.Email }; await _addressRepository.AddAsync(newAppAddress); TempData["message"] = $"Address {model.Address} was created."; return(RedirectToAction("AddressList")); } return(View()); }