public static AborigenDecoratorViewModel GetFlatOwner(int flatNumber) { lock (Locker) { FlatsProvider.VerifyFlatNumber(flatNumber); LoadRelations(); //FlatViewModel flat = FloorsProvider.FindFlatByNumber(flatNumber); OwnRelationModel ownRelationModel = ownRelations.FirstOrDefault(relation => relation.FlatNumber == flatNumber); if (ownRelationModel == null) { return(AborigenDecoratorViewModel.CreateEmptyFake()); } AborigenModel ownerModel = AborigensProvider.GetAborigen(ownRelationModel.OwnerId); if (ownerModel == null) { return(AborigenDecoratorViewModel.CreateEmptyFake()); } return(AborigenDecoratorViewModel.Create(ownerModel)); } }
public static void SaveOrUpdateAborigen(AborigenModel aborigen) { lock (Locker) { using (var context = new SimpleDbContext <AborigenModel>()) { var existingAborigen = context.Objects.FirstOrDefault(abo => abo.Id == aborigen.Id); if (existingAborigen != null) { existingAborigen.AcceptProps(aborigen); } else { context.Objects.Add(aborigen); } context.SaveChanges(); var cachedAborigen = aborigens.FirstOrDefault(abo => abo.Id == aborigen.Id); if (cachedAborigen != null) { cachedAborigen.AcceptProps(aborigen); EventAborigenChanged(aborigen); } else { aborigens.Add(aborigen); EventAborigenAdded(aborigen); } } } }
private void AborigensProvider_OnAborigenAdded(AborigenModel aborigen) { DispatcherHelper.InvokeOnDispatcher(() => { // aborigenDecorators.Add(AborigenDecoratorViewModel.Create(aborigen.Clone())); }); }
public static void AcceptProps(this AborigenModel aborigen, AborigenModel other) { aborigen.Gender = other.Gender; aborigen.Email = other.Email; aborigen.Name = other.Name; aborigen.Otchestvo = other.Otchestvo; aborigen.PhoneNumber = other.PhoneNumber; aborigen.Surname = other.Surname; }
public AborigenDecoratorViewModel GetOrCreateSingle(AborigenModel model) { var existingDecor = aborigens.FirstOrDefault(decorator => decorator.AborigenReadOnly.GetId() == model.Id); if (existingDecor == null) { existingDecor = AborigenDecoratorViewModel.Create(model); aborigens.Add(existingDecor); } return(existingDecor); }
public static AborigenModel Clone(this AborigenModel aborigen) { return(new AborigenModel { Id = aborigen.Id, Gender = aborigen.Gender, Email = aborigen.Email, Name = aborigen.Name, Otchestvo = aborigen.Otchestvo, PhoneNumber = aborigen.PhoneNumber, Surname = aborigen.Surname }); }
public static AborigenModel MakeFake(this AborigenModel model) { if (model == null) { return(new AborigenModel { Surname = fakeSurname, PhoneNumber = fakePhone }); } model.Surname = fakeSurname; model.PhoneNumber = fakePhone; return(model); }
public AborigenViewModel(AborigenModel originalModel, bool isReadonly) { IsReadonly = isReadonly; originalModelId = originalModel.Id; CommandSave = new DelegateCommand(SaveImpl, CanSave); ForceSkipReadonlyCheck = true; Name = originalModel.Name; Email = originalModel.Email; Surname = originalModel.Surname; Otchestvo = originalModel.Otchestvo; Gender = originalModel.Gender; PhoneNumber = originalModel.PhoneNumber; ForceSkipReadonlyCheck = false; LocalizedGender = (string)genderConverter.Convert(Gender, null, null, null); }
private static void _LoadAborigens() { var random = new Random(); for (int index = 0; index < 100; index++) { var aborigenModel = new AborigenModel { Email = "*****@*****.**", Name = $"Крутое имя {random.Next(0, 1000)}", Surname = $"Фамилия {random.Next(0, 1000)}", PhoneNumber = "666-666", Otchestvo = $"Отчество {random.Next(0, 1000)}", Gender = index % 2 == 0 ? GenderType.Man : GenderType.Woman }; aborigens.Add(aborigenModel); } }
public bool HasInCache(AborigenModel model) { var existingDecor = aborigens.FirstOrDefault(cached => cached.AborigenReadOnly.GetId() == model.Id); return(existingDecor != null); }