Ejemplo n.º 1
0
        public string Disable(InsuranceProcessDTO insuranceProcess)
        {
            if (insuranceProcess == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

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

            try
            {
                _insuranceProcessRepository.Update(insuranceProcess);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContext.Dispose();
            }
            return(stat);
        }
Ejemplo n.º 2
0
        public string InsertOrUpdate(InsuranceProcessDTO insuranceProcess)
        {
            try
            {
                var validate = Validate(insuranceProcess);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

                if (ObjectExists(insuranceProcess))
                {
                    return(GenericMessages.DatabaseErrorRecordAlreadyExists);
                }

                insuranceProcess.Synced = false;
                _insuranceProcessRepository.InsertUpdate(insuranceProcess);
                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Ejemplo n.º 3
0
        public bool DeleteInsuranceProcesses(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork)
        {
            List <InsuranceProcessDTO> addressDtos = sourceUnitOfWork.Repository <InsuranceProcessDTO>()
                                                     .Query()
                                                     .Get(-1)
                                                     .ToList();

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

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

            return(true);
        }
Ejemplo n.º 4
0
        public string Validate(InsuranceProcessDTO insuranceProcess)
        {
            if (null == insuranceProcess)
            {
                return(GenericMessages.ObjectIsNull);
            }



            return(string.Empty);
        }
Ejemplo n.º 5
0
        public bool ObjectExists(InsuranceProcessDTO insuranceProcess)
        {
            //var objectExists = false;
            //var iDbContext = DbContextUtil.GetDbContextInstance();
            //try
            //{
            //    var catRepository = new Repository<InsuranceProcessDTO>(iDbContext);
            //    var catExists = catRepository.Query()
            //        .Filter(bp => bp.FirstName == insuranceProcess.FirstName && bp.Id != insuranceProcess.Id && bp.Type == insuranceProcess.Type)
            //        .Get()
            //        .FirstOrDefault();
            //    if (catExists != null)
            //        objectExists = true;
            //}
            //finally
            //{
            //    iDbContext.Dispose();
            //}

            //return objectExists;
            return(false);
        }
Ejemplo n.º 6
0
        public bool SyncInsurance(IUnitOfWork sourceUnitOfWork,
                                  IUnitOfWork destinationUnitOfWork)
        {
            Expression <Func <InsuranceProcessDTO, bool> > filter =
                a => !a.Synced && a.DateLastModified > LastServerSyncDate;

            if (!ToServerSyncing)
            {
                Expression <Func <InsuranceProcessDTO, bool> > filter2 =
                    a => a.Agency != null &&
                    a.Agency.RowGuid == Singleton.Agency.RowGuid;
                filter = filter.And(filter2);
            }
            var exprs = sourceUnitOfWork.Repository <InsuranceProcessDTO>().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 <InsuranceProcessDTO>().Query()
                    .Filter(i => i.RowGuid == adr1.RowGuid)
                    .Get(1)
                    .FirstOrDefault();

                var id = 0;
                if (destination == null)
                {
                    destination = new InsuranceProcessDTO();
                }
                else
                {
                    id = destination.Id;
                }

                try
                {
                    Mapper.Reset();
                    Mapper.CreateMap <InsuranceProcessDTO, InsuranceProcessDTO>()
                    .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, "SyncInsurance 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 <InsuranceProcessDTO>()
                    .InsertUpdate(destination);
                }
                catch
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncInsurance Crud",
                                     "Problem On SyncInsurance Crud Method", UserName, Agency);
                    return(false);
                }
            }
            var changes = destinationUnitOfWork.Commit();
            if (changes < 0)
            {
                _errorsFound = true;
                LogUtil.LogError(ErrorSeverity.Critical, "SyncInsurance Commit",
                                 "Problem Commiting SyncInsurance Method", UserName, Agency);
                return(false);
            }
            return(true);
        }