public async Task <IActionResult> NewCallPriority() { var model = new NewCallPriorityView(); model.CallPriority = new DepartmentCallPriority(); model.AlertSounds = model.AudioType.ToSelectListInt(); return(View(model)); }
public async Task <IActionResult> NewCallPriority(NewCallPriorityView 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.DepartmentId == DepartmentId && x.IsDeleted == false)) { 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 (priotiries.Any(x => x.Name == model.CallPriority.Name && x.IsDeleted == false)) { model.Message = "ERROR: Cannot have duplicate Call Priority names."; return(View(model)); } if (pushfileToUpload != null && pushfileToUpload.Length > 0) { var extenion = Path.GetExtension(pushfileToUpload.FileName); if (!String.IsNullOrWhiteSpace(extenion)) { extenion = extenion.ToLower(); } if (extenion != ".mp3") { ModelState.AddModelError("pushfileToUpload", string.Format("Audio file type ({0}) is not supported for Push Notifications.", extenion)); } if (pushfileToUpload.Length > 1000000) { ModelState.AddModelError("pushfileToUpload", "Android Push Audio file is too large, must be smaller then 1MB."); } var fileAudioLength = _audioValidatorProvider.GetMp3FileDuration(pushfileToUpload.OpenReadStream()); if (fileAudioLength == null) { ModelState.AddModelError("pushfileToUpload", string.Format("Audio file type ({0}) is not supported for Android Push Notifications. MP3 Files are required.", extenion)); } else if (fileAudioLength != null && fileAudioLength.Value > new TimeSpan(0, 0, 25)) { ModelState.AddModelError("pushfileToUpload", string.Format("Android Push audio file length is longer then 25 seconds. Android 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 (String.IsNullOrWhiteSpace(model.CallPriority.Name)) { ModelState.AddModelError("CallPriority_Name", "You must specify a call priority name"); } if (ModelState.IsValid) { if (alertfileToUpload != null && alertfileToUpload.Length > 0) { byte[] uploadedFile = new byte[alertfileToUpload.OpenReadStream().Length]; alertfileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length); model.CallPriority.ShortNotificationSound = uploadedFile; } if (pushfileToUpload != null && pushfileToUpload.Length > 0) { byte[] uploadedFile = new byte[pushfileToUpload.OpenReadStream().Length]; pushfileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length); model.CallPriority.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; } model.CallPriority.DepartmentId = DepartmentId; await _callsService.SaveCallPriorityAsync(model.CallPriority, cancellationToken); return(RedirectToAction("Types", "Department", new { Area = "User" })); } return(View(model)); }