<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using electric_mouse.Data;
using electric_mouse.Models.HallViewModels;
using electric_mouse.Models.RouteItems;
using electric_mouse.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace electric_mouse.Controllers
{
    [Authorize(Roles= RoleHandler.Admin)]
    public class HallController : Controller
    {
        private ApplicationDbContext _dbContext;

        public HallController(ApplicationDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public IActionResult Create()
        {
            IQueryable<RouteHall> halls = _dbContext.RouteHalls.Include(s => s.Sections);
            HallCreateViewModel model = new HallCreateViewModel { Halls = halls.ToList() };
            return View(model);
        }

        [HttpPost]
        public async Task<IActionResult> Create(HallCreateViewModel model)
        {
            if (!string.IsNullOrEmpty(model.Name))
            {
                model.Type--;
                RouteHall hall = new RouteHall
                {
                    Name = model.Name,
                    Sections = new List<RouteSection>()
                };

                if (model.Type <= 0)
                {
                    hall.ExpectedType = model.Type;
                }
                _dbContext.RouteHalls.Add(hall);
                _dbContext.SaveChanges();
            }

            return RedirectToAction(nameof(Create), "Hall");
        }

        [HttpPost]
        public async Task<IActionResult> Delete(HallCreateViewModel model)
        {
            var hall = _dbContext.RouteHalls.Include(s => s.Sections).First(h => h.RouteHallID == model.ID);

            if (hall.Sections?.Count <= 0)<commit_msg>Fixed an error that caused the wrong expected hall information to be saved<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using electric_mouse.Data;
using electric_mouse.Models.HallViewModels;
using electric_mouse.Models.RouteItems;
using electric_mouse.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace electric_mouse.Controllers
{
    [Authorize(Roles= RoleHandler.Admin)]
    public class HallController : Controller
    {
        private ApplicationDbContext _dbContext;

        public HallController(ApplicationDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public IActionResult Create()
        {
            IQueryable<RouteHall> halls = _dbContext.RouteHalls.Include(s => s.Sections);
            HallCreateViewModel model = new HallCreateViewModel { Halls = halls.ToList() };
            return View(model);
        }

        [HttpPost]
        public async Task<IActionResult> Create(HallCreateViewModel model)
        {
            if (!string.IsNullOrEmpty(model.Name))
            {
                model.Type--;
                RouteHall hall = new RouteHall
                {
                    Name = model.Name,
                    Sections = new List<RouteSection>()
                };

                if (model.Type >= 0)
                {
                    hall.ExpectedType = model.Type;
                }
                _dbContext.RouteHalls.Add(hall);
                _dbContext.SaveChanges();
            }

            return RedirectToAction(nameof(Create), "Hall");
        }

        [HttpPost]
        public async Task<IActionResult> Delete(HallCreateViewModel model)
        {
            var hall = _dbContext.RouteHalls.Include(s => s.Sections).First(h => h.RouteHallID == model.ID);

            if (hall.Sections?.Count <= 0)
{'fraction_non_alphanumeric': 0.08691126723913609, 'fraction_numerical': 0.0010408534998698933, 'mean_word_length': 2.038735177865613, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, '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': '6338535', 'n_tokens_mistral': 1023, 'n_tokens_neox': 971, 'n_words': 203}