<commit_before>﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Web.Http;
using Backend.Models;
using Microsoft.AspNet.Identity;

namespace Backend.Controllers
{
    public class VoteController : ApiController
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        [Route("api/Vote/Like/{mealId}")]
        [Authorize]
        [AcceptVerbs("POST")]
        public IHttpActionResult Like(int mealId) 
        {
            var currentUsersName = RequestContext.Principal.Identity.GetUserName();
            var currentUser = db.Users.First(x => x.Email == currentUsersName);
            var currentMeal = db.Meals.Find(mealId);
            
            IEnumerable<Vote> userVotes = db.MealVotes.Where(m => m.User.Email == currentUser.Email);
            if (userVotes.FirstOrDefault(n => n.Meal == currentMeal) == null)
            {
                Vote userVote = new Vote()
                {
                    Meal = currentMeal,
                    Likes = 1,
                    User = currentUser
                };

                currentMeal.Likes += 1;
                db.Meals.AddOrUpdate(currentMeal);
                db.MealVotes.Add(userVote);

                db.SaveChanges();
            }
            else
            {
                return Ok("Error: You cannot vote more than once.");
            }

            return Ok();
        }

        [Route("api/Vote/Dislike/{mealId}")]
        [Authorize]
        [AcceptVerbs("POST")]
        public IHttpActionResult Dislike(int mealId)
        {
            var currentUsersName = RequestContext.Principal.Identity.GetUserName();
            var currentUser = db.Users.First(x => x.Email == currentUsersName);
            var currentMeal = db.Meals.Find(mealId);

            IEnumerable<Vote> userVotes = db.MealVotes.Where(m => m.User.Email == currentUser.Email);
            if (userVotes.FirstOrDefault(n => n.Meal == currentMeal) == null)
            {
                Vote userVote = new Vote()
                {
                    Meal = db.Meals.Find(mealId),
                    Dislikes = 1,
                    User = currentUser
                };

                currentMeal.Dislikes += 1;
                db.Meals.AddOrUpdate(currentMeal);
                db.MealVotes.Add(userVote);
                db.SaveChanges();
            }
            else
            {
                return Ok("Error: You cannot vote more than once.");
            }
            return Ok();
        }


   }
}<commit_msg>added return values to votes<commit_after>﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Web.Http;
using Backend.Models;
using Microsoft.AspNet.Identity;

namespace Backend.Controllers
{
    public class VoteController : ApiController
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        [Route("api/Vote/Like/{mealId}")]
        [Authorize]
        [AcceptVerbs("POST")]
        public IHttpActionResult Like(int mealId) 
        {
            var currentUsersName = RequestContext.Principal.Identity.GetUserName();
            var currentUser = db.Users.First(x => x.Email == currentUsersName);
            var currentMeal = db.Meals.Find(mealId);
            
            IEnumerable<Vote> userVotes = db.MealVotes.Where(m => m.User.Email == currentUser.Email);
            if (userVotes.FirstOrDefault(n => n.Meal == currentMeal) == null)
            {
                Vote userVote = new Vote()
                {
                    Meal = currentMeal,
                    Likes = 1,
                    User = currentUser
                };

                currentMeal.Likes += 1;
                db.Meals.AddOrUpdate(currentMeal);
                db.MealVotes.Add(userVote);

                db.SaveChanges();
            }
            else
            {
                return Ok("You cannot vote more than once.");
            }

            return Ok(currentMeal.Likes);
        }

        [Route("api/Vote/Dislike/{mealId}")]
        [Authorize]
        [AcceptVerbs("POST")]
        public IHttpActionResult Dislike(int mealId)
        {
            var currentUsersName = RequestContext.Principal.Identity.GetUserName();
            var currentUser = db.Users.First(x => x.Email == currentUsersName);
            var currentMeal = db.Meals.Find(mealId);

            IEnumerable<Vote> userVotes = db.MealVotes.Where(m => m.User.Email == currentUser.Email);
            if (userVotes.FirstOrDefault(n => n.Meal == currentMeal) == null)
            {
                Vote userVote = new Vote()
                {
                    Meal = db.Meals.Find(mealId),
                    Dislikes = 1,
                    User = currentUser
                };

                currentMeal.Dislikes += 1;
                db.Meals.AddOrUpdate(currentMeal);
                db.MealVotes.Add(userVote);
                db.SaveChanges();
            }
            else
            {
                return Ok("You cannot vote more than once.");
            }
            return Ok(currentMeal.Dislikes);
        }


   }
}
{'fraction_non_alphanumeric': 0.10329507589781563, 'fraction_numerical': 0.00259163272861903, 'mean_word_length': 1.5888835649257307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '968255', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1456, 'n_words': 284}