public Models.TbMemelation Salvar(Models.TbMemelation tb) { db.Add(tb); db.SaveChanges(); return(tb); }
public Models.TbMemelation AtualizarCurtidas(int id) { Models.TbMemelation atual = db.TbMemelation.First(x => x.IdMemelation == id); atual.QtdCurtidas = atual.QtdCurtidas + 1; db.SaveChanges(); return(atual); }
public void AdicionarCurtidas(int?id) { Models.TbMemelation meme = db.TbMemelation.FirstOrDefault(x => x.IdMemelation == id); meme.NrCurtidas = Convert.ToInt32(meme.NrCurtidas) + 1; db.SaveChanges(); }
public int curtidas(Models.TbMemelation curt) { curt.QtdCurtidas += 1; ctx.SaveChanges(); return(curt.QtdCurtidas); }
public List <Models.TbComentario> buscarcomentarios() { List <Models.TbMemelation> ctx = db.TbMemelation.ToList(); List <Models.TbComentario> ctx2 = db.TbComentario.ToList(); Models.TbMemelation lista2 = new Models.TbMemelation(); List <Models.TbComentario> lista = new List <Models.TbComentario>(); int id = 0; foreach (Models.TbComentario item in ctx2) { id = item.IdMeme; } foreach (Models.TbMemelation item in ctx) { if (item.IdMemelation == id) { lista2 = item; } } foreach (Models.TbComentario item in ctx2) { if (item.IdMeme == lista2.IdMemelation) { lista.Add(item); } } return(lista); }
public Models.TbMemelation deletar(int id) { Models.TbMemelation meme = data.consultarPorID(id); if (meme == null) { throw new ArgumentException("ID não existe"); } return(data.deletar(meme)); }
public int curtidas(int id) { Models.TbMemelation curt = data.consultarPorID(id); if (curt == null) { throw new ArgumentException("ID não existe"); } return(data.curtidas(curt)); }
public Models.Response.MemelationResponse inserir([FromForm] Models.Request.MemelationRequest reg) { Models.TbMemelation ctx = conversor.ReqParaTb(reg); ctx.ImgMeme = gerenciarfoto.gerarnomefoto(reg.imagem.FileName); verificar.verificar(ctx); gerenciarfoto.salvarfoto(ctx.ImgMeme, reg.imagem); Models.Response.MemelationResponse xx = conversor.TbParaRes(ctx); return(xx); }
public Models.TbMemelation ParaTabela(Models.Request.MemeRequest req) { Models.TbMemelation tb = new Models.TbMemelation(); tb.NmAutor = req.Autor; tb.DsCategoria = req.Categoria; tb.DsHashtags = req.Hashtags; tb.BtMaior = req.Maior; tb.DtInclusao = DateTime.Now; return(tb); }
public Models.TbMemelation ReqParaTb(Models.Request.MemelationRequest reg) { Models.TbMemelation ctx = new Models.TbMemelation(); ctx.NmAutor = reg.autor; ctx.DsCategoria = reg.categoria; ctx.DsHashtags = reg.hashtags; ctx.BtMaior = reg.maior; ctx.DtInclusao = reg.inclusao; return(ctx); }
public Models.TbMemelation deletar(Models.TbMemelation del) { ctx.TbMemelation.Remove(del); ctx.SaveChanges(); List <Models.TbComentario> coments = ctx.TbComentario.Where(x => x.IdMeme == del.IdMeme).ToList(); ctx.TbComentario.RemoveRange(coments); ctx.SaveChanges(); return(del); }
public Models.Response.MemeResponse ForResponse(Models.TbMemelation req) { return(new Models.Response.MemeResponse { maior = req.BtMaior, autor = req.NmAutor, categoria = req.DsCategoria, hashtags = req.DsHashtags, id = req.IdMeme, curtidas = req.QtdCurtidas, inclusao = req.DtInclusao, imagem = req.DsImagem }); }
public Models.Response.MemeResponse ParaResponse(Models.TbMemelation tb) { Models.Response.MemeResponse resp = new Models.Response.MemeResponse(); resp.ID = tb.IdMemelation; resp.Autor = tb.NmAutor; resp.Categoria = tb.DsCategoria; resp.Hashtags = tb.DsHashtags; resp.Maior = tb.BtMaior; resp.Imagem = tb.ImgMeme; resp.Inclusao = tb.DtInclusao; return(resp); }
public Models.Response.MemelationResponse TbParaRes(Models.TbMemelation reg) { Models.Response.MemelationResponse ctx = new Models.Response.MemelationResponse(); ctx.id = reg.IdMemelation; ctx.autor = reg.NmAutor; ctx.categoria = reg.DsCategoria; ctx.hashtags = reg.DsHashtags; ctx.maior = reg.BtMaior; ctx.imagem = reg.ImgMeme; ctx.inclusao = reg.DtInclusao; return(ctx); }
public Models.TbMemelation ResParaTb(Models.Response.MemelationResponse reg) { Models.TbMemelation ctx = new Models.TbMemelation(); ctx.IdMemelation = reg.id; ctx.NmAutor = reg.autor; ctx.DsCategoria = reg.categoria; ctx.DsHashtags = reg.hashtags; ctx.BtMaior = reg.maior; ctx.ImgMeme = reg.imagem; ctx.DtInclusao = reg.inclusao; return(ctx); }
public Models.TbMemelation Deletar(int id) { Models.TbMemelation tb = db.TbMemelation.FirstOrDefault(x => x.IdMemelation == id); if (tb != null) { db.TbMemelation.Remove(tb); db.SaveChanges(); } return(tb); }
public Models.TbMemelation alterar(int id, Models.TbMemelation ml) { Models.TbMemelation alt = this.consultarPorID(id); alt.NmAutor = ml.NmAutor; alt.BtMaior = ml.BtMaior; alt.DsCategoria = ml.DsCategoria; alt.DsHashtags = ml.DsHashtags; alt.DsImagem = ml.DsImagem; alt.DtInclusao = ml.DtInclusao; ctx.SaveChanges(); return(alt); }
public ActionResult <Models.Response.MemeResponse> alterar(int id, Models.Request.MemeAltResponse req) { try { Models.TbMemelation meme = conv.ForTableAlt(req); meme = buss.alterar(id, meme); return(conv.ForResponse(meme)); } catch (Exception ex) { return(new BadRequestObjectResult( new Models.Response.ErroResponse(400, ex.Message) )); } }
public ActionResult <Models.Response.MemeResponse> Alterar(int id, [FromForm] Models.Request.MemeRequest req) { try { Models.TbMemelation tb = conversor.ParaTabela(req); Models.TbMemelation novaTb = business.Alterar(id, tb); return(conversor.ParaResponse(novaTb)); } catch (Exception ex) { return(BadRequest( new Models.Response.ErroResponse(400, ex.Message) )); } }
public Models.Response.MemeComentarioResponse ForMemeComentario(Models.TbMemelation tb) { return(new Models.Response.MemeComentarioResponse { maior = tb.BtMaior, autor = tb.NmAutor, categoria = tb.DsCategoria, hashtags = tb.DsHashtags, id = tb.IdMeme, inclusao = tb.DtInclusao, curtidas = tb.QtdCurtidas, imagem = tb.DsImagem, comentarios = tb.TbComentario.Select(x => cont.ForResponse(x) ).ToList() }); }
public Models.TbMemelation alterar(int id, Models.TbMemelation alt) { if (string.IsNullOrEmpty(alt.NmAutor)) { throw new Exception("Nome é obrigatório."); } if (string.IsNullOrEmpty(alt.DsCategoria)) { throw new Exception("Categoria é obrigatório."); } if (string.IsNullOrEmpty(alt.DsHashtags)) { throw new Exception("Hashtag " + alt.DsHashtags + " é obrigatório."); } return(data.alterar(id, alt)); }
public Models.TbMemelation Salvar(Models.TbMemelation tb) { if (string.IsNullOrEmpty(tb.NmAutor)) { throw new Exception("Nome é obrigatório."); } if (string.IsNullOrEmpty(tb.DsCategoria)) { throw new Exception("Categoria é obrigatório."); } if (string.IsNullOrEmpty(tb.DsHashtags)) { throw new Exception("Hashtag é obrigatório."); } return(db.Salvar(tb)); }
public Models.TbMemelation inserir(Models.TbMemelation ml) { if (string.IsNullOrEmpty(ml.NmAutor)) { throw new Exception("Nome é obrigatório."); } if (string.IsNullOrEmpty(ml.DsCategoria)) { throw new Exception("Categoria é obrigatório."); } if (string.IsNullOrEmpty(ml.DsHashtags)) { throw new Exception("Hashtag " + ml.DsHashtags + " é obrigatório."); } return(data.inserir(ml)); }
public Models.TbMemelation Alterar(int id, Models.TbMemelation novaTb) { Models.TbMemelation tb = db.TbMemelation.FirstOrDefault(x => x.IdMemelation == id); if (tb != null) { tb.NmAutor = novaTb.NmAutor; tb.DsCategoria = novaTb.DsCategoria; tb.DsHashtags = novaTb.DsHashtags; tb.BtMaior = novaTb.BtMaior; tb.DtInclusao = novaTb.DtInclusao; db.SaveChanges(); } return(tb); }
public ActionResult <Models.Response.MemeResponse> alterar(int id, [FromForm] Models.Request.MemeRequest req) { try { Models.TbMemelation meme = conv.ForTable(req); meme.DsImagem = gerenciadorFoto.GerarNovoNome(req.imagem.FileName); meme = buss.alterar(id, meme); gerenciadorFoto.SalvarFoto(meme.DsImagem, req.imagem); return(conv.ForResponse(meme)); } catch (Exception ex) { return(new BadRequestObjectResult( new Models.Response.ErroResponse(400, ex.Message) )); } }
public Models.TbMemelation verificar(Models.TbMemelation reg) { if (string.IsNullOrEmpty(reg.NmAutor)) { throw new ArgumentException("nome obrigatorio"); } if (string.IsNullOrEmpty(reg.DsHashtags)) { throw new ArgumentException("hashtags obrigatorio"); } if (string.IsNullOrEmpty(reg.DsCategoria)) { throw new ArgumentException("categoria obrigatorio"); } Models.TbMemelation ctx = salvar.salvar(reg); return(ctx); }
public ActionResult <Models.Response.MemeResponse> Alterar(int id, [FromForm] Models.Request.MemeRequest req) { try { Models.TbMemelation tb = conversor.ParaTabela(req); tb.ImgMeme = gerenciadorFoto.GerarNovoNome(req.Imagem.FileName); Models.TbMemelation novaTb = business.Alterar(id, tb); gerenciadorFoto.SalvarFoto(novaTb.ImgMeme, req.Imagem); return(conversor.ParaResponse(novaTb)); } catch (Exception ex) { return(BadRequest( new Models.Response.ErroResponse(400, ex.Message) )); } }
public Models.TbMemelation Alterar(int id, Models.TbMemelation novaTb) { if (id <= 0) { throw new Exception("ID inválido"); } if (string.IsNullOrEmpty(novaTb.NmAutor)) { throw new Exception("Nome é obrigatório."); } if (string.IsNullOrEmpty(novaTb.DsCategoria)) { throw new Exception("Categoria é obrigatório."); } if (string.IsNullOrEmpty(novaTb.DsHashtags)) { throw new Exception("Hashtag é obrigatório."); } return(db.Alterar(id, novaTb)); }
public Models.Response.MemeResponse ParaCompletoResponse(Models.TbMemelation tb) { Models.Response.MemeResponse resp = new Models.Response.MemeResponse(); resp.ID = tb.IdMemelation; resp.Autor = tb.NmAutor; resp.Categoria = tb.DsCategoria; resp.Hashtags = tb.DsHashtags; resp.Maior = tb.BtMaior; resp.Imagem = tb.ImgMeme; resp.Inclusao = tb.DtInclusao; resp.Curtidas = tb.QtdCurtidas; resp.Comentarios = tb.TbComentario.Select(x => new Models.Response.ComentarioResponse() { Id = x.IdComentario, Texto = x.DsComentario, IdDoMeme = x.IdMemelation }).ToList(); return(resp); }
public Models.TbMemelation cadastrar(Models.TbMemelation ml) { ctx.TbMemelation.Add(ml); ctx.SaveChanges(); return(ml); }