Esempio n. 1
0
        public async Task <(bool, int)> TryAddTreadToBoardAsync(Tread tread, string boardName)
        {
            var board = await _context.Boards.FirstOrDefaultAsync(b => b.Name == boardName);

            if (board == null)
            {
                return(false, 0);
            }

            TreadEntity treadEntity = tread.ToEntity();

            treadEntity.Board          = board;
            treadEntity.TimeOfLastPost = treadEntity.Posts.First().Time;

            _context.Treads.Add(treadEntity);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred while saving changes in the TryAddTreadToBoardAsync method.");
                return(false, 0);
            }

            return(true, treadEntity.Id);
        }
Esempio n. 2
0
 private void LoadTread(TreadEntity tread)
 {
     _context.Entry(tread).Collection(t => t.Posts)
     .Query()
     .Include(p => p.Image)
     .OrderBy(p => p.Time)
     .Load();
 }
Esempio n. 3
0
 public static Tread ToModel(this TreadEntity tread)
 {
     return(new(tread.Id, tread.Posts?.Select(p => p.ToModel())?.ToList(), tread.BoardId));
 }