コード例 #1
0
        private static void CreateOrUpdateCompetence(KlanikContext _context, OwnedCompetences comp)
        {
            var ownedCompExists = _context.OwnedCompetences.Any(x => x.CompetenceId == comp.CompetenceId &&
                                                                x.KonsultantId == comp.KonsultantId);
            var compExists = _context.Competences.Any(x => x.Id == comp.CompetenceId);

            _context.Entry(comp).State =
                ownedCompExists ?
                EntityState.Modified :
                EntityState.Added;

            _context.Entry(comp.Competence).State =
                compExists ?
                EntityState.Modified :
                EntityState.Added;
        }
コード例 #2
0
        private static void CreateOrUpdateCertificate(KlanikContext _context, OwnedCertificate cert)
        {
            var ownedCertExists = _context.OwnedCertificates.Any(x => x.CertificateId == cert.CertificateId &&
                                                                 x.KonsultantId == cert.KonsultantId);

            var certExists = _context.Certificates.Any(x => x.Id == cert.Certificate.Id);

            _context.Entry(cert).State =
                ownedCertExists ?
                EntityState.Modified :
                EntityState.Added;

            _context.Entry(cert.Certificate).State =
                certExists ?
                EntityState.Modified :
                EntityState.Added;
        }
コード例 #3
0
        private static void CreateOrUpdateEducation(KlanikContext _context, PersonalEducation edu)
        {
            var perEduExists = _context.PersonalEducations.Any(x => x.EducationId == edu.EducationId &&
                                                               x.KonsultantId == edu.KonsultantId);

            var eduExists = _context.Educations.Any(x => x.Id == edu.Education.Id);

            _context.Entry(edu).State =
                perEduExists ?
                EntityState.Modified :
                EntityState.Added;

            _context.Entry(edu.Education).State =
                eduExists ?
                EntityState.Modified :
                EntityState.Added;
        }
コード例 #4
0
        private static void CreateOrUpdateLanguage(KlanikContext _context, KnownLanguage lang)
        {
            var knownLangExists = _context.KnownLanguages.Any(x => x.LanguageId == lang.LanguageId &&
                                                              x.KonsultantId == lang.KonsultantId);

            var langExists = _context.Languages.Any(x => x.Id == lang.Language.Id);

            _context.Entry(lang).State =
                knownLangExists ?
                EntityState.Modified :
                EntityState.Added;

            _context.Entry(lang.Language).State =
                langExists ?
                EntityState.Modified :
                EntityState.Added;
        }
コード例 #5
0
        public void Delete(Konsultant toRemove)
        {
            using (IServiceScope scope = _provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                KlanikContext _context = _provider.GetService <KlanikContext>();

                _context.Entry(toRemove).State = EntityState.Deleted;
            }
        }
コード例 #6
0
        private static void CreateOrUpdateProfessionalExperience(KlanikContext _context, ProfessionalExperience exp)
        {
            var profExpExists = _context.ProfessionalExperiences.Any(x => x.Id == exp.Id);

            _context.Entry(exp).State =
                profExpExists ?
                EntityState.Modified :
                EntityState.Added;
        }
コード例 #7
0
        private static void CreateOrUpdateProfessionalReference(KlanikContext _context, ProfessionalReference refer)
        {
            var referExists = _context.ProfessionalReferences.Any(x => x.Id == refer.Id);

            _context.Entry(refer).State =
                referExists ?
                EntityState.Modified :
                EntityState.Added;

            if (!referExists)
            {
                var contact = new Contact
                {
                    Mail  = refer.Contacts.Mail,
                    Phone = refer.Contacts.Phone,
                    ProfessionalReference = refer
                };

                _context.Entry(contact).State = EntityState.Added;
            }
        }
コード例 #8
0
        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();
            }
        }
コード例 #9
0
        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();
            }
        }