예제 #1
0
        public async Task <IActionResult> EditCallPriority(int priorityId)
        {
            var model = new EditCallPriorityView();

            model.CallPriority = await _callsService.GetCallPrioritiesByIdAsync(DepartmentId, priorityId, true);

            if (model.CallPriority == null || model.CallPriority.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            model.AlertSounds = model.AudioType.ToSelectListInt();

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> EditCallPriority(EditCallPriorityView model, IFormFile pushfileToUpload, IFormFile iOSPushfileToUpload, IFormFile alertfileToUpload, CancellationToken cancellationToken)
        {
            var priotiries = await _callsService.GetActiveCallPrioritiesForDepartmentAsync(DepartmentId, true);

            if (model.CallPriority.IsDefault && priotiries.Any(x => x.IsDefault && x.DepartmentCallPriorityId != model.CallPriority.DepartmentCallPriorityId))
            {
                model.Message = "ERROR: Can only have 1 default call priorty and there already is a call priority marked as default for your department.";
                return(View(model));
            }

            if (pushfileToUpload != null && pushfileToUpload.Length > 0)
            {
                var extenion = Path.GetExtension(pushfileToUpload.FileName);

                if (!String.IsNullOrWhiteSpace(extenion))
                {
                    extenion = extenion.ToLower();
                }

                if (extenion != "wav")
                {
                    ModelState.AddModelError("pushfileToUpload", string.Format("Audio file type ({0}) is not supported for Push Notifications.", extenion));
                }

                if (pushfileToUpload.Length > 1000000)
                {
                    ModelState.AddModelError("pushfileToUpload", "Push Audio file is too large, must be smaller then 1MB.");
                }

                var fileAudioLength = _audioValidatorProvider.GetWavFileDuration(pushfileToUpload.OpenReadStream());
                if (fileAudioLength == null)
                {
                    ModelState.AddModelError("pushfileToUpload", string.Format("Audio file type ({0}) is not supported for Push Notifications. WAV Files are required.", extenion));
                }
                else if (fileAudioLength != null && fileAudioLength.Value > new TimeSpan(0, 0, 25))
                {
                    ModelState.AddModelError("pushfileToUpload", string.Format("Push audio file length is longer then 25 seconds. Push notification sounds must be 25 seconds or shorter.", extenion));
                }
            }

            if (iOSPushfileToUpload != null && iOSPushfileToUpload.Length > 0)
            {
                var extenion = Path.GetExtension(iOSPushfileToUpload.FileName);

                if (!String.IsNullOrWhiteSpace(extenion))
                {
                    extenion = extenion.ToLower();
                }

                if (extenion != ".caf")
                {
                    ModelState.AddModelError("iOSPushfileToUpload", string.Format("Audio file type ({0}) is not supported for iOS Push Notifications.", extenion));
                }

                if (iOSPushfileToUpload.Length > 1000000)
                {
                    ModelState.AddModelError("iOSPushfileToUpload", "iOS Push Audio file is too large, must be smaller then 1MB.");
                }

                //var fileAudioLength = await _audioValidatorProvider.GetWavFileDuration(pushfileToUpload.OpenReadStream());
                //if (fileAudioLength == null)
                //	ModelState.AddModelError("iOSPushfileToUpload", string.Format("Audio file type ({0}) is not supported for Push Notifications. CAF Files are required.", extenion));
                //else if (fileAudioLength != null && fileAudioLength.Value > new TimeSpan(0, 0, 25))
                //	ModelState.AddModelError("iOSPushfileToUpload", string.Format("iOS Push audio file length is longer then 25 seconds. iOS Push notification sounds must be 25 seconds or shorter.", extenion));
            }

            if (alertfileToUpload != null && alertfileToUpload.Length > 0)
            {
                var extenion = Path.GetExtension(alertfileToUpload.FileName);

                if (!String.IsNullOrWhiteSpace(extenion))
                {
                    extenion = extenion.ToLower();
                }

                if (extenion != "wav")
                {
                    ModelState.AddModelError("alertfileToUpload", string.Format("Audio file type ({0}) is not supported for Alert Notifications.", extenion));
                }

                if (alertfileToUpload.Length > 1000000)
                {
                    ModelState.AddModelError("alertfileToUpload", "Push Audio file is too large, must be smaller then 1MB.");
                }

                var fileAudioLength = _audioValidatorProvider.GetWavFileDuration(alertfileToUpload.OpenReadStream());
                if (fileAudioLength == null)
                {
                    ModelState.AddModelError("alertfileToUpload", string.Format("Audio file type ({0}) is not supported for Browser Alert Notifications. WAV Files are required.", extenion));
                }
                else if (fileAudioLength != null && fileAudioLength.Value > new TimeSpan(0, 0, 5))
                {
                    ModelState.AddModelError("alertfileToUpload", string.Format("Browser alert audio file length is longer then 5 seconds. Push notification sounds must be 5 seconds or shorter.", extenion));
                }
            }

            if (ModelState.IsValid)
            {
                var priority = await _callsService.GetCallPrioritiesByIdAsync(DepartmentId, model.CallPriority.DepartmentCallPriorityId, true);

                priority.Name                    = model.CallPriority.Name;
                priority.Color                   = model.CallPriority.Color;
                priority.IsDefault               = model.CallPriority.IsDefault;
                priority.DispatchPersonnel       = model.CallPriority.DispatchPersonnel;
                priority.DispatchUnits           = model.CallPriority.DispatchUnits;
                priority.ForceNotifyAllPersonnel = model.CallPriority.ForceNotifyAllPersonnel;
                priority.Tone                    = model.CallPriority.Tone;

                if (alertfileToUpload != null && alertfileToUpload.Length > 0)
                {
                    byte[] uploadedFile = new byte[alertfileToUpload.OpenReadStream().Length];
                    alertfileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                    priority.ShortNotificationSound = uploadedFile;
                }

                if (pushfileToUpload != null && pushfileToUpload.Length > 0)
                {
                    byte[] uploadedFile = new byte[pushfileToUpload.OpenReadStream().Length];
                    pushfileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                    priority.PushNotificationSound = uploadedFile;
                }


                if (iOSPushfileToUpload != null && iOSPushfileToUpload.Length > 0)
                {
                    byte[] uploadedFile = new byte[iOSPushfileToUpload.OpenReadStream().Length];
                    iOSPushfileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                    model.CallPriority.IOSPushNotificationSound = uploadedFile;
                }

                await _callsService.SaveCallPriorityAsync(priority, cancellationToken);

                return(RedirectToAction("Types", "Department", new { Area = "User" }));
            }

            return(View(model));
        }