Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Created March 10, 2016 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleytonferrari/6dedf209bbeb48eec129 to your computer and use it in GitHub Desktop.
Save cleytonferrari/6dedf209bbeb48eec129 to your computer and use it in GitHub Desktop.
Exemplo de Raw direto na classe do Banner
using System;
using System.IO;
using System.Web;
namespace Eva.Dominio
{
public class Banner : Entidade
{
public Banner()
{
Ordem = DateTime.Now.Ticks.ToString();
Zona = new BannerZona();
}
public BannerZona Zona { get; set; }
public Anunciante Anunciante { get; set; }
public string Url { get; set; }
public bool Publicar { get; set; }
public DateTime DataInicial { get; set; }
public DateTime DataFinal { get; set; }
public string Arquivo { get; set; }
public string EmbeddedScript { get; set; }
public string Ordem { get; set; }
public int Views { get; set; }
public IHtmlString ToRaw()
{
var html = EmbeddedScript;
var path = VirtualPathUtility.ToAbsolute("~/Content/Uploads/Banner/" + Arquivo);
if (!string.IsNullOrEmpty(Arquivo))
{
if (Path.GetExtension(Arquivo).ToLower() == ".swf")
html = string.Format("<embed src = \"{0}\" type =\"application/x-shockwave-flash\" width = \"{1}\" height = \"{2}\">", path, Zona.Largura, Zona.Altura);
else
html = string.Format("<img src = \"{0}\" width = \"{1}\" height = \"{2}\">", path, Zona.Largura, Zona.Altura);
}
return new HtmlString(html);
}
}
}
@emersonsoares
Copy link

public class Banner : Entidade, IRawable
    {
        public Banner()
        {
            Ordem = DateTime.Now.Ticks.ToString();
            Zona = new BannerZona();
        }

        public BannerZona Zona { get; set; }
        public Anunciante Anunciante { get; set; }
        public string Url { get; set; }
        public bool Publicar { get; set; }
        public DateTime DataInicial { get; set; }
        public DateTime DataFinal { get; set; }
        public string Arquivo { get; set; }
        public string EmbeddedScript { get; set; }
        public string Ordem { get; set; }
        public int Views { get; set; }
    }

    public class RawService
    {
        private readonly VirtualPathUtility _vpUtility;

        public RawService(VirtualPathUtility vpUtility)
        {
            _vpUtility = vpUtility;
        }

        public IHtmlString TowRaw(IRawable rawable)
        {
            var html = rawable.EmbeddedScript;
            var path = _vpUtility.ToAbsolute("~/Content/Uploads/Banner/" + rawable.Arquivo);

            if (!string.IsNullOrEmpty(rawable.Arquivo))
            {
                if (Path.GetExtension(rawable.Arquivo).ToLower() == ".swf")
                    html = string.Format("<embed src = \"{0}\" type =\"application/x-shockwave-flash\" width = \"{1}\" height = \"{2}\">",
                        path, rawable.Zona.Largura, rawable.Zona.Altura);
                else
                    html = string.Format("<img src = \"{0}\" width = \"{1}\" height = \"{2}\">",
                        path, rawable.Zona.Largura, rawable.Zona.Altura);
            }

            return new HtmlString(html);
        }
    }

    public interface IRawable
    {
        string EmbeddedScript { get; set; }

        string Arquivo { get; set; }

        BannerZona Zona { get; set; }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment