投稿のギャラリーを設定で削除すると、デバッグ時にnull nullを受け入れることがあるのに困っているのですが、ブレークポイントでnull値でない場合は退却します。エステ・コディゴ:
var postold = _postRepositorio.ObterPorId(postDto.Id);
if (postold.ImagemCapa != postDto.ImagemCapa && !String.IsNullOrEmpty(postDto.ImagemCapa) && !String.IsNullOrEmpty(postold.ImagemCapa))
{
if (
File.Exists(
System.Web.HttpContext.Current.Server.MapPath(
Path.Combine(ConfigurationManager.AppSettings["DiretorioImagem"], postDto.ImagemCapa))))
{
File.Delete(
System.Web.HttpContext.Current.Server.MapPath(
Path.Combine(ConfigurationManager.AppSettings["DiretorioImagem"], postold.ImagemCapa)));
}
}
var editPost = AutoMapper.Mapper.Map(postDto, postold);
editPost.CategoriaPost = _categoriaPostRepositorio.ObterPorId(postDto.CategoriaPost);
editPost.Galeria = postDto.Galeria == 0 ? null : _galeriaRepositorio.ObterPorId(postold.Id);
_postRepositorio.Editar(editPost);
_contexto.SaveChanges();
ギャラリーにnullを入れる場所はここにあります
editPost.Galeria = postDto.Galeria == 0? null: _galeriaRepositorio.ObterPorId (postold.Id);