public ChairEntity(IDataService dataService, IMessenger messanger, Model.Chair entity, long position) { DataService = dataService; Messenger = messanger; this.entity = entity; this.position = position; hasChanges = false; UpdateHasChanges(); }
private void Chairs_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (DataService?.DBContext?.ChairToSpecializations != null) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { Model.Chair chair = item as Model.Chair; if (chair != null) { Entity.Chairs.Add(chair); } } break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { Model.Chair chair = item as Model.Chair; if (chair != null) { Entity.Chairs.Remove(chair); } } break; case NotifyCollectionChangedAction.Replace: for (int index = 0; index < e.NewItems.Count; index++) { Model.Chair oldChair = e.OldItems[index] as Model.Chair; Model.Chair newChair = e.NewItems[index] as Model.Chair; Entity.Chairs.Remove(oldChair); Entity.Chairs.Add(newChair); } break; case NotifyCollectionChangedAction.Reset: Entity.Chairs.Clear(); break; } } SetInfoAboutModify(); UpdateHasChanges(); }
private void CreateEntity() { try { if (DataService?.DBContext?.Chairs != null && DataService?.DBContext.Faculties != null) { Model.Chair newEntity = DataService?.DBContext?.Chairs?.Create(); if (newEntity != null) { DataService?.DBContext?.Chairs?.Add(newEntity); Entity = newEntity; Active = true; Model.Faculty faculty = DataService.DBContext.Faculties.FirstOrDefault(); FacultyId = faculty?.Id ?? 0; UserModify = DataService?.UserName; DateTimeOffset now = DateTimeOffset.Now; Entity.Created = now; OnPropertyChanged(nameof(Created)); Entity.LastModify = now; OnPropertyChanged(nameof(LastModify)); } } } catch (EntityException e) { OnEntityException(e); } catch (DbEntityValidationException e) { OnDbEntityValidationException(e); } catch (DbUpdateException e) { OnDbUpdateException(e); } }
public ChairEntity(IDataService dataService, IMessenger messanger, Model.Chair entity) : this(dataService, messanger, entity, 0) { }
private void Chairs_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (DataService != null && DataService.DBContext != null && DataService.DBContext.ChairToSpecializations != null) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { Model.Chair chair = item as Model.Chair; if (chair != null) { ChairToSpecialization relation = DataService.DBContext.ChairToSpecializations.Create(); relation.Chair = chair; relation.ChairId = chair.Id; relation.Specialization = Entity; relation.SpecializationId = Entity.Id; relation.Active = true; DateTimeOffset now = DateTimeOffset.Now; relation.Created = now; relation.LastModify = now; relation.UserModify = DataService?.UserName; } } break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { Model.Chair chair = item as Model.Chair; if (chair != null) { ChairToSpecialization removedItem = Entity.ChairToSpecializations.FirstOrDefault(x => x.Chair == chair); if (removedItem != null) { Entity.ChairToSpecializations.Remove(removedItem); } } } break; case NotifyCollectionChangedAction.Replace: for (int index = 0; index < e.NewItems.Count; index++) { Model.Chair oldChair = e.OldItems[index] as Model.Chair; Model.Chair newChair = e.NewItems[index] as Model.Chair; if (oldChair != null && newChair != null) { ChairToSpecialization replacedItem = Entity.ChairToSpecializations.FirstOrDefault(x => x.Chair == oldChair); if (replacedItem != null) { replacedItem.Chair = newChair; replacedItem.ChairId = newChair.Id; replacedItem.LastModify = DateTimeOffset.Now; replacedItem.UserModify = DataService?.UserName; } } } break; case NotifyCollectionChangedAction.Reset: Entity.ChairToSpecializations.Clear(); break; } } UpdateHasChanges(); }