<commit_before>﻿using System;
using System.Web.Mvc;
using NHibernate;
using WebApplication1.Code.Model;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        private readonly ISession _session;

        public HomeController(ISession session)
        {
            _session = session;
        }

        public ActionResult Index()
        {
            // This is how you're actually meant to modify data...

            using (var tx = _session.BeginTransaction())
            {
                var customer = _session.Get<Customer>(1);
                customer.Name = "NameGoesHere_" + Guid.NewGuid();

                tx.Commit();
            }

            // Notice how that's much less code.
            // Because we "got" the entity from the session, NHibernates change tracking knows about the
            // object and is tracking its state.
            // When the transaction is committed, everything is cleared out and saved down.

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
<commit_msg>Deliberately broken the transaction commit to show how you need to be careful when saving your data.<commit_after>﻿using System;
using System.Web.Mvc;
using NHibernate;
using WebApplication1.Code.Model;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        private readonly ISession _session;

        public HomeController(ISession session)
        {
            _session = session;
        }

        public ActionResult Index()
        {
            // There is a possible gotcha here though. Make sure you remember to commit your transaction...

            using (var tx = _session.BeginTransaction())
            {
                var customer = _session.Get<Customer>(1);
                customer.Name = "NameGoesHere_" + Guid.NewGuid();

                //tx.Commit();
            }

            // Notice how without that commit, your changes aren't saved.

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

{'fraction_non_alphanumeric': 0.07654209815398469, 'fraction_numerical': 0.0027014858171994596, 'mean_word_length': 1.8745148771021993, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2357939', 'n_tokens_mistral': 539, 'n_tokens_neox': 512, 'n_words': 181}