public async Task <bool> CreateEmergencyContact(EmergencyContactServiceModel emergencyContact) { var model = _mapper.Map <EmergencyContact>(emergencyContact); try { _unitOfWork.BeginTransaction(); var employeeRepo = _unitOfWork.GetRepository <Employee>(); var emergencyRepo = _unitOfWork.GetRepository <EmergencyContact>(); var locationRepository = _unitOfWork.GetRepository <Location>(); var employee = employeeRepo.GetById(emergencyContact.Employee.Id); await locationRepository.AddItemAsync(model.Location); await emergencyRepo.AddItemAsync(model); employee.EmergencyContact = model; await employeeRepo.UpdateAsync(employee); await _unitOfWork.CommitAsync(); return(true); } catch { await _unitOfWork.RollbackAsync(); return(false); } }
public async Task <IActionResult> EmergencyContact() { var contact = await _accountManageService.GetEmergencyContactAsync(User.Identity.Name); var countries = _mapper.Map <List <CountryViewModel> >(await _nomenclatureService.GetCountries()); var cities = _mapper.Map <List <CityViewModel> >(await _nomenclatureService.GetCitiesByCountryId(countries[0].Id)); if (contact == null) { contact = new EmergencyContactServiceModel(); } var model = _mapper.Map <EmergencyContactViewModel>(contact); model.Countries = countries; if (contact.Location == null) { model.Cities = cities; } else { model.Cities = _mapper.Map <List <CityViewModel> >(await _nomenclatureService.GetCitiesByCountryId(contact.Location.City.Country.Id)); model.CityId = contact.Location.City.Id; model.CountryId = contact.Location.City.Country.Id; } model.StatusMessage = StatusMessage; return(View(model)); }