public IActionResult Login(int gid, string pass) { using var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var count = context.Groups.Count(i => i.Id == gid && i.Pass == pass); if (count > 0) { var countInList = context.GroupsList.Count(i => i.GroupId == gid && i.UserId == userData.Id); if (countInList >= 1) { return(Redirect($"/Group/Index?gid={gid}")); } var record = new GroupList { GroupId = gid, Owner = 0, UserId = userData.Id }; context.GroupsList.Add(record); context.SaveChanges(); return(Redirect($"/Group/Index?gid={gid}")); } return(View()); }
public IActionResult Create(int?gid, string name, string pass) { using var context = ContextBuilder.Context; SessionKeeper.Get(this, false); ViewData["Title"] = "Редактирование группы"; var userData = SessionKeeper.Get(this); if (gid == null) { ViewData["Title"] = "Создание группы"; var r = new Random(); var g = r.Next(0, 10000000).ToString(); context.Groups.Add(new Group { Name = g }); context.SaveChanges(); var created = context.Groups.First(i => i.Name == g); created.Name = "Новая группа"; context.Groups.Update(created); context.GroupsList.Add(new GroupList { GroupId = created.Id, Owner = 1, UserId = userData.Id }); context.SaveChanges(); ViewData["gid"] = created.Id; ViewData["gName"] = created.Name; ViewData["gPass"] = created.Pass; } else { var group = context.Groups.First(i => i.Id == gid); var allowed = context.GroupsList.Count(i => i.GroupId == gid && i.UserId == userData.Id && i.Owner > 0); if (allowed < 1) { return(Redirect("/Home/Index")); } // Изменение полей при запросе if (name != null && pass != null) { group.Name = name.TrimName().MakeSafe(); group.Pass = pass; context.Groups.Update(group); context.SaveChanges(); } ViewData["gid"] = gid; ViewData["gName"] = group.Name; ViewData["gPass"] = group.Pass; } return(View()); }
// GET public IActionResult Remove(int?gid) { using var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0 || gid != null) { return(Redirect("/Home/Index")); } var record = context.GroupsList.First(i => i.Id == gid); if (record.Owner <= 0) { return(Redirect("/User/Profile")); } var order0 = context.GroupsList.Where(i => i.GroupId == gid); var order1 = context.Groups.Where(i => i.Id == gid); foreach (var g in order0) { context.GroupsList.Remove(g); } foreach (var g in order1) { context.Groups.Remove(g); } context.SaveChanges(); return(Redirect("/User/Profile")); }
public IActionResult Index(int id) { var context = ContextBuilder.Context; // Проверка на доступность пользователю var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var ask = context.Asks.First(i => i.Id == id); if (context.Tests.Count(i => i.Id == ask.TestId && i.OwnerId == userData.Id) < 1) { return(Redirect("/Home/Index")); } var answers = new List <Answer>(context.Answers.Where(i => i.AskId == ask.Id)); ViewData["ask"] = ask; ViewData["answers"] = answers; return(View()); }
public IActionResult LoadAvatar(ImageData imageData) { var context = ContextBuilder.Context; if (imageData.Image == null) { return(Redirect("/User/Profile")); } byte[] data = null; using (var binaryReader = new BinaryReader(imageData.Image.OpenReadStream())) { data = binaryReader.ReadBytes((int)imageData.Image.Length); } var userdata = SessionKeeper.Get(this); var name = userdata.Name; var pass = userdata.Password; var usr = context.Users.First(i => i.Name == name && i.Pass == pass); usr.Photo = data; context.Users.Update(usr); context.SaveChanges(); return(Redirect("/User/Profile")); }
public IActionResult LoadPhoto(ImageData imageData, int id) { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var ask = context.Asks.First(i => i.Id == id); if (context.Tests.Count(i => i.Id == ask.TestId && i.OwnerId == userData.Id) < 1) { return(Redirect("/Home/Index")); } if (imageData.Image == null) { return(Redirect($"/Ask/Index?id={ask.Id}")); } byte[] data = null; using (var binaryReader = new BinaryReader(imageData.Image.OpenReadStream())) { data = binaryReader.ReadBytes((int)imageData.Image.Length); } ask.Photo = data; context.Asks.Update(ask); context.SaveChanges(); return(Redirect($"/Ask/Index?id={ask.Id}")); }
public IActionResult AnswerAdd(int id) { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var ask = context.Asks.First(i => i.Id == id); if (context.Tests.Count(i => i.Id == ask.TestId && i.OwnerId == userData.Id) < 1) { return(Redirect("/Home/Index")); } var answer = new Answer { Value = "Вариант ответа", Impact = 0, AskId = ask.Id, TestId = ask.TestId }; context.Answers.Add(answer); context.SaveChanges(); return(Redirect($"/Ask/Index?id={id}")); }
private DataTable GetImbaseTables() { using (SessionKeeper keeper = new SessionKeeper()) { IDBObjectCollection objCollection = keeper.Session.GetObjectCollection(1069); ConditionStructure[] conditions = new ConditionStructure[] { }; object[] columns = new object[] { ObligatoryObjectAttributes.F_OBJECT_ID, "Наименование" }; object[] sortColumns = new object[] { ObligatoryObjectAttributes.F_OBJECT_ID, "Наименование", }; SortOrders[] order = new SortOrders[] { SortOrders.ASC, SortOrders.ASC }; DBRecordSetParams pars = new DBRecordSetParams(conditions, columns, sortColumns, order, 0, null, QueryConsts.All, true, "MyIMBASE_TableSelection"); DataTable dt = objCollection.Select(pars); return(dt); } }
public IActionResult LoadPhoto(ImageData imageData, string Id) { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var id = int.Parse(Id); var tst = context.Tests.First(i => i.Id == id && i.OwnerId == userData.Id); if (imageData.Image == null) { return(Redirect($"/Test/Create?id={id}")); } byte[] data = null; using (var binaryReader = new BinaryReader(imageData.Image.OpenReadStream())) { data = binaryReader.ReadBytes((int)imageData.Image.Length); } tst.Photo = data; context.Tests.Update(tst); context.SaveChanges(); return(Redirect($"/Test/Create?id={id}")); }
public IActionResult Kick(int?gid, int usr) { using var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0 || gid is null) { return(Redirect("/Home/Index")); } if (usr == userData.Id) { return(Redirect($"/Group/Create?gid={gid}")); } var countInList = context.GroupsList.Count(i => i.GroupId == gid && i.UserId == userData.Id && i.Owner > 0); if (countInList < 1) { return(Redirect($"/Group/Create?gid={gid}")); } var record = context.GroupsList.First(i => i.UserId == usr && i.UserId != userData.Id); context.GroupsList.Remove(record); context.SaveChanges(); return(Redirect($"/Group/Create?gid={gid}")); }
public IActionResult Index() { SessionKeeper.Get(this); using var context = ContextBuilder.Context; var tests = new List <Test>(context.Tests.Where(r => r.Show > 0).Take(MainTestsCount)); return(View(tests)); }
public static void LoadSessions() { if (File.Exists(SaveFilePath)) { string json = File.ReadAllText(SaveFilePath); sessionKeeper = JsonUtility.FromJson <SessionKeeper>(json); } }
public TestContent GetTest(int id, string user, string sessionkey) { try { var usrData = SessionKeeper.Get(user, sessionkey); var test = FreqRequests.GetTestContent(id, usrData.Id); return(test); } catch { return(TestContent.Error); } }
public ResultContent SendTest(int tid, int[] AskId, int[] AnswerId, string user, string sessionkey) { try { var usrData = SessionKeeper.Get(user, sessionkey); var result = FreqRequests.GetResultContent(tid, AskId, AnswerId, usrData.Id); return(result); } catch { return(ResultContent.Error); } }
public IActionResult Logout(string name, string code) { Response.Cookies.Delete("Name"); Response.Cookies.Delete("SessionKey"); if (name == null || code == null) { return(Redirect("/Home/Index")); } SessionKeeper.StopSession(name, code); return(Redirect("/Home/Index")); }
// GET public IActionResult Index() { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); var id = int.Parse(Request.Query["id"]); var test = context.Tests.First(i => i.Id == id); ViewData["test"] = test; ViewData["Title"] = $"Тест - {test.Name}"; ViewData["tAllow"] = false; ViewData["tries"] = 0; // Проверка на количество попыток var triesCount = context.Results.Count(i => i.UserId == userData.Id); ViewData["tries"] = triesCount; if (test.Tries > 0 && test.Tries - triesCount < 1) { return(View()); } // Проверка на наличие в группе var groupCount = context.GroupsList.Count(i => i.UserId == userData.Id && i.GroupId == test.Limit); if (groupCount < 1 && test.Limit > 0) { return(View()); } if (userData.Id < 0 && test.SaveResults > 0) { return(View()); } // Отображение body в случае прохождения проверок ViewData["tAllow"] = true; var asks = new List <Ask>(); asks.AddRange(context.Asks.Where(i => i.TestId == test.Id)); var answers = new List <Answer>(); answers.AddRange(context.Answers.Where(i => i.TestId == test.Id)); ViewData["tAsks"] = asks; ViewData["tAnswers"] = answers; ViewData["Title"] = $"Тест - {test.Name}"; return(View()); }
public SessionContent CreateSession(string name, string password) { try { var code = SessionKeeper.AddSession(name, password); return(code == null ? SessionContent.Error : new SessionContent { Name = name, SessionKey = code }); } catch { return(SessionContent.Error); } }
private void Fill_ImbaseTable(long newSelectedID, DataTable dt) { using (SessionKeeper keeper = new SessionKeeper()) { DataSet ds; DataTable tb2; DataRow row1; try { ds = TableLoadHelper.GetTables(keeper.Session, newSelectedID, true); tb2 = ds.Tables[Intermech.Imbase.Consts.IMS_DATA]; } catch (Exception ex) { MessageBox.Show("Таблицы с tableID = " + newSelectedID.ToString() + " не найдено"); throw ex; } Dictionary <string, Guid> columnNamesAndGuids = new Dictionary <string, Guid>(); byte columnsCount = Convert.ToByte(dt.Columns.Count); // количество колонок в табллице List <string> columnNamesinExcel = new List <string>(columnsCount); for (byte i = 0; i < columnsCount; i++) { columnNamesinExcel.Add(dt.Columns[i].ColumnName); // создали список наименований колонок в таблице columnNamesAndGuids.Add(dt.Columns[i].ColumnName, MetaDataHelper.GetAttributeByTypeNameGuid(dt.Columns[i].ColumnName)); // имя аттрибута и его Guid } string tempGuid; string tempName; foreach (var item in dt.AsEnumerable()) // по всем рядкам { row1 = tb2.NewRow(); for (byte i = 0; i < columnsCount; i++) // по каждой колонке { tempName = columnNamesinExcel[i]; tempGuid = "" + columnNamesAndGuids[tempName] + ""; row1.SetField(tempGuid, item[tempName].ToString()); } tb2.Rows.Add(row1); tb2.AcceptChanges(); } TableLoadHelper.StoreData(keeper.Session, newSelectedID, ds, keeper.Session.GetCustomService(typeof(Intermech.Interfaces.Imbase.ITablesIndexer)) as Intermech.Interfaces.Imbase.ITablesIndexer); } }
public IActionResult Find(string name) { using var context = ContextBuilder.Context; SessionKeeper.Get(this, false); ViewBag.Groups = null; if (name is null) { return(View()); } var groups = new List <Group>(context.Groups.Where(i => i.Name == name)); ViewBag.Groups = groups; return(View()); }
public IActionResult Remove() { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var id = int.Parse(Request.Query["id"]); var tst = context.Tests.First(i => i.Id == id && i.OwnerId == userData.Id); context.Tests.Remove(tst); context.SaveChanges(); return(Redirect("/User/Profile")); }
public IActionResult Index(int?id) { var context = ContextBuilder.Context; SessionKeeper.Get(this); if (id is null) { return(Redirect("/User/Profile")); } var user = context.Users.First(i => i.Id == id); var groupslist = new List <GroupList>(context.GroupsList.Where(i => i.UserId == id)); var groups = groupslist.Select(g => context.Groups.First(i => i.Id == g.GroupId)).ToList(); ViewData["user"] = user; ViewData["groups"] = groups; return(View()); }
public IActionResult Create(int tid) { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var test = context.Tests.First(i => i.Id == tid && i.OwnerId == userData.Id); var ask = new Ask { TestId = test.Id, Value = "Empty" }; context.Asks.Add(ask); context.SaveChanges(); return(Redirect($"/Test/Create?id={tid}")); }
public IActionResult AddDescription(int tid) { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var test = context.Tests.First(i => i.Id == tid && i.OwnerId == userData.Id); var descr = new ResultDescription { MinValue = 0, Text = "", TestId = test.Id }; context.Descriptions.Add(descr); context.SaveChanges(); return(Redirect($"/Test/Create?id={tid}")); }
public void GetTags() { using (SessionKeeper keeper = new SessionKeeper()) { long tableID = TableLoadHelper.GetTableReference(keeper.Session, newSelectedID); MessageBox.Show("tableID " + tableID.ToString()); DataTable dt = TableLoadHelper.GetTableRefIDsByTableID(keeper.Session, tableID); string columnns = ""; foreach (var item in dt.Columns) { columnns += item.ToString() + Environment.NewLine; } foreach (var item in dt.Rows) { string values = ((DataRow)item)[0].ToString() + " " + ((DataRow)item)[1].ToString(); MessageBox.Show("Rows " + values); } MessageBox.Show(columnns); } }
public IActionResult SetGroup() { var context = ContextBuilder.Context; ViewData["Title"] = "Сделать доступным для группы..."; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var id = int.Parse(Request.Query["id"]); var tst = context.Tests.First(i => i.Id == id && i.OwnerId == userData.Id); // Вывод списка с доступными группами if (Request.Query.ContainsKey("gname")) { var gname = (string)Request.Query["gname"]; var groups = new List <Group>(context.Groups.Where(i => i.Name == gname)); ViewData["groups"] = groups; ViewData["test"] = tst; return(View()); } if (!Request.Query.ContainsKey("gid")) { return(Redirect($"/Test/Create?id={id}")); } // Установка новой группы для теста var gid = int.Parse(Request.Query["gid"]); tst.Limit = gid; context.Tests.Update(tst); context.SaveChanges(); return(Redirect($"/Test/Create?id={id}")); }
public IActionResult Remove(int id) { var context = ContextBuilder.Context; var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var ask = context.Asks.First(i => i.Id == id); if (context.Tests.Count(i => i.Id == ask.TestId && i.OwnerId == userData.Id) < 1) { return(Redirect("/Home/Index")); } context.Asks.Remove(ask); context.SaveChanges(); return(Redirect($"/Test/Create?id={ask.TestId}")); }
public IActionResult Login(string name, string pass) { if (pass == null || name == null) { return(View()); } var code = SessionKeeper.AddSession(name, pass); if (code != null) { Response.Cookies.Append("Name", name); Response.Cookies.Append("SessionKey", code); } else { return(View()); } return(Redirect("/Home/Index")); }
public IActionResult Index(int?gid) { using var context = ContextBuilder.Context; SessionKeeper.Get(this, false); if (gid is null) { return(Redirect("/Home/Index")); } var group = context.Groups.First(i => i.Id == gid); var needReg = 1; try { var usr = context.Users.First(i => i.Name == (string)ViewData["Name"]); var contains = context.GroupsList.Count(i => i.UserId == usr.Id && i.GroupId == gid); if (contains > 0) { needReg = 2; } } catch { needReg = 0; } var glists = new List <GroupList>(context.GroupsList.Where(i => i.GroupId == gid)); var users = glists.Select(u => context.Users.First(i => i.Id == u.UserId)).ToList(); var tests = new List <Test>(context.Tests.Where(i => i.Limit == gid)); ViewData["needReg"] = needReg; ViewData["Title"] = group.Name; ViewData["gName"] = group.Name; ViewData["gUsers"] = users; ViewData["gid"] = gid; ViewData["tests"] = tests; return(View()); }
// GET public IActionResult Profile() { var context = ContextBuilder.Context; var user = SessionKeeper.Get(this); if (!Request.Cookies.ContainsKey("Name")) { return(Redirect("/Home/Index")); } if (user.Id < 0) { return(Redirect("/Home/Index")); } ViewData["Password"] = user.Password; ViewData["HideBar"] = true; ViewData["Title"] = $"Профиль пользователя {Request.Cookies["Name"]}"; ViewData["Tests"] = new List <Test>(context.Tests.Where(i => i.OwnerId == user.Id)); return(View()); }
public IActionResult KickSelf(int gid) { using var context = ContextBuilder.Context; try { var userData = SessionKeeper.Get(this); if (userData.Id < 0) { return(Redirect("/Home/Index")); } var record = context.GroupsList.First(i => i.UserId == userData.Id && i.Owner < 1 && i.GroupId == gid); context.GroupsList.Remove(record); context.SaveChanges(); return(Redirect($"/Group/Index?gid={gid}")); } catch { return(Redirect($"/User/Profile")); } }