public async Task <IActionResult> UpdateSubsection([FromBody] Subsection subsection) { _repository.Subsection.Update(subsection); await _repository.Save(); return(Ok(subsection)); }
public List <Subsection> GetSubsectionNames(string languageID) { List <Subsection> names = new List <Subsection>(); con.Open(); SqlCommand cmd = new SqlCommand("SELECT SubsectionID, SubsectionCode, SectionID, SubsectionName, RequiredBool " + "FROM Subsection", con); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Subsection subsection = new Subsection(); subsection.SubsectionID = reader.GetInt32(0); string subsectionCode = reader.GetDouble(1).ToString(); string sectionID = reader.GetInt32(2).ToString(); subsection.SubsectionCode = sectionID + "." + subsectionCode; subsection.SectionID = reader.GetInt32(2); subsection.RequiredBool = reader.GetBoolean(4); string englishWord = reader.GetString(3); languageID = languageID.Trim().ToUpper(); subsection.SubsectionName = translationQuery.GetTranslation(englishWord, languageID); names.Add(subsection); } con.Close(); return(names); }
public void SubsectionRepository_CanStore() { var repo = new SubsectionRepository(); var subsection = new Subsection("第一款"); repo.Store(subsection); // without error }
/// <summary> /// Reads a given value from the ConfigNode. If a Subsection attribute is provided, this /// method will search in a subsection of the ConfigNode for the value /// </summary> /// <param name="node"></param> /// <param name="valueName"></param> /// <param name="attrs"></param> /// <returns></returns> private static string ReadValue(ConfigNode node, string valueName, System.Object[] attrs) { if (attrs == null) { attrs = new System.Object[] { } } ; Subsection ss = attrs.SingleOrDefault(attr => attr is Subsection) as Subsection; if (ss != null) { if (node.HasNode(ss.Section)) { node = node.GetNode(ss.Section); } else // uh oh, we expected a subsection .. { Log.Warning("ConfigUtil.ConfigNodeSerialization: Did not find a subsection called '{0}' when looking up value name {1}", ss.Section, valueName); } } return(node.ReadString(valueName)); } }
public async Task <IActionResult> CreateSubsection(Guid sectionId, string subsectionName) { Section section = await _websiteDB.Sections.FirstOrDefaultAsync(s => s.Id == sectionId); int position = await _websiteDB.Subsections.Where(s => s.Section == section).CountAsync() + 1; if (section != null && !string.IsNullOrWhiteSpace(subsectionName)) { Subsection subsection = new Subsection() { Id = Guid.NewGuid(), SubsectionName = subsectionName, Section = section, SubsectionPosition = position //SubsectionAccessLevel = section.SectionAccessLevel }; await _websiteDB.Subsections.AddAsync(subsection); await _websiteDB.SaveChangesAsync(); return(RedirectToAction("Sections", "Forum")); } return(RedirectToAction("Sections", "Forum")); }
public Subsection Get(string name) { Subsection subsection = null; MySqlConnection cnn = new MySqlConnection(_cnnStr); try { cnn.Open(); MySqlCommand cmd = cnn.CreateCommand(); cmd.CommandText = "SELECT * FROM subsections WHERE name = @name"; cmd.Parameters.AddWithValue("@name", name); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { subsection = CreateSubsection(reader); } reader.Close(); } finally { cnn.Close(); } return(subsection); }
public async Task <IActionResult> CreateTopic(Guid subsectionId) { // Проверка, чтобы пользователь был авторизован if (User.Identity.IsAuthenticated) { // Формируем модель подраздела Subsection subsection = await _websiteDB.Subsections.Include(s => s.Section).FirstOrDefaultAsync(s => s.Id == subsectionId); // Проверяем, что такой подраздел существует if (subsection != null) { ViewBag.SubsectionId = subsection.Id; ViewBag.SubsectionName = subsection.SubsectionName; // Формируем модель пользователя с уровнем доступа для проверки User user = await _websiteDB.Users.Include(u => u.Role).FirstOrDefaultAsync(u => u.Name == User.Identity.Name); // Проверяем, может ли пользователь просматривать данный подраздел if (subsection.Section.SectionAccessLevel <= user.Role.AccessLevel) { // Если может, то возвращаем ему представление //ViewBag.SubsectionId = subsection.Id; return(View()); } } // А если не может, то возвращаем ему ошибку 404 return(Redirect("/Main/PageNotFound")); } // Если юзер не авторизован, перенаправляем его на страницу авторизации return(RedirectToAction("Login", "Account")); }
/// <summary> /// Writes the specified value string into a ConfigNode as a value named valueName. If any of /// the attributes are of Subsection, that value will be written into a subsection of the /// ConfigNode with name provided (will be created if necessary) /// </summary> /// <param name="node"></param> /// <param name="valueName"></param> /// <param name="value"></param> /// <param name="attrs"></param> private static void WriteValue(ConfigNode node, string valueName, string value, System.Object[] attrs) { if (attrs == null) { attrs = new System.Object[] { } } ; Subsection subsection = attrs.SingleOrDefault(attr => attr is Subsection) as Subsection; if (subsection != null) { //Log.Debug("valueName {0} with value '{1}' should be in a subsection called '{2}'", valueName, value, subsection.Section); if (node.HasNode(subsection.Section)) { //Log.Debug("Already has a section of that name"); node = node.GetNode(subsection.Section); } else { Log.Debug("Created a new section for " + subsection.Section); node = node.AddNode(subsection.Section); } } attrs.ToList().ForEach(attr => { if (attr is HelpDoc) { node.AddValue(string.Format("// {0}", valueName), ((HelpDoc)attr).Documentation); } }); node.AddValue(valueName, value); }
public async Task <IActionResult> UpdateSubsection([FromBody] Subsection subsection) { _service.UpdateSubsection(subsection); await _service.Save(); return(Ok(subsection)); }
public async Task <IActionResult> MoveSubsectionDown(Guid sectionId, Guid subsectionId) { List <Subsection> subsections = await _websiteDB.Subsections.Where(s => s.Section.Id == sectionId).OrderBy(s => s.SubsectionPosition).ToListAsync(); Subsection subsection = subsections.FirstOrDefault(s => s.Id == subsectionId); int maxPosition = subsections.Count(); // Если такой подраздел существует и его порядковый номер меньше максимального значения позиции, то заходим в тело условия if (subsection != null && subsection.SubsectionPosition < maxPosition) { // Создаем цикл перебора для прохождения по всему списку for (int i = 0; i < subsections.Count; i++) { // Находим нужный нам подраздел по Id if (subsections[i].Id == subsectionId) { // Меняем местами значение позиций у нужного нам подраздела и того, что стоит на 1 ступень ниже int temp = subsections[i].SubsectionPosition; subsections[i].SubsectionPosition = subsections[i + 1].SubsectionPosition; subsections[i + 1].SubsectionPosition = temp; } } _websiteDB.Subsections.Update(subsection); await _websiteDB.SaveChangesAsync(); } return(RedirectToAction("Sections", "Forum")); }
public async Task <IActionResult> MoveSubsectionUp(Guid sectionId, Guid subsectionId) { List <Subsection> subsections = await _websiteDB.Subsections.Where(s => s.Section.Id == sectionId).OrderBy(s => s.SubsectionPosition).ToListAsync(); Subsection subsection = subsections.FirstOrDefault(s => s.Id == subsectionId); if (subsection != null && subsection.SubsectionPosition > 1) { // Создаем цикл перебора для прохождения по всему списку for (int i = 0; i < subsections.Count; i++) { // Находим нужный нам подраздел по Id if (subsections[i].Id == subsectionId) { // Меняем местами значение позиций у нужного нам подраздела и того, что стоит на 1 ступень выше int temp = subsections[i].SubsectionPosition; subsections[i].SubsectionPosition = subsections[i - 1].SubsectionPosition; subsections[i - 1].SubsectionPosition = temp; } } _websiteDB.Subsections.Update(subsection); await _websiteDB.SaveChangesAsync(); } return(RedirectToAction("Sections", "Forum")); }
public void Section_AddSubsections() { var section = new Section("section"); var subsection = new Subsection("subsection"); section.Add(subsection); CollectionAssert.AreEqual(new[] { subsection }, section.Subsections.ToArray()); }
public async Task <IActionResult> AddSection([FromBody] Subsection subsection) { await _repository.Subsection.Create(subsection); await _repository.Save(); return(CreatedAtRoute(nameof(GetSubsectionById), subsection.Id, subsection)); }
public async Task <IActionResult> AddSection([FromBody] Subsection subsection) { await _service.CreateSubsection(subsection); await _service.Save(); return(Ok()); }
public void constructor_should_set_elements_to_empty() { // When SUT = new Subsection(); // Then Assert.IsEmpty(SUT.Elements); }
public void SectionRepository_CanStore() { var repo = new SectionRepository(); var section = new Section("секция 1"); var subsection = new Subsection("первый подраздел"); section.Add(subsection); repo.Store(section); // without error }
public void Section_AddMultipleSubsections() { var section = new Section("section"); var subsection1 = new Subsection("subsection 1"); var subsection2 = new Subsection("subsection 2"); section.Add(subsection1, subsection2); CollectionAssert.AreEqual(new[] { subsection1, subsection2 }, section.Subsections.ToArray()); }
public ActionResult CreateCard2(Subject Sub, Section Sec, Subsection Subsec, Topic Top) { ViewBag.Sub = Sub; ViewBag.Sec = Sec; ViewBag.Subsec = Subsec; ViewBag.Top = Top; return(View()); }
public void setChildElement_should_throw_if_there_is_no_children_set() { // Given var subsection = new Subsection(); // Then var ex = Assert.Throws <ArgumentException>(() => SUT.SetChildElement(subsection)); Assert.AreEqual("No child elements supplied to set as child", ex.Message); }
public void SubsectionRepository_CanRetrieve() { var repo = new SubsectionRepository(); var subsection = new Subsection("第一款"); repo.Store(subsection); var actual = repo.Retrieve(subsection.Id); Assert.AreEqual(subsection, actual); }
public void UpdateSubsection(Subsection model) { var subsection = Context.Subsections.Find(model.SubsectionId); subsection.Name = model.Name; subsection.SectionId = model.SectionId; subsection.UserId = model.UserId; Context.Subsections.Update(subsection); Context.SaveChanges(); }
public void Section_ToString() { var subsection = new Subsection("Subsection"); Assert.AreEqual(@"Subsection { Title: ""Subsection"" }", subsection.ToString()); var section = new Section("Section"); Assert.AreEqual(@"Section { Title: ""Section"", Subsections: [] }", section.ToString()); section.Add(subsection, new Subsection("第二款")); Assert.AreEqual(@"Section { Title: ""Section"", Subsections: [Subsection { Title: ""Subsection"" }, Subsection { Title: ""第二款"" }] }", section.ToString()); }
public void SectionRepository_CanRetrieve() { var repo = new SectionRepository(); var section = new Section("секция 1"); var subsection1 = new Subsection("первый подраздел"); var subsection2 = new Subsection("второй подраздел"); section.Add(subsection1, subsection2); repo.Store(section); var actual = repo.Retrieve(section.Id); Assert.AreEqual(section, actual); }
public List <Section> GetSectionNames(string languageID) { List <Subsection> subsections = new List <Subsection>(); List <Section> sectionNames = new List <Section>(); languageID = languageID.Trim().ToUpper(); con.Open(); SqlCommand cmd = new SqlCommand("SELECT Section.SectionID, Section.SectionName, SubsectionID, SubsectionCode, SubsectionName, RequiredBool " + "FROM Subsection " + "INNER JOIN Section " + "ON Section.SectionID = Subsection.SectionID " + "ORDER BY Section.SectionID", con); SqlDataReader reader = cmd.ExecuteReader(); int sectionID = 100; Section section = new Section(); while (reader.Read()) { Subsection subsection = new Subsection(); int currentSectionID = reader.GetInt32(0); if (!sectionID.Equals(currentSectionID)) { if (!sectionID.Equals(100)) { section.Subsections = subsections; sectionNames.Add(section); section = new Section(); subsections = new List <Subsection>(); } sectionID = currentSectionID; section.SectionID = sectionID; section.SectionName = translationQuery.GetTranslation(reader.GetString(1), languageID); } subsection.SubsectionID = reader.GetInt32(2); subsection.SectionID = sectionID; string subsectionCode = reader.GetDouble(3).ToString(); subsection.SubsectionCode = sectionID + "." + subsectionCode; subsection.RequiredBool = reader.GetBoolean(5); subsection.SubsectionName = translationQuery.GetTranslation(reader.GetString(4), languageID); subsections.Add(subsection); } if (!sectionID.Equals(100)) { section.Subsections = subsections; sectionNames.Add(section); } con.Close(); return(sectionNames); }
/// <summary> /// Parses the code given the object and sets the data to the object /// from the front of the string. /// </summary> /// <param name="code">The code to parse and handle</param> /// <returns> /// The newly parsed object. The string builder will also have been updted, the code parsed is removed /// </returns> /// <exception cref="ArgumentException">Thrown if the code string doesn't start with one of the accepted code indicators or the element isn't supported by the parser</exception> public LaTeXElement ParseCode(StringBuilder code) { if (!Regex.IsMatch(code.ToString(), CodeParser.CreateCodeStartPattern(CodeIndicators))) { throw new ArgumentException("The code didn't start with an allowed indicator"); } var subsection = new Subsection { Name = CodeParser.SimpleContent("subsection", code) }; return(subsection); }
public void Section_AddAtPosition() { var section = new Section("セクション"); var subsection1 = new Subsection("第一款"); var subsection2 = new Subsection("第二款"); section.Add(subsection1, subsection2); CollectionAssert.AreEqual(new[] { subsection1, subsection2 }, section.Subsections.ToArray()); var subsection3 = new Subsection("第三款"); section.AddAt(2, subsection3); CollectionAssert.AreEqual(new[] { subsection1, subsection3, subsection2 }, section.Subsections.ToArray()); }
public void setChildElement_should_set_elemnts() { // Given var text1 = new TextBody(); var text2 = new TextBody(); var subsection = new Subsection(); // When SUT.SetChildElement(subsection, text1, text2); // Then Assert.AreSame(text1, subsection.Elements[0]); Assert.AreSame(text2, subsection.Elements[1]); }
private Subsection CreateSubsection(MySqlDataReader reader) { Subsection subsection = new Subsection(); int _subsectionId = (Int32)reader["subsection_id"]; int _moduleId = (Int32)reader["module_id"]; string _name = reader["name"].ToString(); string _content = reader["content"].ToString(); subsection.subsectionId = _subsectionId; subsection.moduleId = _moduleId; subsection.name = _name; subsection.content = _content; return(subsection); }
public async Task <IActionResult> DeleteSubsection(Guid subsectionId, bool isChecked) { Subsection subsection = await _websiteDB.Subsections.Include(s => s.Topics).ThenInclude(t => t.Replies).FirstOrDefaultAsync(s => s.Id == subsectionId); if (subsection != null && isChecked) { // Начинаем с удаления ответов в темах, затем темы, и последним сам подраздел _websiteDB.Replies.RemoveRange(subsection.Topics.SelectMany(t => t.Replies).ToList()); _websiteDB.Topics.RemoveRange(subsection.Topics); _websiteDB.Subsections.Remove(subsection); await _websiteDB.SaveChangesAsync(); } return(RedirectToAction("Sections", "Forum")); }
public Document UpdateSubsection(Document doc, Subsection subsect, string targetDataCode) { List <Subsection> subsections = new List <Subsection>(); doc.SDS.Sections.ForEach(sect => { subsections.AddRange(sect.Subsections); }); Subsection subsection = subsections.Where(s => s.DataCode.ToLower() == targetDataCode.ToLower()).FirstOrDefault(); if (subsection != null) { subsection.Value = subsect.Value; } return(doc); }