private void FuncToCall3(object context) { if (SelectedSubTopic == null) { MessageBox.Show("You must select a sub-topic to delete"); } else { using (SelfAssessmentDbContext newContext = new SelfAssessmentDbContext()) { SubTopic retrievedSubTopic = newContext.SubTopics.Where(st => st.Id == SelectedSubTopic.Id).FirstOrDefault(); newContext.SubTopics.Remove(retrievedSubTopic); newContext.SaveChanges(); } SubTopics = Context.SubTopics.Include(m => m.MainTopic) .Where(r => r.MainTopic.Id == SelectedMainTopic.Id) .ToList(); SelectedSubTopic = null; TopicIntroduction = null; TopicContent = null; TopicSummary = null; CreatedSubTopicTitle = null; CreatedSubTopicIntro = null; CreatedSubTopicContent = null; CreatedSubTopicSummary = null; } }
private async void FuncToCall(object context) { if (CreatedSubTopicTitle == null || CreatedSubTopicTitle == "") { MessageBox.Show("You must define a title for this sub-topic."); } else if (SelectedMainTopic == null) { MessageBox.Show("You must select a main topic for this to belong to."); } else if (CreateOrUpdate == "Create") { ISubTopicService service = new SubTopicDataService(); await service.CreateNewSubTopic(SelectedMainTopic.Title, CreatedSubTopicTitle, CreatedSubTopicIntro, CreatedSubTopicContent, CreatedSubTopicSummary); SubTopics = Context.SubTopics .Where(r => r.MainTopic.Id == SelectedMainTopic.Id) .ToList(); } else if (CreateOrUpdate == "Update") { ISubTopicService service = new SubTopicDataService(); SubTopic updatedSubTopic = await service.UpdateSubTopic(SelectedSubTopic.Id, CreatedSubTopicTitle, CreatedSubTopicIntro, CreatedSubTopicContent, CreatedSubTopicSummary); SelectedSubTopic = updatedSubTopic; CreateOrUpdate = "Create"; } }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Value,TopicId")] SubTopic subTopic) { if (id != subTopic.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(subTopic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubTopicExists(subTopic.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TopicId"] = new SelectList(_context.Topics, "Id", "Id", subTopic.TopicId); return(View(subTopic)); }
public Question getQuestion() { var random = new Random(); List <Option> options = new List <Option>(); SubTopic correctAnswerSubTopic = topic.subTopics[random.Next(topic.subTopics.Count)]; this.correctAnswer = correctAnswerSubTopic.name; Option correctOption = new Option() { optionText = correctAnswerSubTopic.name, status = true }; options.Add(correctOption); this.questionText = correctAnswerSubTopic.points[random.Next(correctAnswerSubTopic.points.Count)]; List <SubTopic> copyOfSubTopicsList = new List <SubTopic>(); topic.subTopics.ForEach(subtopic => copyOfSubTopicsList.Add(subtopic)); copyOfSubTopicsList.Remove(correctAnswerSubTopic); do { SubTopic incorrectOptionSubtopic = copyOfSubTopicsList[random.Next(copyOfSubTopicsList.Count)]; Option incorrectOption = new Option { optionText = incorrectOptionSubtopic.name, status = false }; options.Add(incorrectOption); copyOfSubTopicsList.Remove(incorrectOptionSubtopic); } while (options.Count < 3); this.options = options.OrderBy(option => Guid.NewGuid()).ToList(); return(this); }
public void ChangeSubTopicStatus(int subTopicID, string status) { SubTopic Subtopic = db.SubTopics.Where(x => x.SubTopicId == subTopicID).FirstOrDefault(); Subtopic.IsInactive = (string.IsNullOrEmpty(status) || status.ToLower() == "false") ? true : false; db.SaveChanges(); }
public void Post([FromBody] SubTopic topic) { if (ModelState.IsValid) { _service.AddSubTopic(topic); } else { BadRequest(); } }
public async Task CreateANewSubTopicGivenAllNecessaryParameters() { await subTopicService.CreateNewSubTopic("MainTopic", "Title", "Intro", "Content", "Summary"); using (SelfAssessmentDbContext context = new SelfAssessmentDbContext()) { SubTopic subTopic = context.SubTopics.Where(s => s.Title == "Title").FirstOrDefault(); Assert.AreEqual("Title", subTopic.Title); Assert.AreEqual("Intro", subTopic.Introduction); } }
public SubTopic GetDisscussion(int id) { SubTopic comments = _repo.Query <SubTopic>().Where(t => t.Id == id).Select(t => new SubTopic { Id = t.Id, Subject = t.Subject, Description = t.Description, Comments = t.Comments, }).FirstOrDefault(); return(comments); }
public bool AddSubTopic(SubTopic objSubTopic) { try { db.SubTopics.Add(objSubTopic); db.SaveChanges(); return(true); } catch { return(false); } }
public void AddSubTopic(SubTopic topic) { //var topicId = _repo.Query<Topic>().Where(t => t.Id == id).FirstOrDefault(); if (topic.Id == 0) { _repo.Add(topic); } else { _repo.Update(topic); } }
public async Task <IActionResult> Create([Bind("Id,Value,TopicId")] SubTopic subTopic) { if (ModelState.IsValid) { subTopic.Id = Guid.NewGuid(); _context.Add(subTopic); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TopicId"] = new SelectList(_context.Topics, "Id", "Id", subTopic.TopicId); return(View(subTopic)); }
public List <Post> GetPostBySubTopicId(SubTopic subTopic) { List <Post> result = new List <Post>(); try { result = postDB.GetPostBySubTopicId(subTopic); } catch (Exception ex) { this.LogError(ex); } return(result); }
public void Handle_WithBaseClassHandlerRegistered_DoesNothing() { // Arrange var dispatcher = new TopicDispatcher(); dispatcher.Register(handler); var message = new SubTopic(); // Act dispatcher.Handle(subscriber, message); // Assert mockHandler.Verify(m => m.Handle(It.IsAny <Topic>()), Times.Never); }
public async Task UpdateSubTopicContents() { using (SelfAssessmentDbContext context = new SelfAssessmentDbContext()) { SubTopic subTopic = context.SubTopics.Where(s => s.Title == "SubTopic").FirstOrDefault(); SubTopic createdSubTopic = await subTopicService.UpdateSubTopic(subTopic.Id, "NewTitle", "NewIntro", "NewContent", "NewSummary"); } using (SelfAssessmentDbContext context = new SelfAssessmentDbContext()) { SubTopic retrievedsubTopic = context.SubTopics.Where(s => s.Title == "NewTitle").FirstOrDefault(); Assert.AreEqual("NewTitle", retrievedsubTopic.Title); Assert.AreEqual("NewIntro", retrievedsubTopic.Introduction); } }
public IActionResult AddEditSubTopic([FromForm] TopicCommonRequestModel model) { ResponseModel responseModel = new ResponseModel(); if (ModelState.IsValid) { if (model.Id == 0) { SubTopic subTopic = new SubTopic(); subTopic.TopicId = model.TopicId; subTopic.Name = model.Name; subTopic.Description = model.Description; subTopic.ImageUrl = _fileService.SaveFile(model.Files, ClassBookConstant.ImagePath_Topic); subTopic.VideoLink = _fileService.SaveFile(model.Video, ClassBookConstant.VideoPath_Topic); subTopic.DateOfUpload = DateTime.Now; subTopic.DateOfActivation = model.DateOfActivation; subTopic.Deleted = false; subTopic.Active = true; _context.SubTopic.Add(subTopic); _context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); } else { var subTopic = _context.SubTopic.Where(x => x.Id == model.Id).FirstOrDefault(); subTopic.Name = model.Name; subTopic.Description = model.Description; subTopic.DateOfActivation = model.DateOfActivation; if (model.Files.Count > 0) { subTopic.ImageUrl = _fileService.SaveFile(model.Files, ClassBookConstant.ImagePath_Topic); } if (model.Video.Count > 0) { subTopic.VideoLink = _fileService.SaveFile(model.Video, ClassBookConstant.VideoPath_Topic); } _context.SubTopic.Update(subTopic); _context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); } } else { return(StatusCode((int)HttpStatusCode.BadRequest, ModelState)); } }
public IHttpActionResult GetSubTopic([FromUri] GetSubTopicRequest getSubTopicRequest) { var responses = new Responses(); try { if (Utility.UserId < 0) { return(BadRequest(Utility.INVALID_USER)); } if (getSubTopicRequest == null) { getSubTopicRequest = new GetSubTopicRequest(); } var subTopic = new SubTopic() { SubTopicId = getSubTopicRequest.SubTopicId }; var subTopics = iAuthorWriteUpDetail.GetSubTopic(subTopic); var subTopicList = new List <GetSubTopicResponse>(); foreach (var subTopicDetail in subTopics) { subTopicList.Add(new GetSubTopicResponse() { SubTopicId = subTopicDetail.SubTopicId, SubTopicName = subTopicDetail.SubTopicName }); } responses.Status = Utility.SUCCESS_STATUS_RESPONSE; responses.Description = "SubTopic retrieved successfully"; responses.Response = subTopicList; } catch (Exception ex) { responses.Status = Utility.ERROR_STATUS_RESPONSE; responses.Description = "Error while retrieving subTopic."; Utility.WriteLog("GetSubTopic", getSubTopicRequest, "Error while retrieving subTopic. (AuthorWriteUpDetailAdminController)", ex.ToString()); } return(Ok(responses)); }
public IEnumerable <SubTopic> GetSubTopic(SubTopic subTopic) { using (DemsifyEntities dataContext = new DemsifyEntities()) { var subTopics = dataContext.SubTopicGet(subTopic.SubTopicId).ToList(); var subTopicList = new List <SubTopic>(); foreach (var subTopicDetail in subTopics) { subTopicList.Add(new SubTopic() { SubTopicId = subTopicDetail.SubTopicId, SubTopicName = subTopicDetail.SubTopicName }); } return(subTopicList); } }
/// <summary> /// Retornna todos los post relacionados a un subtopic /// </summary> /// <param name="subTopic">Sub topic del cual se quieren obtener los post</param> /// <returns></returns> public List <Post> GetPostBySubTopicId(SubTopic subTopic) { DataSet ds = WikiDBAdapter.GetDataSet("GetPostBySubTopicId", new DataAccessParameter("@SubTopicId", subTopic.SubTopicId, typeof(int), null, ParameterDirection.Input)); List <Post> postResult = new List <Post>(); if (ds != null && ds.Tables.Count > 0) { DataTable myTable = ds.Tables[0]; if (myTable != null && myTable.Rows.Count > 0) { var dsm = new DataSetMapper <Post>(); postResult = dsm.ConvertFromBackend <List <Post> >(myTable); } } return(postResult); }
// To Add User Sub Topic public static bool AddSubTopic(string TopicId, string SubTopicName, int UserId) { using (EditorsEntities entity = new EditorsEntities()) { try { SubTopic NewUserSubTopic = new SubTopic(); NewUserSubTopic.TopicID = Convert.ToInt32(TopicId); NewUserSubTopic.UserID = UserId; NewUserSubTopic.SubTopicName = SubTopicName; NewUserSubTopic.Type = 2; // 2 Represents User SubTopic NewUserSubTopic.createtime = DateTime.Now; entity.SubTopics.Add(NewUserSubTopic); entity.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public bool UpdateSubTopic(SubTopic objSubTopic) { try { SubTopic subTopic = db.SubTopics.Where(x => x.SubTopicId == objSubTopic.SubTopicId).FirstOrDefault(); subTopic.SubTopicDesc = objSubTopic.SubTopicDesc; subTopic.Hint = objSubTopic.Hint; subTopic.IsInactive = objSubTopic.IsInactive; subTopic.IsPrefixShown = objSubTopic.IsPrefixShown; subTopic.IsSuffixShown = objSubTopic.IsSuffixShown; subTopic.IsSEOUrlActive = objSubTopic.IsSEOUrlActive; subTopic.PrefixText = objSubTopic.PrefixText; subTopic.SuffixText = objSubTopic.SuffixText; subTopic.IsQuestionTextFormat = objSubTopic.IsQuestionTextFormat; subTopic.QuestionTextFormat = objSubTopic.QuestionTextFormat; db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult AddSub(Int32 TopId, string SubTopicName) { mocktestEntities1 mock = new mocktestEntities1(); List <Topic> Tp = new List <Topic>(); SubTopic newsubT = new SubTopic(); var trim = SubTopicName.TrimStart(); using (mocktestEntities1 select = new mocktestEntities1()) { var count = select.SubTopics.Where(a => a.Name == trim); if (count.Count() < 1) { newsubT.Name = SubTopicName; newsubT.Active = true; newsubT.TopicId = TopId; mock.SubTopics.Add(newsubT); mock.SaveChanges(); } else { } return(Json(true, JsonRequestBehavior.AllowGet)); } }
public void Setup() { User user = new User() { Username = "******", PasswordHashed = "test2", Email = "*****@*****.**", DateJoined = DateTime.Now }; Account account = new Account() { User = user, }; TestSeries testSeries = new TestSeries() { TestSeriesName = "TestTestSeries", }; Test test = new Test() { TestSeries = testSeries, TestName = "TestName" }; Test secondTest = new Test() { TestSeries = testSeries, TestName = "TestName2" }; TestResult testResult = new TestResult() { Account = account, Mark = 30, Test = test }; MainTopic mainTopic = new MainTopic() { Title = "MainTopic" }; SubTopic subTopic = new SubTopic() { MainTopic = mainTopic, Title = "SubTopic" }; using (SelfAssessmentDbContext context = new SelfAssessmentDbContext()) { context.Accounts.Add(account); context.TestSeries.Add(testSeries); context.MainTopics.Add(mainTopic); context.SubTopics.Add(subTopic); context.Tests.Add(test); context.Tests.Add(secondTest); context.TestResults.Add(testResult); context.SaveChanges(); } }
public void AddSubtopics(SubTopic subTopic) { context.subTopics.Add(subTopic); context.SaveChanges(); }
//public IList<SubTopic> GetSubTopics(int mainTopicID) //{ // //} public void AddSubtopic(SubTopic subTopic, int topicID) { subTopic.SubTopicID = topicID; context.subTopics.Add(subTopic); context.SaveChanges(); }
public void Put(int id, SubTopic subTopic) { _unitOfWork.SubTopics.Update(id, subTopic); _unitOfWork.Save(); }
public void Post(SubTopic subTopic) { _unitOfWork.SubTopics.Create(subTopic); _unitOfWork.Save(); }
public void Add(SubTopic topic) { throw new NotImplementedException(); }