<commit_before>﻿using System.Collections.Generic;
using LiveScoreUpdateSystem.Data.Repositories.Contracts;
using LiveScoreUpdateSystem.Data.SaveContext.Contracts;
using LiveScoreUpdateSystem.Data.Models.Abstraction;

namespace LiveScoreUpdateSystem.Services.Data.Abstraction
{
    namespace MvcTemplate.Services.Data
    {
        using Bytes2you.Validation;
        using System;
        using System.Linq;

        public abstract class DataService<T>
            where T : DataModel
        {
            public DataService(IEfRepository<T> dataSet, ISaveContext saveContext)
            {
                Guard.WhenArgument(dataSet, "IEfRepository dataSet").IsNull().Throw();
                Guard.WhenArgument(saveContext, "SaveContext").IsNull().Throw();

                this.Data = dataSet;
                this.SaveContext = saveContext;
            }

            protected IEfRepository<T> Data { get; private set; }

            protected ISaveContext SaveContext { get; private set; }

            public virtual void Add(T item)
            {
                this.Data.Add(item);
                this.SaveContext.SaveChanges();
            }

            public virtual void Delete(Guid id)
            {
                var entity = this.GetById(id) ?? 
                    throw new InvalidOperationException("No entity with provided id found.");

                this.Data.Delete(entity);
                this.SaveContext.SaveChanges();
            }

            public virtual IEnumerable<T> GetAll()
            {
                return this.Data.All.ToList();
            }

            public virtual T GetById(Guid id)
            {
                return this.Data.All.FirstOrDefault(e => e.Id == id);
            }
        }
    }
}<commit_msg>Changed if guard clauses with Bytes2You validation<commit_after>﻿using System.Collections.Generic;
using LiveScoreUpdateSystem.Data.Repositories.Contracts;
using LiveScoreUpdateSystem.Data.SaveContext.Contracts;
using LiveScoreUpdateSystem.Data.Models.Abstraction;

namespace LiveScoreUpdateSystem.Services.Data.Abstraction
{
    namespace MvcTemplate.Services.Data
    {
        using Bytes2you.Validation;
        using System;
        using System.Linq;

        public abstract class DataService<T>
            where T : DataModel
        {
            public DataService(IEfRepository<T> dataSet, ISaveContext saveContext)
            {
                Guard.WhenArgument(dataSet, "IEfRepository dataSet").IsNull().Throw();
                Guard.WhenArgument(saveContext, "SaveContext").IsNull().Throw();

                this.Data = dataSet;
                this.SaveContext = saveContext;
            }

            protected IEfRepository<T> Data { get; private set; }

            protected ISaveContext SaveContext { get; private set; }

            public virtual void Add(T item)
            {
                this.Data.Add(item);
                this.SaveContext.SaveChanges();
            }

            public virtual void Delete(Guid id)
            {
                var entity = this.GetById(id);

                Guard.WhenArgument(entity, "No entity with such id").IsNull().Throw();

                this.Data.Delete(entity);
                this.SaveContext.SaveChanges();
            }

            public virtual IEnumerable<T> GetAll()
            {
                return this.Data.All.ToList();
            }

            public virtual T GetById(Guid id)
            {
                return this.Data.All.FirstOrDefault(e => e.Id == id);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08805384183959619, 'fraction_numerical': 0.0008412787436904094, 'mean_word_length': 1.7694099378881987, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7664064', 'n_tokens_mistral': 913, 'n_tokens_neox': 873, 'n_words': 186}