Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        public static void SaveOrUpdateOwnRelation(string aborigenId, int flatNumber)
        {
            lock (Locker)
            {
                FlatsProvider.VerifyFlatNumber(flatNumber);

                LoadRelations();

                OwnRelationModel ownRelationModel = ownRelations.FirstOrDefault(relation => relation.OwnerId == aborigenId);
                if (ownRelationModel != null)
                {
                    ownRelationModel.FlatNumber = flatNumber;
                }
                else
                {
                    ownRelations.Add(new OwnRelationModel {
                        FlatNumber = flatNumber, OwnerId = aborigenId
                    });
                }

                using (var context = new SimpleDbContext <OwnRelationModel>())
                {
                    context.Objects.RemoveRange(context.Objects);
                    context.Objects.AddRange(ownRelations);
                    context.SaveChanges();
                }
            }
        }