private bool InsertNewBotToDb(Model.HostInfo hostInfo, bool IsServerVersion = false) { DbContext = new MarketBotDbContext(); if (hostInfo != null && hostInfo.Token != null && hostInfo.BotName != null && hostInfo.UrlWebHook != null && hostInfo.OwnerChatId > 0) { var spl = hostInfo.Token.Split(':'); int chat_id = Convert.ToInt32(spl[0]); BotInfo botInfo = new BotInfo { Token = hostInfo.Token, Name = hostInfo.BotName, WebHookUrl = hostInfo.UrlWebHook, Timestamp = DateTime.Now, HomeVersion = !IsServerVersion, ServerVersion = IsServerVersion, ChatId = chat_id, OwnerChatId = hostInfo.OwnerChatId }; DbContext.BotInfo.Add(botInfo); DbContext.SaveChanges(); var conf = new Configuration { BotInfoId = botInfo.Id, VerifyTelephone = false, OwnerPrivateNotify = false, Delivery = true, Pickup = false, ShipPrice = 0, FreeShipPrice = 0, CurrencyId = 1, BotBlocked = false }; DbContext.Configuration.Add(conf); DbContext.SaveChanges(); Company company = new Company { Instagram = "https://www.instagram.com/", Vk = "https://www.vk.com/", Chanel = "https://t.me/", Chat = "https://t.me/" }; DbContext.Company.Add(company); DbContext.SaveChanges(); return(true); } else { return(false); } }
public IActionResult Unistall() { try { string read = ReadFile("HostInfo.json"); Model.HostInfo hostInfo = JsonConvert.DeserializeObject <Model.HostInfo>(read); DetachDatabase(hostInfo.DbName); DeleteDatabaseFile(hostInfo.DbName); hostInfo.BotName = null; hostInfo.DbConnectionString = null; hostInfo.Token = null; hostInfo.IsFree = true; hostInfo.DbName = null; hostInfo.UrlWebHook = null; hostInfo.Blocked = false; WriteFile("HostInfo.json", JsonConvert.SerializeObject(hostInfo)); return(Ok()); } catch (Exception e) { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "Ok", "false" }, { "Result", e.Message } }; return(Json(dictionary)); } }
public IActionResult Install([FromBody] Model.HostInfo hostInfo) { // string dbname = hostInfo.BotName + "Db"; HostInfo = new Model.HostInfo(); try { if (CreateDb(hostInfo.DbName)) { string read = ReadFile("HostInfo.json"); if (read != null) { HostInfo = JsonConvert.DeserializeObject <Model.HostInfo>(read); } HostInfo.CreateTimeStamp = DateTime.Now; HostInfo.BotName = hostInfo.BotName; HostInfo.IsDemo = hostInfo.IsDemo; HostInfo.IsFree = false; HostInfo.Token = hostInfo.Token; HostInfo.UrlWebHook = hostInfo.UrlWebHook; HostInfo.DbName = hostInfo.DbName; HostInfo.OwnerChatId = hostInfo.OwnerChatId; if (hostInfo.DbConnectionString == null) { HostInfo.DbConnectionString = String.Format("Server=localhost;Database={0};Integrated Security = FALSE;Trusted_Connection = True;", HostInfo.DbName); } WriteFile("connection.json", HostInfo.DbConnectionString); WriteFile("HostInfo.json", JsonConvert.SerializeObject(HostInfo)); InsertNewBotToDb(HostInfo, true); Dictionary <string, string> dictionary = new Dictionary <string, string> { { "name", HostInfo.BotName } }; WriteFile("name.json", JsonConvert.SerializeObject(dictionary)); dictionary.Clear(); dictionary.Add("Ok", "true"); dictionary.Add("Result", JsonConvert.SerializeObject(HostInfo)); return(Json(dictionary)); } else { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "Ok", "false" }, { "Result", "" } }; return(Json(dictionary)); } } catch (Exception e) { Dictionary <string, string> dictionary = new Dictionary <string, string> { { "Ok", "false" }, { "Result", e.Message } }; return(Json(dictionary)); } finally { if (DbContext != null) { DbContext.Dispose(); } if (sqlConnection != null) { sqlConnection.Dispose(); } } }
public IActionResult GetInfo() { Model.HostInfo hostInfo = JsonConvert.DeserializeObject <Model.HostInfo>(ReadFile("HostInfo.json")); return(Json(hostInfo)); }