Example #1
0
        public string DisableCondition(VisaConditionDTO visaCondition)
        {
            if (visaCondition == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

            string stat;
            var    iDbContext = DbContextUtil.GetDbContextInstance();

            try
            {
                _visaConditionRepository.Update(visaCondition);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContext.Dispose();
            }
            return(stat);
        }
Example #2
0
 public VisaCondition(VisaConditionDTO condition)
 {
     VisaViewModel.Errors = 0;
     InitializeComponent();
     Messenger.Default.Send <VisaConditionDTO>(condition);
     Messenger.Reset();
 }
Example #3
0
        public string InsertOrUpdateCondition(VisaConditionDTO visaCondition)
        {
            try
            {
                var validate = ValidateCondition(visaCondition);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

                if (ConditionObjectExists(visaCondition))
                {
                    return(GenericMessages.DatabaseErrorRecordAlreadyExists);
                }

                visaCondition.Synced = false;
                _visaConditionRepository.InsertUpdate(visaCondition);
                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Example #4
0
        public bool DeleteVisaConditiones(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork)
        {
            List <VisaConditionDTO> addressDtos = sourceUnitOfWork.Repository <VisaConditionDTO>()
                                                  .Query()
                                                  .Get(-1)
                                                  .ToList();

            foreach (VisaConditionDTO source in addressDtos)
            {
                VisaConditionDTO adr1 = source;
                var destination       =
                    destinationUnitOfWork.Repository <VisaConditionDTO>()
                    .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 <VisaConditionDTO>().Delete(source.Id);
                    destinationUnitOfWork.Repository <VisaConditionDTO>().Delete(destination.Id);

                    sourceUnitOfWork.Commit();
                    destinationUnitOfWork.Commit();
                }
            }

            return(true);
        }
Example #5
0
        public string ValidateCondition(VisaConditionDTO visaCondition)
        {
            if (null == visaCondition)
            {
                return(GenericMessages.ObjectIsNull);
            }

            return(string.Empty);
        }
Example #6
0
        public bool ConditionObjectExists(VisaConditionDTO visaCondition)
        {
            //var objectExists = false;
            //var iDbContext = DbContextUtil.GetDbContextInstance();
            //try
            //{
            //    var catRepository = new Repository<VisaConditionDTO>(iDbContext);
            //    var catExists = catRepository.Query()
            //        .Filter(bp => bp.FirstName == visaCondition.FirstName && bp.Id != visaCondition.Id && bp.Type == visaCondition.Type)
            //        .Get()
            //        .FirstOrDefault();
            //    if (catExists != null)
            //        objectExists = true;
            //}
            //finally
            //{
            //    iDbContext.Dispose();
            //}

            //return objectExists;
            return(false);
        }
Example #7
0
        public bool SyncVisaConditions(IUnitOfWork sourceUnitOfWork,
                                       IUnitOfWork destinationUnitOfWork)
        {
            Expression <Func <VisaConditionDTO, bool> > filter =
                a => !a.Synced && a.DateLastModified > LastServerSyncDate;

            if (!ToServerSyncing)
            {
                Expression <Func <VisaConditionDTO, bool> > filter2 =
                    a => a.Agency != null &&
                    a.Agency.RowGuid == Singleton.Agency.RowGuid;
                filter = filter.And(filter2);
            }

            var sources = sourceUnitOfWork.Repository <VisaConditionDTO>().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 sources)
            {
                _updatesFound = true;

                var adr1        = source;
                var destination =
                    destinationUnitOfWork.Repository <VisaConditionDTO>().Query()
                    .Filter(i => i.RowGuid == adr1.RowGuid)
                    .Get(1)
                    .FirstOrDefault();

                //To Prevent ServerData Overriding
                if (destination != null && (ToServerSyncing && !destination.Synced))
                {
                    continue;
                }

                var clientId = 0;
                if (destination == null)
                {
                    destination = new VisaConditionDTO();
                }
                else
                {
                    clientId = destination.Id;
                }

                try
                {
                    Mapper.Reset();
                    Mapper.CreateMap <VisaConditionDTO, VisaConditionDTO>()
                    .ForMember("Agency", option => option.Ignore())
                    .ForMember("AgencyId", option => option.Ignore())
                    .ForMember("Synced", option => option.Ignore());
                    destination    = Mapper.Map(source, destination);
                    destination.Id = clientId;

                    destination.CreatedByUserId = GetDestCreatedModifiedByUserId(source.CreatedByUserId,
                                                                                 sourceUnitOfWork, destinationUnitOfWork);
                    destination.ModifiedByUserId = GetDestCreatedModifiedByUserId(source.ModifiedByUserId,
                                                                                  sourceUnitOfWork, destinationUnitOfWork);
                }
                catch (Exception ex)
                {
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncVisaConditions 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 <VisaConditionDTO>().InsertUpdate(destination);
                }
                catch
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncVisaConditions Crud",
                                     "Problem On SyncVisaConditions Crud Method", UserName, Agency);
                    return(false);
                }
            }
            var changes = destinationUnitOfWork.Commit();
            if (changes < 0)
            {
                _errorsFound = true;
                LogUtil.LogError(ErrorSeverity.Critical, "SyncVisaConditions Commit",
                                 "Problem Commiting SyncVisaConditions Method", UserName, Agency);
                return(false);
            }

            return(true);
        }