public string Disable(FlightProcessDTO flightProcess) { if (flightProcess == null) { return(GenericMessages.ObjectIsNull); } string stat; var iDbContext = DbContextUtil.GetDbContextInstance(); try { _flightProcessRepository.Update(flightProcess); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } finally { iDbContext.Dispose(); } return(stat); }
public string InsertOrUpdate(FlightProcessDTO flightProcess) { try { var validate = Validate(flightProcess); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(flightProcess)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } flightProcess.Synced = false; _flightProcessRepository.InsertUpdate(flightProcess); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
public bool DeleteFlightProcesses(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { List <FlightProcessDTO> addressDtos = sourceUnitOfWork.Repository <FlightProcessDTO>() .Query() .Get(-1) .ToList(); foreach (FlightProcessDTO source in addressDtos) { FlightProcessDTO adr1 = source; var destination = destinationUnitOfWork.Repository <FlightProcessDTO>() .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 <FlightProcessDTO>().Delete(source.Id); destinationUnitOfWork.Repository <FlightProcessDTO>().Delete(destination.Id); sourceUnitOfWork.Commit(); destinationUnitOfWork.Commit(); } } return(true); }
public string Validate(FlightProcessDTO flightProcess) { if (null == flightProcess) { return(GenericMessages.ObjectIsNull); } return(string.Empty); }
public bool ObjectExists(FlightProcessDTO flightProcess) { //var objectExists = false; //var iDbContext = DbContextUtil.GetDbContextInstance(); //try //{ // var catRepository = new Repository<FlightProcessDTO>(iDbContext); // var catExists = catRepository.Query() // .Filter(bp => bp.FirstName == flightProcess.FirstName && bp.Id != flightProcess.Id && bp.Type == flightProcess.Type) // .Get() // .FirstOrDefault(); // if (catExists != null) // objectExists = true; //} //finally //{ // iDbContext.Dispose(); //} //return objectExists; return(false); }
public bool SyncFlight(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { Expression <Func <FlightProcessDTO, bool> > filter = a => !a.Synced && a.DateLastModified > LastServerSyncDate; if (!ToServerSyncing) { Expression <Func <FlightProcessDTO, bool> > filter2 = a => a.Agency != null && a.Agency.RowGuid == Singleton.Agency.RowGuid; filter = filter.And(filter2); } var flightProcessDtos = sourceUnitOfWork.Repository <FlightProcessDTO>().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 flightProcessDtos) { _updatesFound = true; var adr1 = source; var destination = destinationUnitOfWork.Repository <FlightProcessDTO>().Query() .Filter(i => i.RowGuid == adr1.RowGuid) .Get(1) .FirstOrDefault(); var id = 0; if (destination == null) { destination = new FlightProcessDTO(); } else { id = destination.Id; } try { Mapper.Reset(); Mapper.CreateMap <FlightProcessDTO, FlightProcessDTO>() .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, "SyncFlight 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 <FlightProcessDTO>() .InsertUpdate(destination); } catch { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncFlight Crud", "Problem On SyncFlight Crud Method", UserName, Agency); return(false); } } var changes = destinationUnitOfWork.Commit(); if (changes < 0) { _errorsFound = true; LogUtil.LogError(ErrorSeverity.Critical, "SyncFlight Commit", "Problem Commiting SyncFlight Method", UserName, Agency); return(false); } return(true); }