public async Task <PaginatedResponseDto <ResourceDto> > GetAllAsync(ResourcePaginatedRequestDto request)
        {
            using (var uow = UowManager.Begin())
                using (UowManager.Current.OverrideCurrentLanguageCode(request.LanguageCode ?? Session.LanguageCode))
                {
                    var options = request.ResolveRepositoryGetAllProjectedOptions(ResourceDto.Projection);
                    var dtos    = await _resourceRepository.GetAllListAsync(
                        x =>
                        (!request.WithId.HasValue || (request.WithId.HasValue && request.WithId.Value == x.Id)) &&
                        (string.IsNullOrEmpty(request.WithKey) || (!string.IsNullOrEmpty(request.WithKey) && request.WithKey == x.Key)) &&
                        (!request.MustBePublic.HasValue || (request.MustBePublic.HasValue && request.MustBePublic == !x.ResourceGroup.IsPrivate))
                        , options
                        , out long total);

                    if (dtos is null)
                    {
                        throw new AppException();
                    }

                    return(new PaginatedResponseDto <ResourceDto>(dtos)
                    {
                        PageIndex = request.PageIndex,
                        PageSize = request.PageSize,
                        Total = total
                    });
                }
        }
示例#2
0
        public async Task <User> FindByUsernameAsync(string username)
        {
            using (var uow = UowManager.Begin())
            {
                UowManager.Current.DisableMayHaveTenantBaseFilter();
                UowManager.Current.DisableMustHaveTenantBaseFilter();

                return(await _userManager.FindByNameAsync(username));
            }
        }
示例#3
0
        public async Task <bool> ValidateCredentialsAsync(User user, string password)
        {
            using (var uow = UowManager.Begin())
            {
                UowManager.Current.DisableMayHaveTenantBaseFilter();
                UowManager.Current.DisableMustHaveTenantBaseFilter();

                return(await _userManager.CheckPasswordAsync(user, password));
            }
        }
示例#4
0
        public Task SignInAsync(User user, AuthenticationProperties properties, string authenticationMethod = null)
        {
            using (var uow = UowManager.Begin())
            {
                UowManager.Current.DisableMayHaveTenantBaseFilter();
                UowManager.Current.DisableMustHaveTenantBaseFilter();

                return(_signInManager.SignInAsync(user, properties, authenticationMethod));
            }
        }
示例#5
0
        public async Task <int> CreateArtwork(ArtworkCreateInputDto inputDto)
        {
            using (var uow = UowManager.Begin())
            {
                try
                {
                    var hasItem = inputDto.ItemIds != null && inputDto.ItemIds.Any();

                    List <ArtworkItem> items = new List <ArtworkItem>();
                    if (hasItem)
                    {
                        items = _artworkItems.GetList(i => inputDto.ItemIds.Contains(i.Id));
                        var notExistItems = inputDto.ItemIds.Except(items.Select(i => i.Id)).ToList();
                        if (notExistItems.Any())
                        {
                            throw new Exception($"these item are not exist: {string.Join(",", notExistItems.Select(i => $"[{i}]"))}");
                        }
                    }

                    var artworkCreateResult = await _artworks.InsertAsync(new Artwork
                    {
                        Name           = inputDto.Name,
                        Description    = inputDto.Description,
                        CoverImage     = inputDto.CoverImage,
                        CompletionTime = inputDto.CompletionTime,
                        OnTop          = inputDto.OnTop,
                    });

                    var id = artworkCreateResult.Id;

                    if (hasItem)
                    {
                        for (var i = 0; i < items.Count; i++)
                        {
                            var item = items[i];
                            item.ArtworkId = id;
                            item.Seq       = i;
                        }

                        await _artworkItems.UpdateAsync(items);
                    }

                    uow.Commit();
                    return(id);
                }
                catch (Exception ex)
                {
                    uow.Rollback();
                    throw new Exception("failed to save");
                }
            }
        }
示例#6
0
        public async Task <bool> ModifyArtwork(ArtworkModifyInputDto inputDto)
        {
            if (!TryGetEntityById <Artwork>(inputDto.Id, out var artwork))
            {
                throw new Exception("artwork not exist");
            }

            using (var uow = UowManager.Begin())
            {
                try
                {
                    artwork.Name           = inputDto.Name;
                    artwork.Description    = inputDto.Description;
                    artwork.CompletionTime = inputDto.CompletionTime;
                    artwork.OnTop          = inputDto.OnTop;
                    artwork.CoverImage     = inputDto.CoverImage;

                    await _artworks.UpdateAsync(artwork);

                    if (inputDto.ItemIds == null)
                    {
                        inputDto.ItemIds = new int[] { };
                    }

                    // delete old items
                    _artworkItems.Update(i => i.ArtworkId == inputDto.Id, i => i.ArtworkId = 0);
                    // add new items
                    var items = _artworkItems.GetList(i => inputDto.ItemIds.Contains(i.Id));
                    for (var i = 0; i < items.Count; i++)
                    {
                        var item = items[i];
                        item.ArtworkId = inputDto.Id;
                        item.Seq       = inputDto.ItemIds.ToList().IndexOf(item.Id);
                    }
                    await _artworkItems.UpdateAsync(items);

                    uow.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    uow.Rollback();
                    throw new Exception("failed to modify");
                }
            }
        }
示例#7
0
        public async Task <Dto.UserPictureDto> GetUserPictureAsync(int userId)
        {
            using (var uow = UowManager.Begin())
            {
                Dto.UserPictureDto result = null;

                var userPicture = await _userPictureRepository.GetByUserIdAsync(userId);

                if (userPicture != null)
                {
                    result = new Dto.UserPictureDto
                    {
                        MimeType = FileExtensions.GetImageMimeTypeFromImageFileExtension(userPicture.Extension),
                        Data     = userPicture.Data
                    };
                }

                return(result);
            }
        }
        public async Task <ResourceDto> GetAsync(ResourceRequestDto request)
        {
            using (var uow = UowManager.Begin())
                using (UowManager.Current.OverrideCurrentLanguageCode(request.LanguageCode ?? Session.LanguageCode))
                {
                    var dto = await _resourceRepository.FirstOrDefaultAsync(
                        x =>
                        (!request.WithId.HasValue || (request.WithId.HasValue && request.WithId.Value == x.Id)) &&
                        (string.IsNullOrEmpty(request.WithKey) || (!string.IsNullOrEmpty(request.WithKey) && request.WithKey == x.Key)) &&
                        (!request.MustBePublic.HasValue || (request.MustBePublic.HasValue && request.MustBePublic == !x.ResourceGroup.IsPrivate))
                        ,
                        new GetProjectedOptions <Resource, int, ResourceDto>
                    {
                        Projection = ResourceDto.Projection
                    });

                    if (dto is null)
                    {
                        throw new AppException();
                    }

                    return(dto);
                }
        }