Ejemplo n.º 1
0
        public static IEnumerable <BuildingItem> SetCacheBuilding(Prepaid.Repositories.IRepository <string, Prepaid.Models.Building> buildingRepository,
                                                                  Prepaid.Repositories.IRoomRespository roomRepository)
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cachebuildings.txt");
            IEnumerable <Prepaid.Models.Building> Buildings = buildingRepository.GetAll();
            var items = from item in Buildings
                        select new BuildingItem
            {
                BuildingNo  = item.BuildingNo,
                Name        = item.Name,
                CommunityID = item.CommunityID,
                //CommunityName = item.Community.Name,
                Description = item.Description,
                Floors      = item.Floors,
                LstFloor    = GetFloors(roomRepository, item.BuildingNo, item.Floors),
                CreateTime  = item.CreateTime,
                Remark      = item.Remark
            };
            string text = JsonConvert.SerializeObject(items);

            using (StreamWriter writer = new StreamWriter(path))
                writer.Write(text);

            return(items);
        }
Ejemplo n.º 2
0
        public static IEnumerable <BuildingItem> GetCacheBuildings(Prepaid.Repositories.IRepository <string, Prepaid.Models.Building> buildingRepository,
                                                                   Prepaid.Repositories.IRoomRespository roomRepository)
        {
            IEnumerable <BuildingItem> items;
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "cachebuildings.txt");
            string text = string.Empty;

            if (!File.Exists(path))
            {
                items = SetCacheBuilding(buildingRepository, roomRepository);
            }
            else
            {
                using (StreamReader reader = new StreamReader(path))
                    text = reader.ReadToEnd();
                items = JsonConvert.DeserializeObject <IEnumerable <BuildingItem> >(text);
            }

            return(items);
        }