private void OnTicketTagAdded(string obj) { var cachedTag = AppServices.MainDataContext.SelectedDepartment.TicketTagGroups.Single( x => x.Id == SelectedTicketTag.Id); Debug.Assert(cachedTag != null); var ctag = cachedTag.TicketTags.SingleOrDefault(x => x.Name.ToLower() == CustomTag.ToLower()); if (ctag == null && cachedTag.SaveFreeTags) { using (var workspace = WorkspaceFactory.Create()) { var tt = workspace.Single <TicketTagGroup>(x => x.Id == SelectedTicketTag.Id); Debug.Assert(tt != null); var tag = tt.TicketTags.SingleOrDefault(x => x.Name.ToLower() == CustomTag.ToLower()); if (tag == null) { tag = new TicketTag() { Name = CustomTag }; tt.TicketTags.Add(tag); workspace.Add(tag); workspace.CommitChanges(); } } } DataContext.SelectedTicket.UpdateTag(SelectedTicketTag, new TicketTag { Name = CustomTag }); CustomTag = string.Empty; InvokeTagUpdated(SelectedTicketTag); }