private void ExcuteEmployeeEducationDeleteCommand() { EmployeeEducationDTO empEduc = SelectedEmployee.Education; //if (empEduc != null) //{ // if (LabourProcess.Count > 0) // { // MessageBox.Show("Delete labour process data first, it depends on education data...", // "Deleting problem", MessageBoxButton.OK, MessageBoxImage.Exclamation); // return; // } // if (EmbassyProcess.Count > 0) // { // MessageBox.Show("Delete embassy process data first, it depends on education data...", // "Deleting problem", MessageBoxButton.OK, MessageBoxImage.Exclamation); // return; // } // if (MessageBox.Show("Are you sure you want to delete the education data?", "Delete Education Data", // MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.No) == // MessageBoxResult.Yes) // { // new EmployeeEducationService(true).Delete(empEduc.Id.ToString(CultureInfo.InvariantCulture)); // SetEducation(); // } //} }
public string InsertOrUpdate(EmployeeEducationDTO employeeEducation) { try { var validate = Validate(employeeEducation); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(employeeEducation)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } employeeEducation.Synced = false; _employeeEducationRepository.InsertUpdate(employeeEducation); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
public string Disable(EmployeeEducationDTO employeeEducation) { if (employeeEducation == null) { return(GenericMessages.ObjectIsNull); } string stat; var iDbContext = DbContextUtil.GetDbContextInstance(); try { _employeeEducationRepository.Update(employeeEducation); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } finally { iDbContext.Dispose(); } return(stat); }
public bool DeleteEmployeeEducationes(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { List <EmployeeEducationDTO> addressDtos = sourceUnitOfWork.Repository <EmployeeEducationDTO>() .Query() .Get(-1) .ToList(); foreach (EmployeeEducationDTO source in addressDtos) { EmployeeEducationDTO adr1 = source; var destination = destinationUnitOfWork.Repository <EmployeeEducationDTO>() .Query() .Filter(i => i.RowGuid == adr1.RowGuid) .Get(-1)//don't use .Get() to make sure both sides of data are disabled .FirstOrDefault(); if (destination != null) { sourceUnitOfWork.Repository <EmployeeEducationDTO>().Delete(source.Id); destinationUnitOfWork.Repository <EmployeeEducationDTO>().Delete(destination.Id); sourceUnitOfWork.Commit(); destinationUnitOfWork.Commit(); } } return(true); }
public IHttpActionResult DeleteEmployeeEducation(int id) { EmployeeEducation employeeEducation = null; try { UnitOfWork unitOfWork = new UnitOfWork(factory); EmployeeEducation education = unitOfWork.EmployeeEducationsRepository.Get(d => d.Id == id, includeProperties: "EducationStudyForm").FirstOrDefault(); education.Deleted = true; unitOfWork.EmployeeEducationsRepository.Update(education); unitOfWork.Save(); EmployeeEducationDTO dto = education.ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PostEmployeeEducation(EmployeeEducationDTO employeeEducation) { try { EmployeeEducation education = employeeEducation.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); education.Id = education.NewId(unitOfWork); unitOfWork.EmployeeEducationsRepository.Insert(education); unitOfWork.Save(); EmployeeEducationDTO dto = unitOfWork.EmployeeEducationsRepository.Get(d => d.Id == education.Id, includeProperties: "EducationStudyForm").FirstOrDefault().ToDTO(); return(CreatedAtRoute("GetEmployeeEducation", new { id = dto.Id }, dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PutEmployeeEducation(int id, EmployeeEducationDTO employeeEducation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeeEducation.Id) { return(BadRequest()); } try { EmployeeEducation education = employeeEducation.FromDTO(); UnitOfWork unitOfWork = new UnitOfWork(factory); unitOfWork.EmployeeEducationsRepository.Update(education); unitOfWork.Save(); EmployeeEducationDTO dto = unitOfWork.EmployeeEducationsRepository.Get(d => d.Id == id, includeProperties: "EducationStudyForm").FirstOrDefault().ToDTO(); return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public string Validate(EmployeeEducationDTO employeeEducation) { if (null == employeeEducation) { return(GenericMessages.ObjectIsNull); } return(string.Empty); }
public IHttpActionResult GetEmployeeEducationView(int id) { try { UnitOfWork unitOfWork = new UnitOfWork(factory); EmployeeEducationDTO employeeEducation = unitOfWork.EmployeeEducationsRepository.Get(d => d.Id == id, includeProperties: "EducationStudyForm").FirstOrDefault().ToDTO(); return(Ok(employeeEducation)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public bool ObjectExists(EmployeeEducationDTO employeeEducation) { //var objectExists = false; //var iDbContext = DbContextUtil.GetDbContextInstance(); //try //{ // var catRepository = new Repository<EmployeeEducationDTO>(iDbContext); // var catExists = catRepository.Query() // .Filter(bp => bp.DisplayName == employeeEducation.DisplayName && bp.Id != employeeEducation.Id && bp.Type == employeeEducation.Type) // .Get() // .FirstOrDefault(); // if (catExists != null) // objectExists = true; //} //finally //{ // iDbContext.Dispose(); //} //return objectExists; return(false); }
public bool SyncEducation(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { Expression <Func <EmployeeEducationDTO, bool> > filter = a => !a.Synced && a.DateLastModified > LastServerSyncDate; if (!ToServerSyncing) { Expression <Func <EmployeeEducationDTO, bool> > filter2 = a => a.Agency != null && a.Agency.RowGuid == Singleton.Agency.RowGuid; filter = filter.And(filter2); } var exprs = sourceUnitOfWork.Repository <EmployeeEducationDTO>() .Query().Include(a => a.Agency) .Filter(filter) .Get(1) .ToList(); var destLocalAgencies = destinationUnitOfWork.Repository <AgencyDTO>().Query() .Filter(a => a.Id == Singleton.Agency.Id) .Get(1) .ToList(); foreach (var source in exprs) { _updatesFound = true; var adr1 = source; var destination = destinationUnitOfWork.Repository <EmployeeEducationDTO>().Query() .Filter(i => i.RowGuid == adr1.RowGuid) .Get(1) .FirstOrDefault(); var id = 0; if (destination == null) { destination = new EmployeeEducationDTO(); } else { id = destination.Id; } try { Mapper.Reset(); Mapper.CreateMap <EmployeeEducationDTO, EmployeeEducationDTO>() .ForMember("Agency", option => option.Ignore()) .ForMember("AgencyId", option => option.Ignore()) .ForMember("Synced", option => option.Ignore()); destination = Mapper.Map(source, destination); destination.Id = id; destination.CreatedByUserId = GetDestCreatedModifiedByUserId(source.CreatedByUserId, sourceUnitOfWork, destinationUnitOfWork); destination.ModifiedByUserId = GetDestCreatedModifiedByUserId(source.ModifiedByUserId, sourceUnitOfWork, destinationUnitOfWork); } catch (Exception ex) { LogUtil.LogError(ErrorSeverity.Critical, "SyncEducation Mapping", ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency); } try { #region Foreign Keys var agencyDTO = destLocalAgencies.FirstOrDefault( c => source.Agency != null && c.RowGuid == source.Agency.RowGuid); { destination.Agency = agencyDTO; destination.AgencyId = agencyDTO != null ? agencyDTO.Id : (int?)null; } #endregion destination.Synced = true; destinationUnitOfWork.Repository <EmployeeEducationDTO>() .InsertUpdate(destination); } catch { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncEducation Crud", "Problem On SyncEducation Crud Method", UserName, Agency); return(false); } } var changes = destinationUnitOfWork.Commit(); if (changes < 0) { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncEducation Commit", "Problem Commiting SyncEducation Method", UserName, Agency); return(false); } return(true); }