コード例 #1
0
        public async Task UpdateExtraInfo(UpdateExtraInfoReq req, DatabaseContext context)
        {
            var expertProfile = await context.ExpertProfiles
                                .Include(p => p.User)
                                .Include(p => p.ExpertProfileDocuments)
                                .SingleAsync(profile => profile.Id == req.ExpertProfileId);

            expertProfile.ClothingSizeId = req.ClothingSizeId;

            var documentIdsToAdd  = req.ExpertDocumentsIds.Where(id => expertProfile.ExpertProfileDocuments.All(d => d.ExpertDocumentId != id)).ToArray();
            var documentsToDelete = expertProfile.ExpertProfileDocuments.Where(d => !req.ExpertDocumentsIds.Contains(d.ExpertDocumentId)).ToArray();

            foreach (var docId in documentIdsToAdd)
            {
                expertProfile.ExpertProfileDocuments.Add(new ExpertProfileDocument {
                    ExpertDocumentId = docId
                });
            }

            foreach (var doc in documentsToDelete)
            {
                expertProfile.ExpertProfileDocuments.Remove(doc);
            }

            if (expertProfile.IsPublished)
            {
                this.ThrowIfPublishingBroken(expertProfile);
            }
        }
コード例 #2
0
        public async Task UpdateExtraInfo(UpdateExtraInfoReq req, DatabaseContext context)
        {
            var currentUserData = this._currentUserService.GetCurrentUserData();

            var vac = context.Vacancies
                      .Include(v => v.VacancyLanguages)
                      .Include(v => v.VacancyDocuments)
                      .Include(v => v.VacancySkills)
                      .Single(v => v.Id == req.VacancyId && v.Event.Company.UserId == currentUserData.Id);


            var languagesIdsToAdd    = req.LanguagesIds.Where(id => vac.VacancyLanguages.All(l => l.LanguageId != id)).ToArray();
            var vacLanguagesToDelete = vac.VacancyLanguages.Where(lang => !req.LanguagesIds.Contains(lang.LanguageId)).ToArray();

            foreach (var profileLang in vacLanguagesToDelete)
            {
                vac.VacancyLanguages.Remove(profileLang);
            }

            foreach (var langId in languagesIdsToAdd)
            {
                vac.VacancyLanguages.Add(new VacancyLanguage {
                    LanguageId = langId
                });
            }


            var documentIdsToAdd  = req.DocumentsIds.Where(id => vac.VacancyDocuments.All(d => d.ExpertDocumentId != id)).ToArray();
            var documentsToDelete = vac.VacancyDocuments.Where(d => !req.DocumentsIds.Contains(d.ExpertDocumentId)).ToArray();

            foreach (var docId in documentIdsToAdd)
            {
                vac.VacancyDocuments.Add(new VacancyDocument {
                    ExpertDocumentId = docId
                });
            }

            foreach (var doc in documentsToDelete)
            {
                vac.VacancyDocuments.Remove(doc);
            }


            var skillsIdsToAdd    = req.SkillsIds.Where(id => vac.VacancySkills.All(s => s.SkillId != id)).ToArray();
            var vacSkillsToDelete = vac.VacancySkills.Where(s => !req.SkillsIds.Contains(s.SkillId)).ToArray();

            foreach (var skillId in skillsIdsToAdd)
            {
                vac.VacancySkills.Add(new VacancySkill {
                    SkillId = skillId
                });
            }

            foreach (var profileSkill in vacSkillsToDelete)
            {
                vac.VacancySkills.Remove(profileSkill);
            }

            if (vac.IsPublished)
            {
                this.ThrowIfPublishingBroken(vac);
            }
        }