Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

emersonsoares commented Mar 10, 2016

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
You can’t perform that action at this time.