public async Task <IActionResult> Edit(string id, RecordEditInputModel recordEditInputModel) { if (!this.ModelState.IsValid) { var allGenres = await this.recordService.GetAllGenres().ToListAsync(); this.ViewData["types"] = allGenres.Select(genre => new GenreCreateViewModel { Name = genre.Name }) .ToList(); return(this.View(recordEditInputModel)); } string pictureUrl = await this.cloudinaryService.UploadPictureAsync(recordEditInputModel.Picture, recordEditInputModel.AlbumName); RecordServiceModel recordCreate = AutoMapper.Mapper.Map <RecordServiceModel>(recordEditInputModel); recordCreate.Picture = pictureUrl; await this.recordService.Edit(id, recordCreate); return(this.Redirect("/")); }
public async Task <IActionResult> Edit(string id) { RecordEditInputModel recordEditInputModel = (await this.recordService.GetById(id)).To <RecordEditInputModel>(); if (recordEditInputModel == null) { //error handlling return(this.Redirect("/")); } var allGenres = await this.recordService.GetAllGenres().ToListAsync(); this.ViewData["types"] = allGenres.Select(genre => new GenreCreateViewModel { Name = genre.Name }) .ToList(); return(this.View(recordEditInputModel)); }