public ActionResult Post([FromForm] InsertShow value) { var extension = Path.GetExtension(value.ShowPicturePath.FileName); if (!AllowedExtensions.Extensions.Contains(extension)) { return(UnprocessableEntity("Extension is not allowed!")); } try { var newPictureName = Guid.NewGuid().ToString() + "_" + value.ShowPicturePath.FileName; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", newPictureName); value.ShowPicturePath.CopyTo(new FileStream(filePath, FileMode.Create)); var show = new ShowDTO { ShowPicturePath = newPictureName, ShowTitle = value.ShowTitle, ShowText = value.ShowText, ShowYear = value.ShowYear, CategoryId = value.CategoryId }; addShowCommand.Execute(show); return(StatusCode(201)); } catch (Exception e) { return(StatusCode(500)); } }
public ActionResult Put(int id, [FromForm] InsertShow value) { if (value.ShowPicturePath != null) { var extension = Path.GetExtension(value.ShowPicturePath.FileName); if (!AllowedExtensions.Extensions.Contains(extension)) { return(UnprocessableEntity("Extension is not allowed!")); } try { var newPictureName = Guid.NewGuid().ToString() + "_" + value.ShowPicturePath.FileName; var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", newPictureName); value.ShowPicturePath.CopyTo(new FileStream(filePath, FileMode.Create)); var show = new ShowDTO { ShowPicturePath = newPictureName }; editShowCommand.Execute(show); return(NoContent()); } catch (Exception e) { return(StatusCode(500)); } } else { return(null); //?? } }