Ejemplo n.º 1
0
 public void UpdateDocument(CreateModelDto document)
 {
     if (document.File != null)
     {
         UploadImageForArticle(document.Id, document.File, document.IsDiary);
     }
     if (document.IsDiary)
     {
         var entity = db.Diary.Where(c => c.Id == document.Id).AsQueryable().FirstOrDefault();
         if (entity != null)
         {
             entity.Name            = document.Name;
             entity.Body            = document.Body;
             entity.AlbumYear       = document.AlbumYear.Value;
             entity.CatalogueNumber = document.CatalogueNumber;
             entity.Genre           = document.Genre;
             entity.ReleaseYear     = document.ReleaseYear.Value;
             entity.Label           = document.Label;
             if (entity.IsPublished != document.IsPublished)
             {
                 entity.IsPublished = document.IsPublished;
                 entity.DateCreated = DateTime.Now;
             }
         }
         db.Entry(entity).State = EntityState.Modified;
     }
     else
     {
         var entity = db.Articles.Where(c => c.Id == document.Id).AsQueryable().FirstOrDefault();
         if (entity != null)
         {
             entity.Name             = document.Name;
             entity.Body             = document.Body;
             entity.Prelude          = document.Prelude;
             entity.DateEdited       = DateTime.Now;
             entity.CategoryId       = articleHelper.GetCategoryByName(document.CategoryId).Id;
             entity.SubCategoryId    = articleHelper.GetSubCategoryByName(document.SubCategoryId).Id;
             entity.Series           = articleHelper.GetSeriesByName(document.Series).Id;
             entity.IndexDescription = document.IndexDescription;
             if (entity.IsPublished != document.IsPublished)
             {
                 entity.IsPublished = document.IsPublished;
                 entity.DateCreated = DateTime.Now;
             }
         }
         db.Entry(entity).State = EntityState.Modified;
     }
     db.SaveChanges();
 }