コード例 #1
0
        /// <summary>
        /// Used to create new diary entries
        /// </summary>
        public async Task <DiaryEntryViewModel> CreateNewEntry(DiaryEntryCreateModel createModel)
        {
            var diaryEntry = new DiaryEntry()
            {
                EventAt     = createModel.EventAt,
                Description = createModel.Description,
                UserId      = _userBusinessService.CurrentUserId
            }.SetCreated <DiaryEntry>(_userBusinessService.CurrentUserName);

            await _databaseContext
            .Set <DiaryEntry>()
            .AddAsync(diaryEntry);

            var diaryImages = createModel.Images?.Select(x => new DiaryImage
            {
                ImageFileName = x.ImageFileName,
                ImageFile     = x.ImageFile,
                DiaryEntryId  = diaryEntry.Id
            }.SetCreated <DiaryImage>(_userBusinessService.CurrentUserName));

            if (diaryImages != null)
            {
                await _databaseContext
                .Set <DiaryImage>()
                .AddRangeAsync(diaryImages);
            }

            await _databaseContext.SaveChangesAsync();

            return(new DiaryEntryViewModel
            {
                Id = diaryEntry.Id,
                EventAt = diaryEntry.EventAt,
                Description = diaryEntry.Description,
                Images = diaryImages?.Select(x => new DiaryImageViewModel
                {
                    Id = x.Id,
                    ImageFileName = x.ImageFileName,
                    ImageFile = x.ImageFile
                })
            });
        }
コード例 #2
0
ファイル: DiaryController.cs プロジェクト: thnew/diary-app
 public async Task <DiaryEntryViewModel> CreateNewEntry(DiaryEntryCreateModel createModel)
 {
     return(await _diaryBusinessService.CreateNewEntry(createModel));
 }