public bool DeleteEmployeeExperiencees(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { List <EmployeeExperienceDTO> addressDtos = sourceUnitOfWork.Repository <EmployeeExperienceDTO>() .Query() .Get(-1) .ToList(); foreach (EmployeeExperienceDTO source in addressDtos) { EmployeeExperienceDTO adr1 = source; var destination = destinationUnitOfWork.Repository <EmployeeExperienceDTO>() .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 <EmployeeExperienceDTO>().Delete(source.Id); destinationUnitOfWork.Repository <EmployeeExperienceDTO>().Delete(destination.Id); sourceUnitOfWork.Commit(); destinationUnitOfWork.Commit(); } } return(true); }
public string Disable(EmployeeExperienceDTO employeeExperience) { if (employeeExperience == null) { return(GenericMessages.ObjectIsNull); } string stat; var iDbContext = DbContextUtil.GetDbContextInstance(); try { _employeeApplicationRepository.Update(employeeExperience); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } finally { iDbContext.Dispose(); } return(stat); }
public string InsertOrUpdate(EmployeeExperienceDTO employeeExperience) { try { var validate = Validate(employeeExperience); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(employeeExperience)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } employeeExperience.Synced = false; _employeeApplicationRepository.InsertUpdate(employeeExperience); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
public string Validate(EmployeeExperienceDTO employeeExperience) { if (null == employeeExperience) { return(GenericMessages.ObjectIsNull); } //if (String.IsNullOrEmpty(employeeExperience.ContractPeriod)) // return employeeExperience.ContractPeriod + " " + GenericMessages.StringIsNullOrEmpty; //if (employeeExperience.ContractPeriod.Length > 255) // return employeeExperience.ContractPeriod + " can not be more than 255 characters "; return(string.Empty); }
public bool ObjectExists(EmployeeExperienceDTO employeeExperience) { //var objectExists = false; //var iDbContext = DbContextUtil.GetDbContextInstance(); //try //{ // var catRepository = new Repository<EmployeeExperienceDTO>(iDbContext); // var catExists = catRepository.Query() // .Filter(bp => bp.DisplayName == employeeExperience.DisplayName && bp.Id != employeeExperience.Id && bp.Type == employeeExperience.Type) // .Get() // .FirstOrDefault(); // if (catExists != null) // objectExists = true; //} //finally //{ // iDbContext.Dispose(); //} //return objectExists; return(false); }
public bool SyncExperiences(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { Expression <Func <EmployeeExperienceDTO, bool> > filter = a => !a.Synced && a.DateLastModified > LastServerSyncDate; if (!ToServerSyncing) { Expression <Func <EmployeeExperienceDTO, bool> > filter2 = a => a.Agency != null && a.Agency.RowGuid == Singleton.Agency.RowGuid; filter = filter.And(filter2); } var exprs = sourceUnitOfWork.Repository <EmployeeExperienceDTO>().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 <EmployeeExperienceDTO>().Query() .Filter(i => i.RowGuid == adr1.RowGuid) .Get(1) .FirstOrDefault(); var id = 0; if (destination == null) { destination = new EmployeeExperienceDTO(); } else { id = destination.Id; } try { Mapper.Reset(); Mapper.CreateMap <EmployeeExperienceDTO, EmployeeExperienceDTO>() .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, "SyncExperience 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 <EmployeeExperienceDTO>() .InsertUpdate(destination); } catch { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncExperience Crud", "Problem On SyncExperience Crud Method", UserName, Agency); return(false); } } var changes = destinationUnitOfWork.Commit(); if (changes < 0) { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncExperience Commit", "Problem Commiting SyncExperience Method", UserName, Agency); return(false); } return(true); }