public void Insert(EmployeeViewModel employeeViewModel) { var model = AutoMapper.Mapper.Map <EmployeeViewModel, Employee>(employeeViewModel); if (model.Nationality != null) { model.Nationality = _countryRepository.FindById(model.Nationality.Id); } if (model.EthnicGroup != null) { model.EthnicGroup = _ethnicGroupRepository.FindById(model.EthnicGroup.Id); } if (model.Religion != null) { model.Religion = _religionRepository.FindById(model.Religion.Id); } if (model.Education != null) { model.Education = _educationRepository.FindById(model.Education.Id); } model.IsDeleted = false; model.IsDeactivated = false; //model.EmployeeRelationType = 1; // Temporal model.UserId = 1; var skillIds = employeeViewModel.SelectedSkills != null? employeeViewModel.SelectedSkills.ToList() : new List <long>(); var skills = _skillRepository.GetAllByCondition(x => skillIds.Contains(x.Id)); using (var scope = new TransactionScope()) { try { var insertItem = _repository.Add(model); foreach (var skill in skills) { _employeeSkillRepository.Add(new EmployeeSkill() { Skill = skill, Employee = insertItem }); } Save(); scope.Complete(); } catch (TransactionException ex) { scope.Dispose(); } } }
public void Delete(EducationViewModel model) { var item = _repository.FindById(model.Id); if (item != null) { _repository.Delete(item); } }
public IActionResult UpdateEducation([FromBody] Education education) { var lang = Request.Headers["language"].ToString(); var errorMessages = new List <string>(); try { var edu = _educationRepository.FindById(education.Id); if (edu == null) { return(NotFound()); } edu.Title_EN = education.Title_EN; edu.Title_FR = !string.IsNullOrEmpty(education.Title_FR) ? education.Title_FR : education.Title_EN; edu.Specialization_EN = education.Specialization_EN; edu.Specialization_FR = !string.IsNullOrEmpty(education.Specialization_FR) ? education.Specialization_FR : education.Specialization_EN; edu.Establishment_EN = education.Establishment_EN; edu.Establishment_FR = !string.IsNullOrEmpty(education.Establishment_FR) ? education.Establishment_FR : education.Establishment_EN; edu.Mention_EN = education.Mention_EN; edu.Mention_FR = !string.IsNullOrEmpty(education.Mention_FR) ? education.Mention_FR : education.Mention_EN; edu.Country_EN = education.Country_EN; edu.Country_FR = !string.IsNullOrEmpty(education.Country_FR) ? education.Country_FR : education.Country_EN; edu.City_EN = education.City_EN; edu.City_FR = !string.IsNullOrEmpty(education.City_FR) ? education.City_FR : education.City_EN; edu.YearsCount = education.YearsCount; edu.Note = education.Note; edu.StartDate = education.StartDate; edu.GraduateDate = education.GraduateDate; var updatedEducation = _educationRepository.Update(edu); return(Ok(new { updatedEducation })); } catch { errorMessages.Add(_translator.GetTranslation("ERROR", lang)); return(BadRequest(new { errors = errorMessages })); } }