public string Disable(EmployeeRelativeDTO employeeRelative) { if (employeeRelative == null) { return(GenericMessages.ObjectIsNull); } string stat; var iDbContext = DbContextUtil.GetDbContextInstance(); try { _employeeRelativeRepository.Update(employeeRelative); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } finally { iDbContext.Dispose(); } return(stat); }
public string InsertOrUpdate(EmployeeRelativeDTO employeeRelative) { try { var validate = Validate(employeeRelative); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(employeeRelative)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } employeeRelative.Synced = false; _employeeRelativeRepository.InsertUpdate(employeeRelative); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
public bool DeleteEmployeeRelativees(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { List <EmployeeRelativeDTO> addressDtos = sourceUnitOfWork.Repository <EmployeeRelativeDTO>() .Query() .Get(-1) .ToList(); foreach (EmployeeRelativeDTO source in addressDtos) { EmployeeRelativeDTO adr1 = source; var destination = destinationUnitOfWork.Repository <EmployeeRelativeDTO>() .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 <EmployeeRelativeDTO>().Delete(source.Id); destinationUnitOfWork.Repository <EmployeeRelativeDTO>().Delete(destination.Id); sourceUnitOfWork.Commit(); destinationUnitOfWork.Commit(); } } return(true); }
public string Validate(EmployeeRelativeDTO employeeRelative) { if (null == employeeRelative) { return(GenericMessages.ObjectIsNull); } if (String.IsNullOrEmpty(employeeRelative.FullName)) { return(employeeRelative.FullName + " " + GenericMessages.StringIsNullOrEmpty); } if (employeeRelative.FullName.Length > 255) { return(employeeRelative.FullName + " can not be more than 255 characters "); } return(string.Empty); }
public bool ObjectExists(EmployeeRelativeDTO employeeRelative) { //var objectExists = false; //var iDbContext = DbContextUtil.GetDbContextInstance(); //try //{ // var catRepository = new Repository<EmployeeRelativeDTO>(iDbContext); // var catExists = catRepository.Query() // .Filter(bp => bp.FullName == employeeRelative.FullName && bp.Id != employeeRelative.Id && bp.Type == employeeRelative.Type) // .Get() // .FirstOrDefault(); // if (catExists != null) // objectExists = true; //} //finally //{ // iDbContext.Dispose(); //} //return objectExists; return(false); }
public bool SyncRelatives(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { Expression <Func <EmployeeRelativeDTO, bool> > filter = a => !a.Synced && a.DateLastModified > LastServerSyncDate; if (!ToServerSyncing) { Expression <Func <EmployeeRelativeDTO, bool> > filter2 = a => a.Agency != null && a.Agency.RowGuid == Singleton.Agency.RowGuid; filter = filter.And(filter2); } var sourceList = sourceUnitOfWork.Repository <EmployeeRelativeDTO>().Query() .Include(a => a.Agency, a => a.Address, a => a.Employee) .Filter(filter) .Get(1) .ToList(); var destLocalAgencies = destinationUnitOfWork.Repository <AgencyDTO>().Query() .Filter(a => a.Id == Singleton.Agency.Id) .Get(1) .ToList(); if (sourceList.Any()) { _updatesFound = true; var destAddresses = destinationUnitOfWork.Repository <AddressDTO>().Query() .Filter(a => a.AgencyId == Singleton.Agency.Id) .Get(1) .ToList(); var destEmployees = destinationUnitOfWork.Repository <EmployeeDTO>().Query() .Filter(a => a.AgencyId == Singleton.Agency.Id) .Get(1) .ToList(); var destList = destinationUnitOfWork.Repository <EmployeeRelativeDTO>().Query() .Filter(a => a.AgencyId == Singleton.Agency.Id) .Include(a => a.Address) .Get(1) .ToList(); foreach (var source in sourceList) { var destination = destList.FirstOrDefault(i => i.RowGuid == source.RowGuid); if (destination == null) { destination = new EmployeeRelativeDTO(); } try { Mapper.Reset(); Mapper.CreateMap <EmployeeRelativeDTO, EmployeeRelativeDTO>() .ForMember("Agency", option => option.Ignore()) .ForMember("AgencyId", option => option.Ignore()) .ForMember("Address", option => option.Ignore()) .ForMember("Id", option => option.Ignore()) .ForMember("Employee", option => option.Ignore()) .ForMember("Synced", option => option.Ignore()); destination = Mapper.Map(source, destination); //clients.Id = clientId; destination.CreatedByUserId = GetDestCreatedModifiedByUserId(source.CreatedByUserId, sourceUnitOfWork, destinationUnitOfWork); destination.ModifiedByUserId = GetDestCreatedModifiedByUserId(source.ModifiedByUserId, sourceUnitOfWork, destinationUnitOfWork); } catch (Exception ex) { LogUtil.LogError(ErrorSeverity.Critical, "SyncRelatives 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; } var categoryDTO = destAddresses.FirstOrDefault( c => source.Address != null && c.RowGuid == source.Address.RowGuid); { destination.Address = categoryDTO; destination.AddressId = categoryDTO != null ? categoryDTO.Id : (int?)null; } var employeeDto = destEmployees.FirstOrDefault( c => source.Employee != null && c.RowGuid == source.Employee.RowGuid); { destination.Employee = employeeDto; destination.EmployeeId = employeeDto != null ? employeeDto.Id : (int?)null; } #endregion destination.Synced = true; destinationUnitOfWork.Repository <EmployeeRelativeDTO>() .InsertUpdate(destination); } catch { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncRelatives Crud", "Problem On SyncRelatives Crud Method", UserName, Agency); return(false); } } var changes = destinationUnitOfWork.Commit(); if (changes < 0) { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncRelatives Commit", "Problem Commiting SyncRelatives Method", UserName, Agency); return(false); } } return(true); }