Пример #1
0
        public static void AutomaticDatabaseBackup()
        {
            try
            {
                string dest        = PathUtil.GetServerBackupPath();
                string source      = PathUtil.GetFolderPath();
                var    dir         = new DirectoryInfo(source);
                var    localAgency = new LocalAgencyService(true).GetLocalAgency(); // Singleton.Agency;

                IEnumerable <FileInfo> fileList = dir.GetFiles("*.sdf", SearchOption.AllDirectories);
                foreach (FileInfo fileInfo in fileList)
                {
                    string sourceFiName = fileInfo.Name;
                    string destFiName   = localAgency.AgencyNameShort + "_" + DateTime.Now.ToString("dd-MM-yy") + "_" +
                                          fileInfo.Name;

                    File.Copy(Path.Combine(source, sourceFiName), Path.Combine(dest, destFiName), true);
                }
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "AutomaticDatabaseBackup.AutomaticDatabaseBackup",
                                 ex.Message + Environment.NewLine + ex.InnerException, "defaultUser1", "Agency1");
            }
        }
Пример #2
0
        public static bool InsertAgencyWithAgents(string userName, string agencyName)
        {
            //try
            //{
            //    userName = Singleton.User.UserName;
            //    agencyName = Singleton.Agency.AgencyName;
            //}
            //catch
            //{
            //    userName = "******";
            //    agencyName = "Default Agency";
            //}

            try
            {
                IDbContext iDbContext = DbContextUtil.GetDbContextInstance();
                var        unitOfWork = new UnitOfWork(iDbContext);


                AgencyDTO agency = new LocalAgencyService(true).GetLocalAgency();
                IEnumerable <AgentDTO> agents = new ForeignAgentService(true, false).GetAll();

                foreach (AgentDTO foreignAgentDTO in agents)
                {
                    AgentDTO dto = foreignAgentDTO;
                    var      agencyWithAgents = unitOfWork.Repository <AgencyAgentDTO>()
                                                .Query()
                                                .FilterList(f => f.AgentId == dto.Id && f.AgencyId == agency.Id)
                                                .Get()
                                                .FirstOrDefault();

                    if (agencyWithAgents != null)
                    {
                        continue;
                    }

                    agencyWithAgents = new AgencyAgentDTO
                    {
                        AgencyId = agency.Id,
                        AgentId  = foreignAgentDTO.Id
                    };

                    unitOfWork.Repository <AgencyAgentDTO>().Insert(agencyWithAgents);
                }
                unitOfWork.Commit();

                unitOfWork.Dispose();

                return(true);
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "Insert Agency With Agents",
                                 ex.Message + Environment.NewLine + ex.InnerException, userName, agencyName);
                return(false);
            }
        }
Пример #3
0
        public ActionResult AgencyDetail(string agencyId)
        {
            if (!string.IsNullOrEmpty(agencyId))
            {
                var localAgencyId = EncryptionUtility.Hash64Decode(agencyId);
                var cri           = new SearchCriteria <AgencyDTO>();
                cri.FiList.Add(v => v.Id == localAgencyId);
                var localAgencyDTO = new LocalAgencyService(true)
                                     .GetAll(cri).ToList().FirstOrDefault();

                return(View(localAgencyDTO));
            }

            return(View());
        }
Пример #4
0
        public static void SendLogReport()
        {
            try
            {
                string    dest   = PathUtil.GetServerLogPath();
                string    source = PathUtil.GetLogPath();
                var       dir    = new DirectoryInfo(source);
                AgencyDTO agency = new LocalAgencyService(true).GetLocalAgency(); // Singleton.Agency;

                IEnumerable <FileInfo> fileList = dir.GetFiles("*.txt", SearchOption.AllDirectories);
                foreach (FileInfo fileInfo in fileList)
                {
                    string sourceFiName = fileInfo.Name;
                    string destFiName   = agency.AgencyNameShort + "_" + fileInfo.Name;

                    File.Copy(Path.Combine(source, sourceFiName), Path.Combine(dest, destFiName), true);
                }
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ErrorSeverity.Critical, "SendLogReport.SendLogReport",
                                 ex.Message + Environment.NewLine + ex.InnerException, "defaultUser1", "Agency1");
            }
        }
Пример #5
0
        public static bool InsertAgencyNamesonAddressesandAttachments()
        {
            #region Update Addresses
            var localAgency = new LocalAgencyService(true).GetLocalAgency();

            try
            {
                var unitOfWork = new UnitOfWork(DbContextUtil.GetDbContextInstance());

                var addresses = unitOfWork.Repository <AddressDTO>()
                                .Query().Filter(a => a.AgencyId == null).Get().ToList();
                if (addresses.Count > 0)
                {
                    foreach (var addressDTO in addresses)
                    {
                        addressDTO.AgencyId = localAgency.Id;
                        unitOfWork.Repository <AddressDTO>().Update(addressDTO);
                    }
                    unitOfWork.Commit();
                }


                unitOfWork.Dispose();
            }
            catch (Exception exception)
            {
                LogUtil.LogError(ErrorSeverity.Fatal,
                                 "InsertAgencyNamesonAddressesandAttachments",
                                 exception.Message + Environment.NewLine + exception.InnerException, "", "");
            }
            #endregion

            #region Update Attachments
            try
            {
                var unitOfWork = new UnitOfWork(DbContextUtil.GetDbContextInstance());


                var addresses = unitOfWork.Repository <AttachmentDTO>()
                                .Query().Filter(a => a.AgencyId == null).Get().ToList();

                if (addresses.Count > 0)
                {
                    foreach (var addressDTO in addresses)
                    {
                        addressDTO.AgencyId = localAgency.Id;
                        unitOfWork.Repository <AttachmentDTO>().Update(addressDTO);
                    }
                    unitOfWork.Commit();
                }
                unitOfWork.Dispose();
            }
            catch (Exception exception)
            {
                LogUtil.LogError(ErrorSeverity.Fatal,
                                 "InsertAgencyNamesonAddressesandAttachments",
                                 exception.Message + Environment.NewLine + exception.InnerException, "", "");
            }
            #endregion

            return(true);
        }
Пример #6
0
        public SelectList GetAgencies()
        {
            var agncies = new LocalAgencyService(true).GetAll().ToList();

            return(new SelectList(agncies, "Id", "AgencyName"));
        }