示例#1
0
 private static FileUploadResult Success(VoipUpload file)
 {
     return(new FileUploadResult
     {
         Success = true,
         Data = file
     });
 }
        public VoipUpload DeleteUploadedFile(AudioType audioType, string fileName)
        {
            if (!CRMSecurity.IsAdmin)
            {
                throw CRMSecurity.CreateSecurityException();
            }

            var store  = Global.GetStore();
            var path   = Path.Combine(audioType.ToString().ToLower(), fileName);
            var result = new VoipUpload
            {
                AudioType = audioType,
                Name      = fileName,
                Path      = CommonLinkUtility.GetFullAbsolutePath(store.GetUri(path).ToString())
            };

            if (!store.IsFile("voip", path))
            {
                throw new ItemNotFoundException();
            }
            store.Delete("voip", path);

            var dao     = DaoFactory.VoipDao;
            var numbers = dao.GetNumbers();

            var defAudio = StorageFactory.GetStorage("", "crm").ListFiles("voip", "default/" + audioType.ToString().ToLower(), "*.*", true).FirstOrDefault();

            if (defAudio == null)
            {
                return(result);
            }

            foreach (var number in numbers)
            {
                switch (audioType)
                {
                case AudioType.Greeting:
                    if (number.Settings.GreetingAudio == result.Path)
                    {
                        number.Settings.GreetingAudio = CommonLinkUtility.GetFullAbsolutePath(defAudio.ToString());
                    }
                    break;

                case AudioType.HoldUp:
                    if (number.Settings.HoldAudio == result.Path)
                    {
                        number.Settings.HoldAudio = CommonLinkUtility.GetFullAbsolutePath(defAudio.ToString());
                    }
                    break;

                case AudioType.Queue:
                    var queue = number.Settings.Queue;
                    if (queue != null && queue.WaitUrl == result.Path)
                    {
                        queue.WaitUrl = CommonLinkUtility.GetFullAbsolutePath(defAudio.ToString());
                    }
                    break;

                case AudioType.VoiceMail:
                    if (number.Settings.VoiceMail == result.Path)
                    {
                        number.Settings.VoiceMail = CommonLinkUtility.GetFullAbsolutePath(defAudio.ToString());
                    }
                    break;
                }

                dao.SaveOrUpdateNumber(number);
            }

            return(result);
        }