public void Update(T toEdit)
 {
     using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
     {
         KlanikContext _context = _provider.GetService <KlanikContext>();
         _context.SaveChanges();
     }
 }
        public void Delete(T toRemove)
        {
            using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                KlanikContext _context = _provider.GetService <KlanikContext>();

                var exists = _context.Set <T>().Any(x => x.Id == toRemove.Id);

                if (exists)
                {
                    _context.Entry(toRemove).State = EntityState.Deleted;
                }

                _context.SaveChanges();
            }
        }
        public void Create(T toCreate)
        {
            using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                KlanikContext _context = _provider.GetService <KlanikContext>();

                var exists = _context.Set <T>().Any(x => x.Id == toCreate.Id);

                _context.Entry(toCreate).State =
                    exists ?
                    EntityState.Modified :
                    EntityState.Added;

                _context.SaveChanges();
            }
        }
        public void Create(Konsultant toCreate)
        {
            using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                KlanikContext _context = _provider.GetService <KlanikContext>();

                var exists = _context.Konsultants.Any(x => x.Id == toCreate.Id);

                if (exists)
                {
                    Update(toCreate);
                }
                else
                {
                    _context.Add(toCreate);
                }

                _context.SaveChanges();
            }
        }
        public void Update(Konsultant toEdit)
        {
            using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                KlanikContext _context = _provider.GetService <KlanikContext>();
                foreach (var comp in toEdit.Competences)
                {
                    CreateOrUpdateCompetence(_context, comp);
                }

                foreach (var edu in toEdit.Educations)
                {
                    CreateOrUpdateEducation(_context, edu);
                }

                foreach (var cert in toEdit.Certificates)
                {
                    CreateOrUpdateCertificate(_context, cert);
                }

                foreach (var lang in toEdit.Languages)
                {
                    CreateOrUpdateLanguage(_context, lang);
                }

                foreach (var exp in toEdit.ProfessionalExperiences)
                {
                    CreateOrUpdateProfessionalExperience(_context, exp);
                }

                foreach (var refer in toEdit.ProfessionalReferences)
                {
                    CreateOrUpdateProfessionalReference(_context, refer);
                }

                _context.SaveChanges();
            }
        }