public async Task <IActionResult> Create([Bind("Id,Name,ImageFile")] MarcViewModel view) { if (ModelState.IsValid) { //Guardar a imagem var path = string.Empty; if (view.ImageFile != null && view.ImageFile.Length > 0) { path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\images\\Brands", view.ImageFile.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await view.ImageFile.CopyToAsync(stream); } path = $"~/images/Brands/{view.ImageFile.FileName}"; } var marc = this.ToMarc(view, path); //TODO: Change for the logged user on POST:->Create await this.marcaRepository.CreateAsync(marc); return(RedirectToAction(nameof(Index))); } return(View(view)); }
private Marca ToMarc(MarcViewModel view, string path) { return(new Marca { Id = view.Id, ImageUrl = path, Name = view.Name }); }