public async Task WriteCahce(HttpRequest httpRequest) { // Create dictionaries for saving var cacheText = new Dictionary <string, object>(); var cachePhotos = new Dictionary <string, object>(); var language = httpRequest.Headers["Accept-Language"]; // Getting path for cahce saving var path = GetPathToTextCache(language); var photosCachePath = GetPathToPhotosCache(); var halls = await _hallsService.GetAllAsync(httpRequest); WriteHallsAsync(halls, cacheText, cachePhotos, language); foreach (var hall in halls) { var hallFromDB = await _hallsService.GetAsync(httpRequest, hall.Id); WriteHallAsync(hallFromDB, cacheText, cachePhotos, language); foreach (var stand in hallFromDB.Stands) { var standFromDB = await _standsService.GetAsync(httpRequest, hallFromDB.Id, stand.Id); WriteStandAsync(standFromDB, cacheText, cachePhotos, language); foreach (var exhibit in standFromDB.Exhibits) { var exhibitFromDB = await _exhibitsService.GetAsync(httpRequest, hallFromDB.Id, stand.Id, exhibit.Id); WriteExhibitAsync(exhibitFromDB, cacheText, cachePhotos, language); } } } var json = $"version:{GetVersion(path) + 1}{Environment.NewLine}"; json += JsonConvert.SerializeObject(cacheText, Formatting.Indented); using (TextWriter tw = new StreamWriter(path)) { tw.WriteLine(json); }; if (!_isPhotosSaved) { json = $"version:{GetVersion(photosCachePath) + 1}{Environment.NewLine}"; json += JsonConvert.SerializeObject(cachePhotos, Formatting.Indented); using (TextWriter tw = new StreamWriter(photosCachePath)) { tw.WriteLine(json); }; _isPhotosSaved = true; } }
public async Task <IActionResult> GetAsync(string id, int?hash) { id.ValidateId(); var hall = await _hallsService.GetAsync(Request, id); if (hall == null) { return(NotFound()); } if (hash != null) { if (_compareService.IsEquals(hash.GetValueOrDefault(), hall)) { return(NoContent()); } } return(Ok(hall)); }