public List <BannerPrincipalEntity> ConsultaTodosBannerPrincipals()
        {
            List <BannerPrincipalEntity> lstBanners = new List <BannerPrincipalEntity>();

            using (var context = new CirculoNegocioEntities())
            {
                var ret = context.tbBannerPrincipals.Join(context.tbClientes, b => b.idCliente, c => c.id, (b, c) => new { b.id, b.idCliente, c.nome, b.Ativo, b.dataAte, b.dataDe, b.DataUltimaAlteracao, b.estado, b.imagemFilePath, b.responsavelUltimaAlteracao, b.Descricao, b.Rodape1, b.Rodape2 }).ToList();

                foreach (var item in ret)
                {
                    BannerPrincipalEntity obj = new BannerPrincipalEntity();

                    obj.id                         = item.id;
                    obj.Ativo                      = item.Ativo;
                    obj.dataAte                    = item.dataAte;
                    obj.dataDe                     = item.dataDe;
                    obj.estado                     = item.estado;
                    obj.idCliente                  = item.idCliente;
                    obj.nomeCliente                = item.nome;
                    obj.imagemFilePath             = item.imagemFilePath;
                    obj.Descricao                  = item.Descricao;
                    obj.Rodape1                    = item.Rodape1;
                    obj.Rodape2                    = item.Rodape2;
                    obj.responsavelUltimaAlteracao = item.responsavelUltimaAlteracao;
                    obj.DataUltimaAlteracao        = item.DataUltimaAlteracao;

                    lstBanners.Add(obj);
                }
            }

            return(lstBanners);
        }
        protected void btnIncluirBannerPrincipal_Click(object sender, EventArgs e)
        {
            BannerPrincipalEntity banner = new BannerPrincipalEntity();
            bool?ativo;

            banner.idCliente = Convert.ToInt32(ddlClienteBannerPrincipal.SelectedValue);
            ativo            = rdlAtivoBannerPrincipal.SelectedValue == "1" ? true : false;
            banner.Ativo     = ativo;
            banner.Descricao = txtDescricaoBannerPrincipal.Text;
            banner.Rodape1   = txtTextoRodape1BannerPrincial.Text;
            banner.Rodape2   = txtTextoRodape2BannerPrincial.Text;
            banner.dataAte   = Convert.ToDateTime(Convert.ToDateTime(txtDataHoraFinalBannerPrincipal.Text).ToString("s"));
            banner.dataDe    = Convert.ToDateTime(Convert.ToDateTime(txtDataHoraInicialBannerPrincipal.Text).ToString("s"));

            banner.dataAte = Convert.ToDateTime(Convert.ToDateTime(txtDataHoraFinalBannerPrincipal.Text).ToString("s"));
            banner.dataDe  = Convert.ToDateTime(Convert.ToDateTime(txtDataHoraInicialBannerPrincipal.Text).ToString("s"));

            banner.estado = ddlEstadoBannerPrincipal.SelectedValue;
            banner.responsavelUltimaAlteracao = Membership.GetUser().UserName;
            banner.DataUltimaAlteracao        = DateTime.Now;

            int idBanner = bannerPrincipalBusiness.InsereBannerPrincipal(banner);

            if (FileUpImagensBannerPrincipal.HasFile)
            {
                if (!Directory.Exists(Server.MapPath(@"~/BannerPrincipal/" + idBanner)))
                {
                    Directory.CreateDirectory(Server.MapPath(@"~/BannerPrincipal/" + idBanner));
                }

                string caminhoArquivo = Server.MapPath(@"~/BannerPrincipal/" + idBanner) + @"\" + FileUpImagensBannerPrincipal.FileName;
                FileUpImagensBannerPrincipal.SaveAs(caminhoArquivo);

                bannerPrincipalBusiness.AtualizaFilePathImagemBannerPrincipal(idBanner, caminhoArquivo);
            }
            else
            {
                bannerPrincipalBusiness.DeletaBannerPrincipal(idBanner);
                idBanner = 0;
                Alert("É obrigatório selecionar a imagem!");
            }

            if (idBanner != 0)
            {
                Alert("Banner principal incluido com sucesso!");
            }
            else
            {
                Alert("Ocorreu um erro ao incluir o Banner principal!");
            }

            CarregaGridView();
        }
        private tbBannerPrincipal CastBannerPrincipal(BannerPrincipalEntity banner)
        {
            tbBannerPrincipal tb = new tbBannerPrincipal();

            tb.Ativo     = banner.Ativo;
            tb.dataAte   = banner.dataAte;
            tb.dataDe    = banner.dataDe;
            tb.estado    = banner.estado;
            tb.idCliente = banner.idCliente;
            tb.responsavelUltimaAlteracao = banner.responsavelUltimaAlteracao;
            tb.DataUltimaAlteracao        = banner.DataUltimaAlteracao;
            tb.Descricao = banner.Descricao;
            tb.Rodape1   = banner.Rodape1;
            tb.Rodape2   = banner.Rodape2;

            return(tb);
        }
        public int InsereBannerPrincipal(BannerPrincipalEntity banner)
        {
            int idBannerPrincipal = 0;

            try
            {
                using (var context = new CirculoNegocioEntities())
                {
                    tbBannerPrincipal tb = CastBannerPrincipal(banner);
                    context.tbBannerPrincipals.AddObject(tb);
                    context.SaveChanges();

                    idBannerPrincipal = tb.id;
                }


                return(idBannerPrincipal);
            }
            catch (Exception)
            {
                return(0);
            }
        }
示例#5
0
 public int InsereBannerPrincipal(BannerPrincipalEntity banner)
 {
     return(lObjBannerPrincipalDAL.InsereBannerPrincipal(banner));
 }