public async Task <Guid> AddCogitation(Guid recordId, string cogitationText) { if (string.IsNullOrWhiteSpace(cogitationText)) { throw new ArgumentException("Text should be passed for creating new cogitation"); } var placeholder = _appSettingsService.GetHostAndPortPlaceholder(); var currentHostAndPort = await _appSettingsService.GetHostAndPort(); bool isRecordExists = await _context.Records.AnyAsync(r => r.Id == recordId).ConfigureAwait(false); if (!isRecordExists) { throw new ArgumentException($"Record with Id='{recordId}' does not exists"); } var cogitation = new Cogitation { Id = Guid.NewGuid(), RecordId = recordId, Date = DateTime.UtcNow, Text = cogitationText.Replace(currentHostAndPort, placeholder, StringComparison.OrdinalIgnoreCase) }; await _context.Cogitations.AddAsync(cogitation).ConfigureAwait(false); await _context.SaveChangesAsync().ConfigureAwait(false); return(cogitation.Id); }
public async Task <ActionResult <Guid> > CreateScope(NewScopeDto newScopeDto) { try { var newScopeName = newScopeDto.NewScopeName.Trim(); var id = await _scopeService.AddScope(newScopeName); var newScopeUri = $@"{await _appSettingsService.GetHostAndPort()}/api/v1.0/scopes/{id}"; return(Created(newScopeUri, id)); } catch (ArgumentException exc) { return(BadRequest(exc.Message)); } }
public async Task <IActionResult> UploadImages([FromForm] UploadImageDto imageDto) { if (imageDto.Image == null) { return(BadRequest("Image file should be selected")); } if (imageDto.NewBiggestDimension < 100 || imageDto.NewBiggestDimension > 10000) { return(BadRequest("Dimension size should be between 100 and 10 000")); } try { var newImageId = await _imagesService.AddImage(imageDto.Image, imageDto.ImageName, imageDto.NewBiggestDimension); if (imageDto.TargetRecordId != null && imageDto.TargetRecordId != Guid.Empty) { await _recordsImagesService.AddRecordImage(imageDto.TargetRecordId.Value, newImageId); } var newImageUri = $@"{await _appSettingsService.GetHostAndPort()}/api/v1.0/images/{newImageId}"; return(Created(newImageUri, newImageId)); } catch (ArgumentException exc) { return(BadRequest(exc.Message)); } }
public async Task <List <DiaryRecord> > GetRecordsList(RecordsTextFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } if (string.IsNullOrWhiteSpace(filter.SearchText)) { return(Enumerable.Empty <DiaryRecord>().ToList()); } var list = (await SearchRecords(filter.SearchText).ConfigureAwait(false)) .OrderByDescending(r => r.Date) .Skip(filter.PageNo * filter.PageSize) .Take(filter.PageSize) .ToList(); var placeholder = _appSettingsService.GetHostAndPortPlaceholder(); var currentHostAndPort = await _appSettingsService.GetHostAndPort(); foreach (var rec in list) { rec.Text = rec.Text?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? ""; rec.Name = rec.Name?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? ""; foreach (var cog in rec.Cogitations) { cog.Text = cog.Text?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? ""; } } return(list); }
public async Task <List <DateListItem> > GetAllDates(DateOnly today) { var sId = (await _appSettingsService.GetAppSetting(AppSettingsKey.ImportantDaysScopeId)).value ?? throw new Exception("Setting 'ImportantDaysScopeId' does not exists"); var scopeId = Guid.Parse(sId); var placeholder = _appSettingsService.GetHostAndPortPlaceholder(); var currentHostAndPort = await _appSettingsService.GetHostAndPort(); var allRecordsIds = _context.Scopes .AsNoTracking() .Where(s => s.Id == scopeId) .SelectMany(s => s.Themes.SelectMany(t => t.RecordsRefs).Select(rr => rr.RecordId)) .AsEnumerable(); var records = await _context.Records .AsNoTracking() .Include(r => r.ThemesRefs) .ThenInclude(tr => tr.Theme) .Where(r => allRecordsIds.Contains(r.Id)) .ToListAsync() .ConfigureAwait(false); var items = records .Select(r => new DateListItem( r.Id, r.Date, new DateOnly(today.Year, r.Date.Month, r.Date.Day), string.IsNullOrWhiteSpace(r.Name) ? "[ПУСТО]" : r.Name.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase), r.Text?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? "", string.Join(", ", r.ThemesRefs.Select(tr => tr.Theme !.ThemeName)))) .OrderBy(r => r.TransferredDate) .ToList(); return(items); }
public async Task <List <DiaryRecord> > GetRecordsList(RecordsFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } var recordsPage = await FetchRecordsListFilteredQuery(filter) .OrderByDescending(r => r.Date) .Skip(filter.PageNo * filter.PageSize) .Take(filter.PageSize) .ToListAsync() .ConfigureAwait(false); var placeholder = _appSettingsService.GetHostAndPortPlaceholder(); var currentHostAndPort = await _appSettingsService.GetHostAndPort(); foreach (var rec in recordsPage) { rec.Text = rec.Text?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? ""; rec.Name = rec.Name?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? ""; foreach (var cog in rec.Cogitations) { cog.Text = cog.Text?.Replace(placeholder, currentHostAndPort, StringComparison.OrdinalIgnoreCase) ?? ""; } } return(recordsPage); }
public async Task <IActionResult> CreateRecord(CreateRecordDto createDto) { try { var recId = await _recordService.AddRecord(createDto.Date, createDto.RecordName, createDto.RecordText); if (createDto.ThemesIds.Length > 0) { await _recordsThemesService.AddRecordTheme(recId, createDto.ThemesIds); } var newRecordUri = $@"{await _appSettingsService.GetHostAndPort()}/api/v1.0/records/{recId}"; return(Created(newRecordUri, recId)); } catch (ArgumentException exc) { return(BadRequest(exc.Message)); } }
public async Task <List <CalendarItem> > GetCalendarItems(int year, IEnumerable <Guid> themesId, bool combineThemes) { var placeholder = _appSettingsService.GetHostAndPortPlaceholder(); var currentHostAndPort = await _appSettingsService.GetHostAndPort(); if (themesId is null || !themesId.Any()) { var records = await _context.Records .AsNoTracking() .Select(r => new CalendarItem( r.Id, string.IsNullOrWhiteSpace(r.Name) ? "[ПУСТО]" : r.Name.Replace(currentHostAndPort, placeholder, StringComparison.OrdinalIgnoreCase), r.Date, r.Date)) .ToListAsync() .ConfigureAwait(false); records = records .Where(r => r.StartDate.Year == year) .OrderBy(r => r.StartDate) .ToList(); return(records); }
public async Task OnGetAsync() { HostAndPort = await _settingsSvc.GetHostAndPort(); CurrentHostAndPort = Request.GetAppBaseUrl(); }