Inheritance: BaseEntity
コード例 #1
0
        public static void UpdateChildWithParent(this Vacancy childVacancy, Vacancy parentVacancy, IUnitOfWork uow)
        {
            if (childVacancy.Id != 0 && childVacancy.ParentVacancyId != parentVacancy.Id)
            {
                throw new Exception("Child vacancy is not a child of specified parent vacancy");
            }
            childVacancy.State = parentVacancy.State;
            childVacancy.Title = parentVacancy.Title;
            childVacancy.Description = parentVacancy.Description;
            childVacancy.SalaryMin = parentVacancy.SalaryMin;
            childVacancy.SalaryMax = parentVacancy.SalaryMax;
            childVacancy.CurrencyId = parentVacancy.CurrencyId;
            childVacancy.TypeOfEmployment = parentVacancy.TypeOfEmployment;
            childVacancy.StartDate = parentVacancy.StartDate;
            childVacancy.EndDate = parentVacancy.EndDate;
            childVacancy.DeadlineDate = parentVacancy.DeadlineDate;
            childVacancy.IndustryId = parentVacancy.IndustryId;
            childVacancy.DepartmentId = parentVacancy.DepartmentId;
            childVacancy.ResponsibleId = parentVacancy.ResponsibleId;

            childVacancy.Cities.Clear();
            childVacancy.Cities = parentVacancy.Cities.Select(x => uow.CityRepo.GetByID(x.Id)).ToList();
            childVacancy.Levels.Clear();
            childVacancy.Levels = parentVacancy.Levels.Select(x => uow.LevelRepo.GetByID(x.Id)).ToList();
            childVacancy.Tags.Clear();
            childVacancy.Tags = parentVacancy.Tags.Select(x => uow.TagRepo.GetByID(x.Id)).ToList();
            childVacancy.StageFlow.Clear();
            childVacancy.StageFlow = parentVacancy.StageFlow.Select(x =>
            {
                var stage = uow.StageRepo.GetByID(x.Id);
                return new ExtendedStage { Stage = stage, Order = stage.Order };
            }).ToList();
            childVacancy.Cities.Clear();
            childVacancy.Cities = parentVacancy.Cities.Select(x => uow.CityRepo.GetByID(x.Id)).ToList();
            childVacancy.Levels.Clear();
            childVacancy.Levels = parentVacancy.Levels.Select(x => uow.LevelRepo.GetByID(x.Id)).ToList();
            childVacancy.Tags.Clear();
            childVacancy.Tags = parentVacancy.Tags.Select(x => uow.TagRepo.GetByID(x.Id)).ToList();
            childVacancy.RequiredSkills.Clear();
            childVacancy.RequiredSkills = parentVacancy.RequiredSkills.Select(x => uow.SkillRepo.GetByID(x.Id)).ToList();
            childVacancy.LanguageSkill = new LanguageSkill
            {
                LanguageId = parentVacancy.LanguageSkill.LanguageId,
                LanguageLevel = parentVacancy.LanguageSkill.LanguageLevel
            };
            childVacancy.ParentVacancy = parentVacancy;
            //CandidatesProgress
            childVacancy.Files.Clear();
            childVacancy.Files = parentVacancy.Files.Select(x => new File
            {
                FilePath = x.FilePath,
                Size = x.Size,
                Description = x.Description
            }).ToList();
            childVacancy.Comments.Clear();
            childVacancy.Comments = parentVacancy.Comments.Select(x => new Comment { Message = x.Message }).ToList();
        }
コード例 #2
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);
 }
コード例 #3
0
        public static void Update(this VacancyStageInfo vacancyStageInfoDomain, Vacancy destination, VacancyStageInfoDTO vacancyStageInfoSource)
        {
            vacancyStageInfoDomain.CandidateId = vacancyStageInfoSource.CandidateId;
            if (vacancyStageInfoSource.VacancyId.HasValue)
            {
                vacancyStageInfoDomain.VacancyId = vacancyStageInfoSource.VacancyId.Value;
            }
            else
            {
                vacancyStageInfoDomain.Vacancy = destination;
            }
            vacancyStageInfoDomain.DateOfPass = vacancyStageInfoSource.DateOfPass;
            vacancyStageInfoDomain.StageState = vacancyStageInfoSource.StageState;
            vacancyStageInfoDomain.StageId = vacancyStageInfoSource.StageId;

            var extendedStage = destination.StageFlow.FirstOrDefault(x => x.StageId == vacancyStageInfoSource.StageId);
            if (vacancyStageInfoSource.IsNew())
            {
                if (extendedStage.Stage.IsCommentRequired)
                {
                    if (vacancyStageInfoSource.Comment == null)
                    {
                        if (vacancyStageInfoDomain.StageState == Domain.Entities.Enum.StageState.Passed)
                        {
                            throw new Exception("Comment is needed");
                        }
                    }
                    else
                    {
                        vacancyStageInfoDomain.Comment = new Comment();
                        vacancyStageInfoDomain.Comment.Update(vacancyStageInfoSource.Comment);
                    }
                }
            }
            else if (extendedStage.Stage.IsCommentRequired && vacancyStageInfoSource.Comment != null)
            {
                vacancyStageInfoDomain.Comment = new Comment();
                vacancyStageInfoDomain.Comment.Update(vacancyStageInfoSource.Comment);
            }
        }
コード例 #4
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));
     });
 }
コード例 #5
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));
     });
 }
コード例 #6
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);
     }
 }
コード例 #7
0
 public void UpdateVacancy(Vacancy vacancy)
 {
     Vacancy = vacancy;
 }
コード例 #8
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);
         }
     });
 }
コード例 #9
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);
 }
コード例 #10
0
 private static bool NeedDeleteDeadlineEvent(Vacancy destination, VacancyDTO source)
 {
     return destination.DeadlineToCalendar && !source.DeadlineToCalendar;
 }
コード例 #11
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);
     });
 }
コード例 #12
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);
     });
 }
コード例 #13
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;
     }
 }
コード例 #14
0
 private static void PerformVacancyStageFilling(Vacancy destination, IUnitOfWork uow)
 {
     var stages = uow.StageRepo.Get(new List<Expression<Func<Stage, bool>>>() { x => x.IsDefault }).ToList();
     stages.ForEach(x => destination.StageFlow.Add(x));
 }
コード例 #15
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));
     });
 }
コード例 #16
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");
         }
     }
 }
コード例 #17
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));
     });
 }
コード例 #18
0
 private static void PerformChildVacanciesUpdating(Vacancy destination, IUnitOfWork uow)
 {
     destination.ChildVacancies.ToList().ForEach(x =>
     {
         x.UpdateChildWithParent(destination, uow);
     });
 }
コード例 #19
0
 private static void PerformVacancyStageFilling(Vacancy destination, IUnitOfWork uow)
 {
     var stages = uow.StageRepo.Get(new List<Expression<Func<Stage, bool>>>() { x => x.IsDefault }).ToList();
     var extendedStages = stages.Select(x => new ExtendedStage { Stage = x, Order = x.Order }).ToList();
     extendedStages.ForEach(x => destination.StageFlow.Add(x));
     extendedStages = extendedStages.OrderBy(x => x.Order).ToList();
     destination.StageFlow = extendedStages;
 }
コード例 #20
0
 private static void PerformCommentsSaving(Vacancy destination, VacancyDTO source, IRepository<Comment> commentRepository)
 {
     RefreshExistingComments(destination, source, commentRepository);
     CreateNewComments(destination, source);
 }
コード例 #21
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);
         }
     });
 }
コード例 #22
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);
             }
         }
     });
 }
コード例 #23
0
 public void AddVacancy(Vacancy vacancy)
 {
     _vacancies.Add(vacancy);
 }
コード例 #24
0
 public Appointment(AppointmentType type, DateTime startsAt, Candidate withCandidate, Vacancy forVacancy) : this()
 {
     AppointmentType = type;
     StartsAt        = startsAt;
     Candidate       = withCandidate;
     Vacancy         = forVacancy;
 }