예제 #1
0
    public async Task <bool> CreateLinkAsync(LinkViewModel lvm,
                                             string userId,
                                             CancellationToken cancellationToken = default)
    {
        var certificate = await _certificateRepository.GetCertificateIncludeLinksAsync(lvm.CertificateId,
                                                                                       userId,
                                                                                       cancellationToken);

        if (certificate != null)
        {
            // Check the limit (maximum 5).
            if (certificate.Links.Count >= 5)
            {
                return(true);
            }

            await _linkRepository.CreateAsync(new Link(lvm.Url, lvm.CertificateId),
                                              cancellationToken);

            await _cacheService.SetItemAsync(lvm.CertificateId, userId);

            return(true);
        }

        return(false);
    }
    public async Task UpdateCertificateAsync(CertificateViewModel cvm,
                                             string userId,
                                             CancellationToken cancellationToken = default)
    {
        var certificate = new Certificate
                          (
            userId,
            cvm.Title,
            cvm.Path,
            cvm.Description,
            cvm.Stage,
            cvm.Date
                          ).SetId(cvm.Id);

        await _repository.UpdateAsync(certificate, cancellationToken);

        await _cacheService.SetItemAsync(certificate.Id, userId);

        _cacheService.SetList(userId);
    }