Newer
Older
enum / Original.cs
@Derek Comartin Derek Comartin on 29 Jan 2024 1 KB Init
namespace Original;

public enum OfferingType
{
    Course,
    Ebook,
    Book,
    Offline,
    Template,
}

public sealed record Product(int Id, OfferingType Type);

public sealed class ProductHandler(ResourcesHelper resourcesHelper)
{
    public void Handle(Product product)
    {
        if (product.Type == OfferingType.Template ||
            product.Type == OfferingType.Ebook ||
            product.Type == OfferingType.Offline)
        {
            var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type);
            var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type);
        }

    }
}

public sealed class ResourcesHelper
{
    public string? GetDownloadUrl(OfferingType offeringType)
    {
        if (offeringType == OfferingType.Template ||
            offeringType == OfferingType.Ebook)
        {
            // some code to do this...
            return "TODO: get the download URL";
        }

        return null;
    }

    public string? GetDefaultDownloadFileName(OfferingType offeringType)
    {
        if (offeringType == OfferingType.Template ||
            offeringType == OfferingType.Ebook)
        {
            // some code to do this...
            return "TODO: get the file name";
        }

        return null;
    }
}

/*
public sealed record DownloadableResource(
    int Id,
    int ProductId,
    string DownloadUrl,
    string DefaultDownloadFilename);

public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper)
{
    public void DoStuff(Product product)
    {
        var downloadableResource = resourcesHelper.GetDownloadable(product.Id);
        // do stuff with downloadable resource
    }
}

public sealed class ResourcesHelper2
{
    public DownloadableResource? GetDownloadable(int productId)
    {
        // TODO: go fetch this...
        return null;
    }
}
*/