public async Task <ActionResult> Remove(int id) { using (HolidayEntryDataProvider dataProvider = new HolidayEntryDataProvider()) { if (!await dataProvider.RemoveItemByIdentityAsync(id)) { throw new Error(this.__ResStr("cantRemove", "Couldn't remove holiday with id {0}")); } return(Reload(null, Reload: ReloadEnum.ModuleParts)); } }
public async Task <ActionResult> AddHoliday_Partial(AddModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } using (HolidayEntryDataProvider dataProvider = new HolidayEntryDataProvider()) { if (!await dataProvider.AddItemAsync(model.GetData())) { ModelState.AddModelError(nameof(AddModel.HolidayDate), this.__ResStr("dup", "An entry for {0} already exists", Formatting.FormatDate(model.HolidayDate))); return(PartialView(model)); } return(FormProcessed(model, this.__ResStr("okSaved", "New holiday saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule)); } }
private GridDefinition GetGridModel() { return(new GridDefinition { SizeStyle = GridDefinition.SizeStyleEnum.SizeToFit, ModuleGuid = Module.ModuleGuid, //SettingsModuleGuid = Module.PermanentGuid, RecordType = typeof(BrowseItem), AjaxUrl = GetActionUrl(nameof(BrowseHolidays_GridData)), DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sort, List <DataProviderFilterInfo> filters) => { using (HolidayEntryDataProvider dataProvider = new HolidayEntryDataProvider()) { DataProviderGetRecords <HolidayEntry> browseItems = await dataProvider.GetItemsAsync(skip, take, sort, filters); return new DataSourceResult { Data = (from s in browseItems.Data select new BrowseItem(Module, s)).ToList <object>(), Total = browseItems.Total }; } }, }); }
public async Task <ActionResult> Process(string request, string extension, int errCount, string token) { LogCall(request, extension); TwilioData twilioConfig = await TwilioConfigDataProvider.GetConfigCondAsync(); if (twilioConfig == null || !twilioConfig.IsConfigured()) { return(RejectResult("Twilio is not configured")); } string authToken = twilioConfig.TestMode ? twilioConfig.TestAuthToken : twilioConfig.LiveAuthToken; IVRConfig ivrConfig = await IVRConfigDataProvider.GetConfigCondAsync(); if (ivrConfig == null || string.IsNullOrWhiteSpace(ivrConfig.PublicKey) || string.IsNullOrWhiteSpace(ivrConfig.PrivateKey)) { return(RejectResult("Config settings not available")); } #if !DEBUG // There is something very peculiar about twilio verification. The initial request will validate correctly, but anything after that will not. // Even if the only difference is CallStatus (tested with a redirect to Request=Main. So I gave up and validate just the first one // and add my own token validation (as argument) if (string.IsNullOrWhiteSpace(token)) { if (!Verify.VerifyTwilio(authToken, twilioConfig.TestMode ? ivrConfig.TestVerificationProcessCallUrl : ivrConfig.LiveVerificationProcessCallUrl)) { return(RejectResult("Twilio verification failed")); } } else { // verify token. If it wasn't generated within the last 5 minutes, reject it. string decryptedToken; RSACrypto.Decrypt(ivrConfig.PrivateKey, token, out decryptedToken); DateTime tokenTime = new DateTime(Convert.ToInt64(decryptedToken)); if (tokenTime < DateTime.UtcNow.AddMinutes(-5)) { return(RejectResult("Token verification failed")); } } #endif if (string.IsNullOrWhiteSpace(request)) { // call log using (CallLogDataProvider callLogDP = new CallLogDataProvider()) { await callLogDP.AddItemAsync(new CallLogEntry { Caller = GetForm("From")?.Truncate(Globals.MaxPhoneNumber), CallerCity = GetForm("CallerCity")?.Truncate(CallLogEntry.MaxCity), CallerCountry = GetForm("CallerCountry")?.Truncate(CallLogEntry.MaxCountry), CallerState = GetForm("CallerState")?.Truncate(CallLogEntry.MaxState), CallerZip = GetForm("CallerZip")?.Truncate(CallLogEntry.MaxZip), To = GetForm("Called")?.Truncate(Globals.MaxPhoneNumber), }); } // check for blocked numbers using (BlockedNumberDataProvider blockedDP = new BlockedNumberDataProvider()) { BlockedNumberEntry blockedEntry = await blockedDP.GetItemAsync(GetForm("From")); if (blockedEntry != null) { return(RejectResult($"Blocked number {GetForm("From")}")); } } // notify (new call) foreach (ExtensionPhoneNumber notifyNumber in ivrConfig.NotificationNumbers) { if (notifyNumber.SendSMS) { SendSMS sendSMS = new SendSMS(); await sendSMS.SendMessageAsync(notifyNumber.PhoneNumber, this.__ResStr("notifySMS", "Incoming call received from {0} ({1}, {2}, {3}, {4}) - {5}", GetForm("Caller"), GetForm("CallerCity"), GetForm("CallerState"), GetForm("CallerZip"), GetForm("CallerCountry"), GetForm("To")), ThrowError : false); } } // determine main action to run request = SECTION_MAIN; using (HolidayEntryDataProvider holidayDP = new HolidayEntryDataProvider()) { HolidayEntry holiday = await holidayDP.GetItemAsync(DateTime.Now.Date.ToUniversalTime()); if (holiday != null) { request = SECTION_MAINHOLIDAY; } else if (ivrConfig.OpeningHours.IsClosed(DateTime.UtcNow)) { request = SECTION_MAINCLOSED; } } } string called; if (!TryGetForm("CalledVia", out called)) { called = GetForm("Called"); } if (ivrConfig.MaxErrors != 0 && errCount >= ivrConfig.MaxErrors) { request = SECTION_MAINGOODBYE; } request = request.ToLower(); using (ScriptDataProvider scriptDP = new ScriptDataProvider()) { ScriptData script = await scriptDP.GetScriptAsync(called); if (script == null) { return(RejectResult($"Script not found for {called}")); } // See if a valid extension was entered if (request == SECTION_GATHEREXTENSION.ToLower()) { string digits; if (TryGetForm("Digits", out digits)) { Extension ext = script.FindExtension(digits); if (ext != null) { extension = ext.Digits; request = SECTION_ENTEREDEXTENSION.ToLower(); // a valid extension was entered, run EnteredExtension instead } } } // find the entry that matches the name and parameters List <ScriptEntry> entries = (from e in script.Scripts where e.Tag == request select e).ToList(); foreach (ScriptEntry entry in entries) { if (entry.Parms.Count > 0) { // check parms bool valid = true; foreach (ScriptParm parm in entry.Parms) { if (GetForm(parm.Name) != parm.Value) { valid = false; break; } } if (!valid) { continue; } } return(await RunEntryAsync(ivrConfig, script, called, extension, entry, errCount)); } throw new InternalError($"Nothing to execute - tag \"{request}\" for {called}"); } }