<commit_before>﻿using System;
using System.Collections.Generic;

namespace Core
{
    public class CustomerRepository
    {
        private Dictionary<int, Customer> Customers = new Dictionary<int, Customer>();
        private Database DB = new Database();
        public List<Customer> GetCustomers()
        {
            // Convert Dictrionary to List (without having any KeyValuePairs)s
            List<Customer> CustomerList = new List<Customer>();
            CustomerList.AddRange(Customers.Values);

            return CustomerList;
        }
        public Customer GetCustomer(int ID)
        {
            return Customers[ID];
        }

        public void SaveCustomer(Customer Customer)
        {
            //this.Delete(Customer.ID);
            //this.Customers.Add(Customer.ID, Customer);
            Dictionary<string, string> param = new Dictionary<string, string>();
            Address addr = Customer.Address;
            param.Add("@Firstname", Customer.Firstname);
            param.Add("@Lastname", Customer.Lastname);
            param.Add("@Email", Customer.Email);
            param.Add("@Phone", Customer.Phone);
            param.Add("@HouseNo", addr.HouseNo.ToString());
            param.Add("@FloorNo", addr.FloorNo.ToString());
            param.Add("@Streetname", addr.Streetname);
            param.Add("@Entrance", addr.Entrance);
            param.Add("@City", addr.City);
            param.Add("@PostCode", addr.PostCode.ToString());

            DB.RunSP("usp_SaveCustomer", param);

        }

        public void Update(int id, string prop, string newvalue)
        {
            Customer Customer = this.GetCustomer(id);

            switch (prop)
            {
                case "Firstname": Customer.Firstname = newvalue; break;
                case "Lastname": Customer.Lastname = newvalue; break;
                case "Email": Customer.Email = newvalue; break;
                case "password": Customer.Password = newvalue; break;
                case "Phone": Customer.Phone = newvalue; break;
                default: throw new Exception("Invalid Property");
            }

            this.SaveCustomer(Customer);
        }

        public void Update(int id, string prop, Address newvalue)
        {
            if (prop != "Address") throw new Exception("Invalid Property");
            Customer Customer = this.GetCustomer(id);
            Customer.Address = newvalue;

            this.SaveCustomer(Customer);
        }

        public bool Delete(int id)
        {
            if (Customers.ContainsKey(id))
            {
                Customers.Remove(id);
                return true;
            }
            else { return false; }
        }
    }

}
<commit_msg>Fix for null value handling with save<commit_after>﻿using System;
using System.Collections.Generic;

namespace Core
{
    public class CustomerRepository
    {
        private Dictionary<int, Customer> Customers = new Dictionary<int, Customer>();
        private Database DB = new Database();
        public List<Customer> GetCustomers()
        {
            // Convert Dictrionary to List (without having any KeyValuePairs)s
            List<Customer> CustomerList = new List<Customer>();
            CustomerList.AddRange(Customers.Values);

            return CustomerList;
        }
        public Customer GetCustomer(int ID)
        {
            return Customers[ID];
        }

        public void SaveCustomer(Customer Customer)
        {
            //this.Delete(Customer.ID);
            //this.Customers.Add(Customer.ID, Customer);
            Dictionary<string, string> param = new Dictionary<string, string>();
            Address addr = Customer.Address;
            param.Add("@Firstname", Customer.Firstname);
            param.Add("@Lastname", Customer.Lastname);
            param.Add("@Email", Customer.Email);
            param.Add("@Phone", Customer.Phone);
            param.Add("@HouseNo", addr.HouseNo.ToString());
            param.Add("@FloorNo", addr.FloorNo.ToString());
            param.Add("@Streetname", addr.Streetname);
            param.Add("@Entrance", "" + addr.Entrance);
            param.Add("@City", addr.City);
            param.Add("@PostCode", addr.PostCode.ToString());

            DB.RunSP("usp_SaveCustomer", param);

        }

        public void Update(int id, string prop, string newvalue)
        {
            Customer Customer = this.GetCustomer(id);

            switch (prop)
            {
                case "Firstname": Customer.Firstname = newvalue; break;
                case "Lastname": Customer.Lastname = newvalue; break;
                case "Email": Customer.Email = newvalue; break;
                case "password": Customer.Password = <PASSWORD>; break;
                case "Phone": Customer.Phone = newvalue; break;
                default: throw new Exception("Invalid Property");
            }

            this.SaveCustomer(Customer);
        }

        public void Update(int id, string prop, Address newvalue)
        {
            if (prop != "Address") throw new Exception("Invalid Property");
            Customer Customer = this.GetCustomer(id);
            Customer.Address = newvalue;

            this.SaveCustomer(Customer);
        }

        public bool Delete(int id)
        {
            if (Customers.ContainsKey(id))
            {
                Customers.Remove(id);
                return true;
            }
            else { return false; }
        }
    }

}

{'fraction_non_alphanumeric': 0.11159657746222465, 'fraction_numerical': 0.0, 'mean_word_length': 1.856994279771191, 'pattern_counts': {'":': 10, '<': 18, '<?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': '5977869', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1345, 'n_words': 326}