<commit_before>using Microsoft.AspNetCore.Mvc;
using ADL.Models;
using System.Linq;
using QRCoder;
using System;

namespace ADL.Controllers
{
    public class LocationController : Controller
    {
        ILocationRepository repository;
        public LocationController(ILocationRepository repo)
        {
            repository = repo;
        }

        public ViewResult List() => View(repository.Locations);

        public ViewResult Edit(int locationId) =>
            View(repository.Locations
                .FirstOrDefault(l => l.LocationId == locationId));

        [HttpPost]
        public IActionResult Edit(Location location)
        {
            if (ModelState.IsValid) {
                repository.SaveLocation(location);
                TempData["message"] = $"{location.Title} blev gemt.";
                return RedirectToAction(nameof(List));
            } else {
                // there is something wrong with the data values
                return View(location);
            }
        }

        // Uses edit view, but gives it a new location as input
        public ViewResult Create() => View(nameof(Edit), new Location());

        [HttpPost]
        public IActionResult Delete(int locationId) {
            Location deletedLocation = repository.DeleteLocation(locationId);
            if (deletedLocation != null) {
                TempData["message"] = $"{deletedLocation.Title} blev slettet.";
            }
            return RedirectToAction(nameof(List));
        }

        public ViewResult GenerateQR(int locationID)
        {
            QRByteArraytoImageDataURL(PathtoQRByteArray(LocationIdtoPath(locationID)));
            return View();
        }

        private string LocationIdtoPath(int locationID)
        {
            /*Combine the locationID and the path into a single string*/
            string path = $"~/images/{locationID}";

            return path;
        }

        private Byte[] PathtoQRByteArray(string inputURL)
        {
            /*Create a QR CODE GENERATOR*/
            QRCodeGenerator qrGenerator = new QRCodeGenerator();

            /*Create an instance of the QRCodeData with the actual inputdata*/
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(inputURL, QRCodeGenerator.ECCLevel.Q);

            /*Combine the QRCode Generator and the data*/
            BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData);

            /*Get the actual image as a ByteArray*/
            byte[] qrByteArray = qrCode.GetGraphic(20);    

            return qrByteArray;
        }

        public string ByteArraytoURL(Byte[] qrCodeByteArray)
        {
            return "";
        }


        private string QRByteArraytoImageDataURL(Byte[] inputByteArray)
        {
            /*Convert the input array into into a string with the base of 64*/
            string imageBase64Data = Convert.ToBase64String(inputByteArray);

            /*creates a readable URL to the previou string through a url*/
            string imageDataURL = string.Format("data:image/png;base64,{0}", imageBase64Data);

            return imageDataURL;
        }

        
    }
}<commit_msg>fjernet lort fra locationcontroller<commit_after>using Microsoft.AspNetCore.Mvc;
using ADL.Models;
using System.Linq;
using QRCoder;
using System;

namespace ADL.Controllers
{
    public class LocationController : Controller
    {
        ILocationRepository repository;
        public LocationController(ILocationRepository repo)
        {
            repository = repo;
        }

        public ViewResult List() => View(repository.Locations);

        public ViewResult Edit(int locationId) =>
            View(repository.Locations
                .FirstOrDefault(l => l.LocationId == locationId));

        [HttpPost]
        public IActionResult Edit(Location location)
        {
            if (ModelState.IsValid) {
                repository.SaveLocation(location);
                TempData["message"] = $"{location.Title} blev gemt.";
                return RedirectToAction(nameof(List));
            } else {
                // there is something wrong with the data values
                return View(location);
            }
        }

        // Uses edit view, but gives it a new location as input
        public ViewResult Create() => View(nameof(Edit), new Location());

        [HttpPost]
        public IActionResult Delete(int locationId) {
            Location deletedLocation = repository.DeleteLocation(locationId);
            if (deletedLocation != null) {
                TempData["message"] = $"{deletedLocation.Title} blev slettet.";
            }
            return RedirectToAction(nameof(List));
        }

        public ViewResult GenerateQR(int locationID)
        {
            GenerateQR(locationID);
            return View(nameof(ViewQR));
        }

        private ViewResult ViewQR()
        {
            return View();
        }
    }
}
{'fraction_non_alphanumeric': 0.08492095662748277, 'fraction_numerical': 0.00263477908390758, 'mean_word_length': 1.9872881355932204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1209372', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1221, 'n_words': 321}