public ActionResult <CurtidasModel> CurteItem(string id, int posicao) { // Obtém um top que possua o id indicado var top = _db.Top .Include(top => top.Item) // ver *** .SingleOrDefault(top => top.Id == id); if (top == null) { // 400 BAD REQUEST return(BadRequest()); } // Busca pelo item da posição indicada var item = top.Item.SingleOrDefault(item => item.Posicao == posicao); if (item == null) { // 400 BAD REQUEST return(BadRequest()); } // Acrescenta uma curtida ao item item.Curtidas += 1; _db.SaveChanges(); // Retorna o novo número de curtidas var retorno = new CurtidasModel { Curtidas = item.Curtidas }; // 200 OK return(Ok(retorno)); }
public ActionResult <CurtidasModel> CurteTop(string id) { // Obtém um top que possua o id indicado var top = _db.Top .Include(top => top.Item) // ver *** .SingleOrDefault(top => top.Id == id); if (top == null) { // 400 BAD REQUEST return(BadRequest()); } // Acrescenta uma curtida top.Curtidas += 1; _db.SaveChanges(); // Retorna o novo número de curtidas var retorno = new CurtidasModel { Curtidas = top.Curtidas }; // 200 OK return(Ok(retorno)); }