private void RemoveExistingSerieItems(Serie serie) { // Remove files from disk var removedItems = serie.SerieItems.Where(i => !SerieItems.Any(si => i.FileName == si.Filename)); // Remove from database if (removedItems.Any()) { _context.SerieItems.RemoveRange(removedItems); _context.SaveChanges(); } }
public void Handle(EditProjectCommand command) { var project = _context.Projects.First(p => p.Id == command.ProjectId); project.Name = command.Name; project.PublicationDate = command.PublicationDate; _context.SaveChanges(); }
public void Handle() { var project = new Project { Name = Name, UniqueName = Name.ReplaceSpaces(), PublicationDate = PublicationDate, Rank = 0, }; _context.Projects.Add(project); _context.SaveChanges(); }
public void Handle() { var rankCounter = 0; foreach (var projectId in ProjectIds) { var project = _context.Projects.First(p => p.Id == projectId); project.Rank = rankCounter; rankCounter++; } _context.SaveChanges(); }
private Serie CreateSerie(int?projectId) { var serie = new Serie { Created = DateTime.Now, Name = SerieName, UniqueName = SerieName.ReplaceSpaces(), Published = PublicationDate, ProjectId = projectId }; _context.Series.Add(serie); _context.SaveChanges(); return(serie); }
private Project CreateProject() { if (ProjectName.HasValue()) { var project = new Project { Name = ProjectName, }; _context.Projects.Add(project); _context.SaveChanges(); return(project); } return(null); }
public void SaveChanges() { try { _context.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); } } throw raise; } }
public void Save() { db.SaveChanges(); }