private void AddLabel(DTO.LabelDTO label, DatabaseContext dbContext) { var dbLabel = dbContext.Labels .AsTracking() .AsEnumerable() .FirstOrDefault(l => (l.LabelId == label.Id || string.Equals(l.Name, label.Name, StringComparison.CurrentCultureIgnoreCase))); if (dbLabel == null) { throw new Exception($"Failed to find label with id {label.Id} or name '{label.Name}'."); } if (NoteLabels.Any(nl => nl.LabelId == dbLabel.LabelId)) { throw new Exception($"Duplicate labels found with name '{dbLabel.Name}'"); } NoteLabels.Add(new NoteLabel() { Note = this, Label = dbLabel }); }
public Label(DTO.LabelDTO label) { LabelId = label.Id; Name = label.Name; }