コード例 #1
0
ファイル: RelationsProvider.cs プロジェクト: Laxale/TwinSovet
        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));
            }
        }
コード例 #2
0
        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);
                    }
                }
            }
        }
コード例 #3
0
 private void AborigensProvider_OnAborigenAdded(AborigenModel aborigen)
 {
     DispatcherHelper.InvokeOnDispatcher(() =>
     {
         //
         aborigenDecorators.Add(AborigenDecoratorViewModel.Create(aborigen.Clone()));
     });
 }
コード例 #4
0
ファイル: ModelExtensions.cs プロジェクト: Laxale/TwinSovet
 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;
 }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: ModelExtensions.cs プロジェクト: Laxale/TwinSovet
 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
     });
 }
コード例 #7
0
ファイル: ModelExtensions.cs プロジェクト: Laxale/TwinSovet
        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);
        }
コード例 #8
0
ファイル: AborigenViewModel.cs プロジェクト: Laxale/TwinSovet
        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);
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        public bool HasInCache(AborigenModel model)
        {
            var existingDecor = aborigens.FirstOrDefault(cached => cached.AborigenReadOnly.GetId() == model.Id);

            return(existingDecor != null);
        }