コード例 #1
0
ファイル: AddAzure.cs プロジェクト: UcheIgbokwe/Reactivities
            public async Task <Photo> Handle(Command request, CancellationToken cancellationToken)
            {
                var photoUploadResult = _photoAccessor.AddAzurePhoto(request.File);

                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                var photo = new Photo
                {
                    Id = photoUploadResult.ToString()
                };

                if (!user.Photos.Any(x => x.IsMain))
                {
                    photo.IsMain = true;
                }
                user.Photos.Add(photo);


                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(photo);
                }
                else
                {
                    throw new Exception("Problem saving changes");
                }
            }