public ActionResult DetalhadoView(int id, int idIndicador, string data1, string data2) { var views = new ViewsNome(); var dataAtual = DateTime.Now; ViewBag.data1 = String.IsNullOrEmpty(data1) ? new DateTime(dataAtual.Year, dataAtual.Month, 1).ToString() : data1; ViewBag.data2 = String.IsNullOrEmpty(data2) ? new DateTime(dataAtual.Year, dataAtual.Month, 1).AddMonths(1).AddDays(-1).ToString() : data2; string query = "SELECT Tipo,object_id Id,upper(NAME) Nome FROM "; query += "(SELECT 'view' Tipo,object_id,name FROM SYS.views "; query += "union "; query += "SELECT 'procedure' Tipo,object_id,name FROM SYS.procedures) as p "; query += "WHERE object_id = '" + id + "' "; views = db.Database.SqlQuery <ViewsNome>(query).First(); views.Indicador = db.T_Indicadores.Find(idIndicador); if (views.Tipo == "view") { views.Campos = db.Database.SqlQuery <ViewsCampos>("SELECT name Nome FROM sys.columns where object_id = " + id.ToString()).ToList(); } else { views.Campos = Util.QueryAnaliser.GetCamposProcedure(views.Nome); } views.Valores = new string[0, 0]; db.Database.CommandTimeout = 999; if ((data1 != "" && data1 != null) && (data2 != "" && data2 != null)) { views.Valores = QueryAnaliser.GetValores(views.Tipo, views.Nome, data1, data2); } views.Nome = views.Nome.Replace("VW_SGI_" + idIndicador.ToString() + "_", "").Replace("_", " "); //select list itens return(View(views)); }
public List <FuzzySearchResult> GetCustomer(List <string> customerNames, List <BotCustomer> customers) { var qa = new QueryAnaliser(); var fuzzySearchDataofCustomers = customers.Select(x => new FuzzySearchModel { FuzzySearchModelID = x.BotCustomerID, Name = x.Name, KeyWords = x.KeyWords + ", " + x.City }).ToList(); var results = new List <FuzzySearchResult>(); foreach (var item in customerNames) { var reader = new MindReader(fuzzySearchDataofCustomers, 0.5); var result = reader.BotMainSearch(item); if (result.Count != 0) { result = result.DistinctBy(c => c.ID).ToList(); result.Sort(); result = qa.DeleteBadREsults(result); } else { result = reader.BotSecondSearch(item); if (result.Count != 0) { result = result.DistinctBy(c => c.ID).ToList(); result.Sort(); result = qa.DeleteBadREsults(result); } } results.AddRange(result); } results.Sort(); return(results); }
public async Task <HttpResponseMessage> PostMessage(JObject jsonResponce) { DateTime TimeToStartAnswer = DateTime.Now; var telegramResponce = jsonResponce.ToObject <Update>(); Logging.Logger.Debug($"PostMessage message={jsonResponce}"); if (telegramResponce == null) { Logging.Logger.Error("Пустой запрос"); return(new HttpResponseMessage(HttpStatusCode.OK)); } if (telegramResponce.Type == UpdateType.MessageUpdate) { var _Bot = new Telegram.Bot.Api(_token); await _Bot.SendChatActionAsync(telegramResponce.Message.Chat.Id, ChatAction.Typing); if (telegramResponce.Message.Text == null) { await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, "Простите, но я не поняла вас \U0001F614"); } else { try { // кэшируем #region string trimmedLoweredQuery = telegramResponce.Message.Text.ToLower().Trim(QueryAnaliser.splitters); var thisQuery = new BotUserQuery { IsError = 0 }; var mbFunctional = new MallBotFunctional(); var mbDBHelper = new MallBotDBHelper(); var mbApiFunctional = new MallBotApiTelegramFunctional(); string MainCachedItemKey = "MainDataOfBot"; string RadugaCachedItemKey = "RadugaDataOfBot"; MallBotModel MainDataOfBot = null; MallBotModel RadugaDataOfBot = null; var dbMainContext = new MallBotContext(); dbMainContext.Configuration.ProxyCreationEnabled = false; var dbRadugaContext = new MallBotContext(1); dbMainContext.Configuration.ProxyCreationEnabled = false; object MaindataFromCache = MemoryCache.Default.Get(MainCachedItemKey, null); object RadugadataFromCache = MemoryCache.Default.Get(RadugaCachedItemKey, null); if (trimmedLoweredQuery == "update") { if (MaindataFromCache != null) { MemoryCache.Default.Remove(MainCachedItemKey, null); } if (RadugadataFromCache != null) { MemoryCache.Default.Remove(RadugaCachedItemKey, null); } MaindataFromCache = null; RadugadataFromCache = null; } if (MaindataFromCache == null || RadugadataFromCache == null) { List <int?> ids = new List <int?> { 3, 5 }; MainDataOfBot = new MallBotModel(dbMainContext, ids); ids = new List <int?> { 1 }; RadugaDataOfBot = new MallBotModel(dbRadugaContext, ids); string[] TimeOfExpiration = ConfigurationManager.AppSettings["TimeOfExpiration"].ToString().Split(':'); CacheItemPolicy cip = new CacheItemPolicy() { AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddHours(int.Parse(TimeOfExpiration[0])).AddMinutes(int.Parse(TimeOfExpiration[1])).AddSeconds(int.Parse(TimeOfExpiration[2]))) }; MemoryCache.Default.Set(new CacheItem(MainCachedItemKey, (object)MainDataOfBot), cip); MemoryCache.Default.Set(new CacheItem(RadugaCachedItemKey, (object)RadugaDataOfBot), cip); } else { MainDataOfBot = (MallBotModel)MaindataFromCache; RadugaDataOfBot = (MallBotModel)RadugadataFromCache; } #endregion var botUsers = dbMainContext.BotUser.ToList(); var botUser = botUsers.FirstOrDefault(x => x.BotUserTelegramID == telegramResponce.Message.Chat.Id.ToString()); QueryAnaliserResult answer = null; MallBotModel DataOfBot = null; var customers = MainDataOfBot.Customers; customers.AddRange(RadugaDataOfBot.Customers); var IsTutorial = true; if ( #region botUser == null || trimmedLoweredQuery == "place" || trimmedLoweredQuery == "место" || trimmedLoweredQuery == "сменить тц" || trimmedLoweredQuery == "тц" || botUser.CustomerName == "newuser" || trimmedLoweredQuery == "help" && (botUser.CustomerName == "newuser" || botUser.CustomerName == "empty") || trimmedLoweredQuery == "помощь" && (botUser.CustomerName == "newuser" || botUser.CustomerName == "empty") #endregion ) { if (trimmedLoweredQuery == "help" || trimmedLoweredQuery == "помощь") { var message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%priorityhelp%").Text; message = message.Replace("%place%", "/place"); message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); } else { if (botUser == null) { dbMainContext = mbDBHelper.AddBotUser(ulong.Parse(telegramResponce.Message.Chat.Id.ToString()), 2, null, telegramResponce.Message.From.FirstName, telegramResponce.Message.From.LastName, 0, null, "ru_RU", false, dbMainContext); botUser = dbMainContext.BotUser.FirstOrDefault(x => x.BotUserTelegramID == telegramResponce.Message.Chat.Id.ToString()); } botUser.CustomerName = "empty"; if (botUser.LevelTutorial != 4) { botUser.LevelTutorial = 0; } botUser.ModifiedDate = DateTime.Now; dbMainContext.SaveChanges(); var message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%mallselect%").Text; message = message.Replace("%mall1%", "1. " + customers[0].Name + " " + customers[0].City); message = message.Replace("%mall2%", "2. " + customers[1].Name + " " + customers[1].City); message = message.Replace("%mall3%", "3. " + customers[2].Name + " " + customers[2].City); message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); } } else { if (botUser.CustomerName == "empty") { var qa = new QueryAnaliser(); var res = mbFunctional.SearchCustomer(qa.NormalizeQuery(telegramResponce.Message.Text), customers); if (res.Count != 0) { var findedCustomer = customers.FirstOrDefault(x => x.CustomerID == res[0].ID); var message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%mallselectsucces%").Text; message = message.Replace("%findedmall%", findedCustomer.Name + " " + findedCustomer.City); message = message.Replace("%place%", "/place"); message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); botUser.CustomerName = res[0].Name; dbMainContext.SaveChanges(); if (botUser.LevelTutorial != 4) { answer = await mbApiFunctional.doTutorial(botUser, telegramResponce.Message.Text, _Bot, telegramResponce.Message.Chat.Id, dbMainContext, MainDataOfBot); } } else { var message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%mallselectfail%").Text; message = message.Replace("%notfindedmall%", telegramResponce.Message.Text); message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); } } else { if (botUser.CustomerName == RadugaDataOfBot.Customers[0].Name) { DataOfBot = RadugaDataOfBot; DataOfBot.Texts = MainDataOfBot.Texts; } else { DataOfBot = mbDBHelper.SelectData(MainDataOfBot, botUser, customers); } // Блок для описания команд if (trimmedLoweredQuery.Contains("testfunc")) // команды для разработчиков { await mbApiFunctional.doDebelopersCommands(trimmedLoweredQuery, DataOfBot, _Bot, telegramResponce.Message.Chat.Id); } else // команды для пользователей { var message = ""; switch (trimmedLoweredQuery) { case "start": message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%start%").Text; message = message.Replace("%help%", "/help"); message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "update": message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%cacheupdate%").Text; message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "clear": botUser.LevelTutorial = 0; botUser.CustomerName = "newuser"; botUser.ModifiedDate = DateTime.Now; dbMainContext.SaveChanges(); message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%clear%").Text; message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "skip": botUser.LevelTutorial = 4; botUser.ModifiedDate = DateTime.Now; dbMainContext.SaveChanges(); message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%skip%").Text; message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "привет": case "hello": case "здравствуйте": case "пряффки": case "hi": message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%hello%").Text; message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "пока": case "до свидания": case "спасибо": case "покеда": case "досвидули": case "большоеспасибо": case "прощай": message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%thkx%").Text; message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "помощь": case "help": case "как это работает": case "хелп": message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%help%").Text; message = message.Replace("%place%", "/place"); message = message.Replace("%tutorial%", "/tutorial"); message = message.Replace("%help%", "/help"); message = BotTextHelper.SmileCodesReplace(message); await _Bot.SendTextMessageAsync(telegramResponce.Message.Chat.Id, message); break; case "что делать": case "tutorial": case "обучение": case "туториал": answer = await mbApiFunctional.doTutorial(botUser, telegramResponce.Message.Text, _Bot, telegramResponce.Message.Chat.Id, dbMainContext, DataOfBot, true); break; default: if (botUser.LevelTutorial != 4) { answer = await mbApiFunctional.doTutorial(botUser, telegramResponce.Message.Text, _Bot, telegramResponce.Message.Chat.Id, dbMainContext, DataOfBot); } else { var mbFunctionalAnalizer = new MallBotFunctionalAnalizeTelegramHelper(); answer = await mbFunctionalAnalizer.AnaliseDoWorkResult(telegramResponce.Message.Text, telegramResponce.Message.Chat.Id, DataOfBot, _Bot, botUser); IsTutorial = false; } break; } } } } //пишем в базу запрос if (botUser != null) { if (DataOfBot == null) { mbDBHelper.AddBotQuery(botUser, ulong.Parse(telegramResponce.Message.Chat.Id.ToString()), 2, answer, telegramResponce.Message.Text, IsTutorial, TimeToStartAnswer, thisQuery); } else { mbDBHelper.AddBotQuery(botUser, ulong.Parse(telegramResponce.Message.Chat.Id.ToString()), 2, answer, telegramResponce.Message.Text, IsTutorial, TimeToStartAnswer, thisQuery); } } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("ok"), }); } catch (Exception exc) { Logging.Logger.Error(exc); return(new HttpResponseMessage(HttpStatusCode.OK)); } } } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("ok"), }); }
public ActionResult ExportarExcel(int id, int idIndicador, string data1, string data2) { var views = new ViewsNome(); var dataAtual = DateTime.Now; ViewBag.data1 = String.IsNullOrEmpty(data1) ? new DateTime(dataAtual.Year, dataAtual.Month, 1).ToString() : data1; ViewBag.data2 = String.IsNullOrEmpty(data2) ? new DateTime(dataAtual.Year, dataAtual.Month, 1).AddMonths(1).AddDays(-1).ToString() : data2; string query = "SELECT Tipo,object_id Id,upper(NAME) Nome FROM "; query += "(SELECT 'view' Tipo,object_id,name FROM SYS.views "; query += "union "; query += "SELECT 'procedure' Tipo,object_id,name FROM SYS.procedures) as p "; query += "WHERE object_id = '" + id + "' "; views = db.Database.SqlQuery <ViewsNome>(query).First(); views.Indicador = db.T_Indicadores.Find(idIndicador); if (views.Tipo == "view") { views.Campos = db.Database.SqlQuery <ViewsCampos>("SELECT name Nome FROM sys.columns where object_id = " + id.ToString()).ToList(); } else { views.Campos = Util.QueryAnaliser.GetCamposProcedure(views.Nome); } views.Valores = new string[0, 0]; if ((data1 != "" && data1 != null) && (data2 != "" && data2 != null)) { views.Valores = QueryAnaliser.GetValores(views.Tipo, views.Nome, data1, data2); } views.Nome = views.Nome.Replace("VW_SGI_" + idIndicador.ToString() + "_", "").Replace("_", " "); var products = new System.Data.DataTable(views.Nome); //Adiciona colunas for (int i = 0; i < views.Campos.Count; i++) { products.Columns.Add(views.Campos[i].Nome, typeof(string)); } //Preenche valores string[] valores; for (int ln = 0; ln < views.Valores.GetLength(0); ln++) { valores = new string[views.Campos.Count]; for (int col = 0; col < views.Campos.Count; col++) { valores[col] = views.Valores[ln, col]; } products.Rows.Add(valores); } var grid = new GridView(); grid.DataSource = products; grid.DataBind(); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment; filename=" + views.Nome + DateTime.Now.Date.ToString("ddMMyyyy") + ".xls"); Response.ContentType = "application/vnd.ms-excel"; Response.Charset = ""; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); return(View()); }
public async Task <HttpResponseMessage> PostMessage(JObject jsonResponce) { var vkResponce = jsonResponce.ToObject <VKResponce>(); Logging.Logger.Debug($"PostMessage message={jsonResponce}"); if (vkResponce == null) { Logging.Logger.Error("Пустой запрос"); return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (vkResponce.GroupId != 127789119) { Logging.Logger.Error($"Группа с идентификатором {vkResponce.GroupId} не поддерживается ботом MOLOKO"); return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (vkResponce.Type == "confirmation") { if (vkResponce.GroupId == 127789119) { return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("38ffe9fe", Encoding.UTF8, "text/html") }); } } if (vkResponce.Type == "message_new") { try { var vk = new VK("9a50a582a63ff80cb9d03a5333984e3932dc13cc6ec150a1cf0026bef7c273084b3e0a55c7ebbc42f08f4"); var vkMessage = jsonResponce["object"].ToObject <VKMessage>(); List <BotCustomer> customers = null; string CachedItemKey = "Customers"; var dbContext = new MallBotSearchContext(); object dataFromCache = MemoryCache.Default.Get(CachedItemKey, null); if (dataFromCache == null) { customers = dbContext.BotCustomer.ToList(); string[] TimeOfExpiration = ConfigurationManager.AppSettings["TimeOfExpiration"].ToString().Split(':'); CacheItemPolicy cip = new CacheItemPolicy() { AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddHours(int.Parse(TimeOfExpiration[0])).AddMinutes(int.Parse(TimeOfExpiration[1])).AddSeconds(int.Parse(TimeOfExpiration[2]))) }; MemoryCache.Default.Set(new CacheItem(CachedItemKey, customers), cip); } else { customers = (List <BotCustomer>)dataFromCache; } var searchHerper = new SearchHelper(); var analizer = new QueryAnaliser(); var findedCustomers = searchHerper.GetCustomer(analizer.NormalizeQuery(vkMessage.Body), customers); string message = "Ура! :-) Я нашла: \r\n \r\n"; if (findedCustomers.Count != 0) { foreach (var item in findedCustomers) { var temp = customers.FirstOrDefault(x => x.BotCustomerID == item.ID); if (!string.IsNullOrWhiteSpace(temp.VKGroupName) && !string.IsNullOrWhiteSpace(temp.Name)) { message += "« " + temp.Name + " » \r\n vk.me/" + temp.VKGroupName + "\r\n \r\n"; } } } else { message = "к сожалению я ничего не нашла 3("; } AsyncHelper.RunSync(() => vk.SendMessage(vkMessage.UserId, message)); } catch (Exception exc) { Logging.Logger.Error(exc); return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("ВСЕ ОЧЕНЬ ПЛОХО!"), }); } } if (vkResponce.Type == "group_join") { return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("ok"), }); } Logging.Logger.Error(jsonResponce.ToString()); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public async Task <HttpResponseMessage> PostMessage(JObject Responce) { DateTime TimeToStartAnswer = DateTime.Now; FacebookResponce facebookeResponce = Responce.ToObject <FacebookResponce>(); if (facebookeResponce == null) { Logging.Logger.Error("Facebook. Empty request!"); return(new HttpResponseMessage(HttpStatusCode.OK)); } if (facebookeResponce.Object != ObjectTypes.page) { Logging.Logger.Error($"Facebook. It's not a text message!"); return(new HttpResponseMessage(HttpStatusCode.OK)); } else { var FacebookBot = new FacebookApiHelper(_token); var thisQuery = new BotUserQuery { IsError = 0 }; await FacebookBot.SendAction(facebookeResponce.entry[0].messaging[0].sender.Id, SenderActionType.typing_on, thisQuery); if (facebookeResponce.entry[0].messaging[0].message.text != null) // пришло тектовое сообщение { try { string trimmedLoweredQuery = facebookeResponce.entry[0].messaging[0].message.text.ToLower().Trim(QueryAnaliser.splitters); var mbFunctional = new MallBotFunctional(); var mbDBHelper = new MallBotDBHelper(); var mbApiFunctional = new MallBotFacebookApiFunctional(); // Кэширование #region string MainCachedItemKey = "MainDataOfBot"; string RadugaCachedItemKey = "RadugaDataOfBot"; MallBotModel MainDataOfBot = null; MallBotModel RadugaDataOfBot = null; var dbMainContext = new MallBotContext(); dbMainContext.Configuration.ProxyCreationEnabled = false; var dbRadugaContext = new MallBotContext(1); dbMainContext.Configuration.ProxyCreationEnabled = false; object MaindataFromCache = MemoryCache.Default.Get(MainCachedItemKey, null); object RadugadataFromCache = MemoryCache.Default.Get(RadugaCachedItemKey, null); if (trimmedLoweredQuery == "update") { if (MaindataFromCache != null) { MemoryCache.Default.Remove(MainCachedItemKey, null); } if (RadugadataFromCache != null) { MemoryCache.Default.Remove(RadugaCachedItemKey, null); } MaindataFromCache = null; RadugadataFromCache = null; } if (MaindataFromCache == null || RadugadataFromCache == null) { List <int?> ids = new List <int?> { 3, 5 }; MainDataOfBot = new MallBotModel(dbMainContext, ids); ids = new List <int?> { 1 }; RadugaDataOfBot = new MallBotModel(dbRadugaContext, ids); string[] TimeOfExpiration = ConfigurationManager.AppSettings["TimeOfExpiration"].ToString().Split(':'); CacheItemPolicy cip = new CacheItemPolicy() { AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddHours(int.Parse(TimeOfExpiration[0])).AddMinutes(int.Parse(TimeOfExpiration[1])).AddSeconds(int.Parse(TimeOfExpiration[2]))) }; MemoryCache.Default.Set(new CacheItem(MainCachedItemKey, (object)MainDataOfBot), cip); MemoryCache.Default.Set(new CacheItem(RadugaCachedItemKey, (object)RadugaDataOfBot), cip); } else { MainDataOfBot = (MallBotModel)MaindataFromCache; RadugaDataOfBot = (MallBotModel)RadugadataFromCache; } #endregion var botUsers = dbMainContext.BotUser.ToList(); var botUser = botUsers.FirstOrDefault(x => x.BotUserFacebookID == facebookeResponce.entry[0].messaging[0].sender.Id); QueryAnaliserResult answer = null; MallBotModel DataOfBot = null; var customers = MainDataOfBot.Customers; customers.AddRange(RadugaDataOfBot.Customers); var IsTutorial = true; // Блок для описания команд. Приоритет 1. Наивысший if ( #region botUser == null || trimmedLoweredQuery == "place" || trimmedLoweredQuery == "место" || trimmedLoweredQuery == "сменить тц" || trimmedLoweredQuery == "тц" || trimmedLoweredQuery == "mall" || botUser.CustomerName == "newuser" || trimmedLoweredQuery == "help" && (botUser.CustomerName == "newuser" || botUser.CustomerName == "empty") || trimmedLoweredQuery == "помощь" && (botUser.CustomerName == "newuser" || botUser.CustomerName == "empty") #endregion ) { string message = ""; switch (trimmedLoweredQuery) { case "help": case "помощь": message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%priorityhelp%").Text; if (botUser.Locale == "ru_RU") { message = message.Replace("%place%", "место"); } else { message = message.Replace("%place%", "place"); } await FacebookBot.SendMessage(facebookeResponce.entry[0].messaging[0].sender.Id, message, thisQuery); break; default: if (botUser == null) { FacebookUser facebookUser = await FacebookBot.GetUsersInformation(facebookeResponce.entry[0].messaging[0].sender.Id, thisQuery); byte gender = 0; if (facebookUser.gender == "male") { gender = 2; } else { gender = 1; } dbMainContext = mbDBHelper.AddBotUser(ulong.Parse(facebookeResponce.entry[0].messaging[0].sender.Id), 3, null, facebookUser.first_name, facebookUser.last_name, gender, null, facebookUser.locale, false, dbMainContext); string senderId = facebookeResponce.entry[0].messaging[0].sender.Id; botUser = dbMainContext.BotUser.FirstOrDefault(x => x.BotUserFacebookID == senderId); } message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%mallselect%").Text; message = message.Replace("%mall1%", "1. " + customers[0].Name + " " + customers[0].City); message = message.Replace("%mall2%", "2. " + customers[1].Name + " " + customers[1].City); message = message.Replace("%mall3%", "3. " + customers[2].Name + " " + customers[2].City); string[] quickReplies = { customers[0].Name, customers[1].Name, customers[2].Name }; await FacebookBot.SendMessage(facebookeResponce.entry[0].messaging[0].sender.Id, message, thisQuery, quickReplies); botUser.CustomerName = "empty"; if (botUser.LevelTutorial != 4) { botUser.LevelTutorial = 0; } botUser.ModifiedDate = DateTime.Now; dbMainContext.SaveChanges(); break; } } else { if (botUser.CustomerName == "empty") { var qa = new QueryAnaliser(); var res = mbFunctional.SearchCustomer(qa.NormalizeQuery(facebookeResponce.entry[0].messaging[0].message.text), customers); if (res.Count != 0) { var findedCustomer = customers.FirstOrDefault(x => x.CustomerID == res[0].ID); var message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%mallselectsucces%").Text; message = message.Replace("%findedmall%", findedCustomer.Name + ", " + findedCustomer.City); if (botUser.Locale == "ru_RU") { message = message.Replace("%place%", "место"); } else { message = message.Replace("%place%", "place"); } await FacebookBot.SendMessage(facebookeResponce.entry[0].messaging[0].sender.Id, message, thisQuery); botUser.CustomerName = res[0].Name; dbMainContext.SaveChanges(); if (botUser.LevelTutorial != 4) { answer = await mbApiFunctional.doTutorial(botUser, facebookeResponce.entry[0].messaging[0].message.text, FacebookBot, facebookeResponce.entry[0].messaging[0].sender.Id, dbMainContext, MainDataOfBot, thisQuery); } } else { var message = MainDataOfBot.Texts.FirstOrDefault(x => x.Locale == botUser.Locale && x.Key == "%mallselectfail%").Text; message = message.Replace("%notfindedmall%", facebookeResponce.entry[0].messaging[0].message.text); await FacebookBot.SendMessage(facebookeResponce.entry[0].messaging[0].sender.Id, message, thisQuery); } } else { if (botUser.CustomerName == RadugaDataOfBot.Customers[0].Name) { DataOfBot = RadugaDataOfBot; DataOfBot.Texts = MainDataOfBot.Texts; } else { DataOfBot = mbDBHelper.SelectData(MainDataOfBot, botUser, customers); } if (trimmedLoweredQuery.Contains("testfunc")) // команды для разработчиков { await mbApiFunctional.doDebelopersCommands(trimmedLoweredQuery, DataOfBot, FacebookBot, facebookeResponce.entry[0].messaging[0].sender.Id, thisQuery); } else { // Блок для описания команд. Приоритет 0 // команды для пользователей await mbApiFunctional.doUsersCommands(trimmedLoweredQuery, DataOfBot, FacebookBot, facebookeResponce.entry[0].messaging[0].sender.Id, botUser, thisQuery, dbMainContext); } } } if (botUser != null) { if (DataOfBot == null) { mbDBHelper.AddBotQuery(botUser, ulong.Parse(facebookeResponce.entry[0].messaging[0].sender.Id.ToString()), 3, answer, facebookeResponce.entry[0].messaging[0].message.text, IsTutorial, TimeToStartAnswer, thisQuery); } else { mbDBHelper.AddBotQuery(botUser, ulong.Parse(facebookeResponce.entry[0].messaging[0].sender.Id.ToString()), 3, answer, facebookeResponce.entry[0].messaging[0].message.text, IsTutorial, TimeToStartAnswer, thisQuery); } } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("ok"), }); } catch (Exception exc) { Logging.Logger.Error("Facebook" + exc); return(new HttpResponseMessage(HttpStatusCode.OK)); } } else { await FacebookBot.SendMessage(facebookeResponce.entry[0].messaging[0].sender.Id, "Sorry, but i didn't understand you \U0001F614", thisQuery); } } return(new HttpResponseMessage(HttpStatusCode.OK)); }