Inheritance: BaseEntityDTO
Exemplo n.º 1
0
 public VacancyDTO Add(VacancyDTO vacancy)
 {
     var vacancyToAdd = new Vacancy();
     vacancyToAdd.Update(vacancy, uow);
     CreateChildVacanciesIfNeeded(vacancyToAdd, vacancy);
     uow.VacancyRepo.Insert(vacancyToAdd);
     uow.Commit();
     return DTOService.ToDTO<Vacancy, VacancyDTO>(vacancyToAdd);
 }
Exemplo n.º 2
0
        public static void Update(this Vacancy destination, VacancyDTO source, IUnitOfWork uow)
        {
            destination.Id = source.Id;
            if (source.Id == 0)
            {
                PerformVacancyStageFilling(destination, uow);
            }
            destination.State = source.State;

            destination.Title = source.Title;
            destination.Description = source.Description;
            destination.SalaryMin = source.SalaryMin;
            destination.SalaryMax = source.SalaryMax;
            destination.TypeOfEmployment = source.TypeOfEmployment;
            destination.StartDate = source.StartDate;
            destination.EndDate = source.EndDate;
            destination.DeadlineDate = source.DeadlineDate;
            PerformAddingDeadlineToCalendar(destination, source, uow);
            destination.DeadlineToCalendar = source.DeadlineToCalendar;

            destination.ParentVacancyId = source.ParentVacancyId;
            destination.IndustryId = source.IndustryId;
            destination.DepartmentId = source.DepartmentId;
            destination.ResponsibleId = source.ResponsibleId;
            destination.CurrencyId = source.CurrencyId;
            destination.ChildVacanciesNumber = source.ChildVacanciesNumber;

            destination.ClosingCandidateId = source.ClosingCandidateId;

            PerformLevelsSaving(destination, source, uow.LevelRepo);
            PerformLocationsSaving(destination, source, uow.CityRepo);
            PerformTagsSaving(destination, source, uow.TagRepo);
            PerformSkillsSaving(destination, source, uow.SkillRepo);
            PerformLanguageSkillsSaving(destination, source, uow.LanguageSkillRepo);
            PerformVacanciesProgressSaving(destination, source, uow.VacancyStageInfoRepo);
            PerformFilesSaving(destination, source, uow.FileRepo);
            PerformCommentsSaving(destination, source, uow.CommentRepo);
            PerformChildVacanciesUpdating(destination, uow);
        }
Exemplo n.º 3
0
 private static void PerformVacanciesProgressSaving(Vacancy destination, VacancyDTO source, IVacancyStageInfoRepository vacancyStageInfoRepository)
 {
     //TODO: if vacancy id null - set to THIS
     RefreshExistingVacanciesProgress(destination, source, vacancyStageInfoRepository);
     CreateNewVacanciesProgress(destination, source);
 }
Exemplo n.º 4
0
 private static void PerformTagsSaving(Vacancy destination, VacancyDTO source, ITagRepository tagRepository)
 {
     destination.Tags.Clear();
     source.TagIds.ToList().ForEach(tagId =>
     {
         destination.Tags.Add(tagRepository.GetByID(tagId));
     });
 }
Exemplo n.º 5
0
 private static void PerformSkillsSaving(Vacancy destination, VacancyDTO source, ISkillRepository skillRepository)
 {
     destination.RequiredSkills.Clear();
     source.RequiredSkillIds.ToList().ForEach(skillId =>
     {
         destination.RequiredSkills.Add(skillRepository.GetByID(skillId));
     });
 }
Exemplo n.º 6
0
 private static void PerformLocationsSaving(Vacancy destination, VacancyDTO source, ICityRepository locationRepository)
 {
     destination.Cities.Clear();
     source.CityIds.ToList().ForEach(locationId =>
     {
         destination.Cities.Add(locationRepository.GetByID(locationId));
     });
 }
Exemplo n.º 7
0
 private static void PerformLevelsSaving(Vacancy destination, VacancyDTO source, ILevelRepository levelRepository)
 {
     destination.Levels.Clear();
     source.LevelIds.ToList().ForEach(levelId =>
     {
         destination.Levels.Add(levelRepository.GetByID(levelId));
     });
 }
Exemplo n.º 8
0
 private static void PerformLanguageSkillsSaving(Vacancy destination, VacancyDTO source, ILanguageSkillRepository languageSkillRepository)
 {
     var updatedLanguageSkill = source.LanguageSkill;
     LanguageSkill domainLanguageSkill = destination.LanguageSkill;
     if (destination.LanguageSkill == null)
     {
         domainLanguageSkill = destination.LanguageSkill = new LanguageSkill();
     }
     if (updatedLanguageSkill == null)
     {
         destination.LanguageSkill = null;
         return;
     }
     if (updatedLanguageSkill.ShouldBeRemoved())
     {
         languageSkillRepository.Delete(updatedLanguageSkill.Id);
     }
     else
     {
         domainLanguageSkill.Update(updatedLanguageSkill);
     }
 }
Exemplo n.º 9
0
 private void CreateChildVacanciesIfNeeded(Vacancy domain, VacancyDTO dto)
 {
     List<Vacancy> childVacancies = new List<Vacancy>();
     if (dto.ChildVacanciesNumber.HasValue)
     {
         if (!domain.ChildVacancies.Any())
         {
             if (dto.HasParent()) throw new Exception("This vacancy has parent vacancy, so you can't create child of it");
             dto.ChildVacanciesNumber.Value.Times(() =>
             {
                 Vacancy childVacancy = new Vacancy();
                 childVacancy.UpdateChildWithParent(domain, uow);
                 childVacancies.Add(childVacancy);
             });
         }
         else if (dto.ChildVacanciesNumber.Value > domain.ChildVacancies.Count)
         {
             var additionalVacancyChildsNumber = dto.ChildVacanciesNumber.Value - domain.ChildVacancies.Count;
             additionalVacancyChildsNumber.Times(() =>
             {
                 Vacancy childVacancy = new Vacancy();
                 childVacancy.UpdateChildWithParent(domain, uow);
                 childVacancies.Add(childVacancy);
             });
         }
         childVacancies.ForEach(x => domain.ChildVacancies.Add(x));
     }
     if(domain.ChildVacanciesNumber < domain.ChildVacancies.Count)
     {
         domain.ChildVacanciesNumber = domain.ChildVacancies.Count;
     }
 }
Exemplo n.º 10
0
 private static void PerformCommentsSaving(Vacancy destination, VacancyDTO source, IRepository<Comment> commentRepository)
 {
     RefreshExistingComments(destination, source, commentRepository);
     CreateNewComments(destination, source);
 }
Exemplo n.º 11
0
 private static void PerformAddingDeadlineToCalendar(Vacancy destination, VacancyDTO source, IUnitOfWork uow)
 {
     if (NeedAddDeadlineEvent(destination, source))
     {
         var eventType = uow.EventTypeRepo.Get(new List<Expression<Func<EventType, bool>>> { (x => x.Title.StartsWith("Vacancy deadline")) }).FirstOrDefault();
         if (!(eventType is EventType))
         {
             throw new EntityNotFoundException("You should scpecify 'Vacancy deadline' event type");
         }
         uow.EventRepo.Insert(new Event
         {
             EventDate = source.DeadlineDate.Value,
             EventType = eventType,
             ResponsibleId = source.ResponsibleId,
             Vacancy = destination,
             Description = string.Format("Deadline for {0} vacancy", destination.Title)
         });
     }
     else if (NeedDeleteDeadlineEvent(destination, source))
     {
         var deadlineEvent = uow.EventRepo.Get(new List<Expression<Func<Event, bool>>> { x => x.EventType.Title.StartsWith("Vacancy deadline") && x.VacancyId == destination.Id }).FirstOrDefault();
         if (deadlineEvent is Event)
         {
             uow.EventRepo.Delete(deadlineEvent);
         }
         else
         {
             throw new EntityNotFoundException("Can not find event bounded to chosen vacancy");
         }
     }
 }
Exemplo n.º 12
0
 private static bool NeedDeleteDeadlineEvent(Vacancy destination, VacancyDTO source)
 {
     return destination.DeadlineToCalendar && !source.DeadlineToCalendar;
 }
Exemplo n.º 13
0
 private static void CreateNewVacanciesProgress(Vacancy destination, VacancyDTO source)
 {
     source.CandidatesProgress.Where(x => x.IsNew()).ToList().ForEach(newVacancyStageInfo =>
     {
         var toDomain = new VacancyStageInfo();
         toDomain.Update(destination, newVacancyStageInfo);
         destination.CandidatesProgress.Add(toDomain);
     });
 }
Exemplo n.º 14
0
 private static void CreateNewComments(Vacancy destination, VacancyDTO source)
 {
     source.Comments.Where(x => x.IsNew()).ToList().ForEach(newComment =>
     {
         var toDomain = new Comment();
         toDomain.Update(newComment);
         destination.Comments.Add(toDomain);
     });
 }
Exemplo n.º 15
0
 private static void RefreshExistingComments(Vacancy destination, VacancyDTO source, IRepository<Comment> commentRepository)
 {
     source.Comments.Where(x => !x.IsNew()).ToList().ForEach(updatedComment =>
     {
         var domainComment = destination.Comments.FirstOrDefault(x => x.Id == updatedComment.Id);
         if (domainComment == null)
         {
             throw new ArgumentNullException("You trying to update comment which is actually doesn't exists in database");
         }
         if (updatedComment.ShouldBeRemoved())
         {
             commentRepository.Delete(updatedComment.Id);
         }
         else
         {
             domainComment.Update(updatedComment);
         }
     });
 }
Exemplo n.º 16
0
 private static void PerformFilesSaving(Vacancy destination, VacancyDTO source, IFileRepository fileRepository)
 {
     source.Files.ToList().ForEach(file =>
     {
         var fileInVacancy = destination.Files.FirstOrDefault(x => x.Id == file.Id);
         var dbFile = fileRepository.GetByID(file.Id);
         if (dbFile == null)
         {
             throw new Exception("Unknown file");
         }
         if (file.ShouldBeRemoved())
         {
             fileRepository.Delete(file.Id);
         }
         else
         {
             dbFile.Update(file);
             if (fileInVacancy == null)
             {
                 destination.Files.Add(dbFile);
             }
         }
     });
 }
Exemplo n.º 17
0
 private static void RefreshExistingVacanciesProgress(Vacancy destination, VacancyDTO source, IVacancyStageInfoRepository vacancyStageInfoRepository)
 {
     source.CandidatesProgress.Where(x => !x.IsNew()).ToList().ForEach(updatedVacanciesStageInfo =>
     {
         var domainVacancyStageInfo = destination.CandidatesProgress.FirstOrDefault(x => x.Id == updatedVacanciesStageInfo.Id);
         if (domainVacancyStageInfo == null)
         {
             throw new ArgumentNullException("You trying to update vacanies progress which is actually doesn't exists in database");
         }
         if (updatedVacanciesStageInfo.ShouldBeRemoved())
         {
             vacancyStageInfoRepository.Delete(updatedVacanciesStageInfo.Id);
         }
         else
         {
             domainVacancyStageInfo.Update(destination, updatedVacanciesStageInfo);
         }
     });
 }
Exemplo n.º 18
0
 public VacancyDTO Update(VacancyDTO vacancy)
 {
     var vacancyToUpdate = uow.VacancyRepo.GetByID(vacancy.Id);
     vacancyToUpdate.Update(vacancy, uow);
     CreateChildVacanciesIfNeeded(vacancyToUpdate, vacancy);
     uow.VacancyRepo.Update(vacancyToUpdate);
     uow.Commit();
     return DTOService.ToDTO<Vacancy, VacancyDTO>(vacancyToUpdate);
 }