public ActionResult Create(int chapterId, CreateTopicModel model) { try { Topic topic = new Topic { CourseRef = model.CourseId == Constants.NoCourseId ? (int?)null : model.CourseId, ChapterRef = model.ChapterId, TopicTypeRef = model.TopicTypeId, Name = model.TopicName }; AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors); if (ModelState.IsValid) { Storage.AddTopic(topic); return(RedirectToAction("Index", new { ChapterId = model.ChapterId })); } else { SaveValidationErrors(); return(RedirectToAction("Create")); } } catch (Exception e) { throw e; } }
public JsonResult Edit(int topicId, CreateTopicModel model) { try { var topic = new Topic { Id = topicId }; topic.UpdateFromModel(model); AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors); if (ModelState.IsValid) { topic = Storage.UpdateTopic(topic); var viewTopic = topic.ToViewTopicModel(Storage); var discipline = Storage.GetTopic(topicId).Chapter.Discipline; // TODO: FatTony;wtf? return(Json(new { success = true, topicId = topicId, topicRow = PartialViewAsString("TopicRow", viewTopic), disciplineId = discipline.Id, error = discipline.IsValid ? string.Empty : Validator.GetValidationError(discipline) })); } var m = new CreateTopicModel(Storage.GetCourses(), topic); return(Json(new { success = false, topicId = topicId, html = PartialViewAsString("Edit", m) })); } catch (Exception ex) { return(Json(new { success = false, html = ex.Message })); } }
public ActionResult Edit(int topicId, CreateTopicModel model) { try { Topic topic = Storage.GetTopic(topicId); topic.CourseRef = model.CourseId == Constants.NoCourseId ? (int?)null : model.CourseId; topic.TopicTypeRef = model.TopicTypeId; topic.Name = model.TopicName; AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors); if (ModelState.IsValid) { Storage.UpdateTopic(topic); return(RedirectToRoute("Topics", new { action = "Index", ChapterId = topic.ChapterRef })); } else { SaveValidationErrors(); return(RedirectToAction("Edit")); } } catch (Exception e) { throw e; } }
public IActionResult Create([FromBody] CreateTopicModel model) { try { using (var wb = new WebClient()) { var data = new NameValueCollection(); data["secret"] = _secretService.GetSecret("recaptcha-secret"); data["response"] = model.Token; var response = wb.UploadValues(_secretService.GetSecret("recaptcha-verify-url"), "POST", data); var responseObj = JsonSerializer.Deserialize <RecaptchaResponseModel>(response); if (responseObj.success) { var topic = _topicService.Create(model, int.Parse(User.Identity.Name)); var topicResource = _mapper.Map <TopicResourceModel>(topic); return(Ok(topicResource)); } return(BadRequest(new { message = "Recaptcha verification failed" })); } } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
//Todo: Create Data public Topic Create(CreateTopicModel topicData, int userId) { User user = _context.Users.Find(userId); Option left = new Option { Name = topicData.Left, Type = EOptionTypes.Left, Votes = new List <Vote>() }; Option right = new Option { Name = topicData.Right, Type = EOptionTypes.Right, Votes = new List <Vote>() }; _context.Options.Add(left); _context.Options.Add(right); Topic newTopic = new Topic { User = user, Question = topicData.Question, Options = new List <Option> { left, right } }; _context.Topics.Add(newTopic); _context.SaveChanges(); return(newTopic); }
public ActionResult Edit(int topicId) { var topic = Storage.GetTopic(topicId); var model = new CreateTopicModel(Storage.GetCourses(), topic); return(PartialView("Edit", model)); }
public ActionResult Create(int chapterId, CreateTopicModel model) { var topic = new Topic { ChapterRef = model.ChapterId, Name = model.TopicName, TestCourseRef = model.BindTestCourse ? model.TestCourseId : (int?)null, TestTopicTypeRef = model.BindTestCourse ? model.TestTopicTypeId : (int?)null, TheoryCourseRef = model.BindTheoryCourse ? model.TheoryCourseId : (int?)null, TheoryTopicTypeRef = model.BindTheoryCourse ? model.TheoryTopicTypeId : (int?)null }; AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors); if (ModelState.IsValid) { Storage.AddTopic(topic); return(RedirectToAction("Index", new { ChapterId = model.ChapterId })); } else { SaveValidationErrors(); return(RedirectToAction("Create")); } }
public async Task <IActionResult> CreateTopic([FromBody] CreateTopicModel model) { // check related work Guid?workId; if (model.RelatedWork == null) { workId = null; } else { workId = XUtils.ParseId(model.RelatedWork); var work = await Context.Works.FirstOrDefaultAsync(p => p.Id == workId); if (work == null) { return(new ApiError("ID_NOT_FOUND", "作品id无效").Wrap()); } } // create topic and set member=1 var topic = new Topic(model.IsGroup, model.Name, model.Description, workId, AuthStore.UserId.Value); topic.SetMemberCount(1); await Context.AddAsync(topic); await Context.GoAsync(); return(Ok(new IdResponse(topic.Id))); }
public ActionResult CreateTopic() { CreateTopicModel createTopicModel = new CreateTopicModel(); createTopicModel.topicModel = new TopicModel(); return(View(createTopicModel)); }
// GET: Topic/Create public ActionResult Create(string courseId) { var model = new CreateTopicModel() { CourseId = courseId }; return(View(model)); }
public async Task <ActionResult> Create(CreateTopicModel model) { if (!ModelState.IsValid) { return(View(model)); } await _service.CreateTopic(model.Title, model.SubjectId, UserData.Id); return(RedirectToAction("TopicList", new { subjectId = model.SubjectId })); }
public ActionResult Create(int chapterId) { LoadValidationErrors(); var chapter = Storage.GetChapter(chapterId); var model = new CreateTopicModel("", chapterId, Storage.GetCourses(), 0, Storage.GetTestTopicTypes(), 0, 0, Storage.GetTheoryTopicTypes(), 0); ViewData["DisciplineName"] = chapter.Discipline.Name; ViewData["ChapterName"] = chapter.Name; return(View(model)); }
public ActionResult Edit(int topicId) { LoadValidationErrors(); var topic = Storage.GetTopic(topicId); var model = new CreateTopicModel(topic.Name, topic.ChapterRef, Storage.GetCourses(), topic.TestCourseRef, Storage.GetTestTopicTypes(), topic.TestTopicTypeRef, topic.TheoryCourseRef, Storage.GetTheoryTopicTypes(), topic.TheoryTopicTypeRef); ViewData["DisciplineName"] = topic.Chapter.Discipline.Name; ViewData["ChapterName"] = topic.Chapter.Name; ViewData["TopicName"] = topic.Name; return(View(model)); }
public ActionResult Edit(CreateTopicModel model) { if (ModelState.IsValid) { var topic = UnitOfWork.GetRepository <Topic>().GetById(model.Id); topic.Title = model.Title; UnitOfWork.GetRepository <Topic>().Update(topic); UnitOfWork.Save(); return(RedirectToAction("Details", new { id = topic.Course.Id })); } return(View("Create", model)); }
public async Task <IActionResult> CreateTopic(CreateTopicModel model) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (!ModelState.IsValid || !_groupsService.IsMember(model.GroupId, userId)) { return(BadRequest()); } var topic = _mapper.Map <DetailsTopicModel>(_groupsService.CreateTopic(userId, model.GroupId, model.Name)); await _groupsHubContext.Clients.Group(model.GroupId.ToString()).SendAsync("TopicCreated", model.GroupId, topic.Id, userId); return(Ok()); }
public async Task <ActionResult> Create(CreateTopicModel model) { if (ModelState.IsValid) { var topic = new Topic() { Course = UnitOfWork.GetRepository <Course>().GetById(model.CourseId), Person = await ApplicationUserManager.FindByNameAsync(User.Identity.Name), Time = DateTime.Now, Title = model.Title }; UnitOfWork.GetRepository <Topic>().Add(topic); UnitOfWork.Save(); return(RedirectToAction("Details", "Course", new { id = topic.Course.Id })); } return(View(model)); }
public ActionResult Create(int chapterId) { try { LoadValidationErrors(); Chapter chapter = Storage.GetChapter(chapterId); var model = new CreateTopicModel(chapterId, Storage.GetCourses(), 0, Storage.GetTopicTypes(), 0, ""); ViewData["DisciplineName"] = chapter.Discipline.Name; ViewData["ChapterName"] = chapter.Name; return(View(model)); } catch (Exception e) { throw e; } }
async Task CreateByModel(CreateTopicModel model) { var a = await ClientSesion.RandomInstance(); var idRes = await a.Api <TopicApi>().CreateTopicAsync(model); var topicId = idRes.Id; // Check topic var topic = await Context.Topics .Where(p => p.Id == Guid.Parse(topicId.ToString())).FirstOrDefaultAsync(); Assert.NotNull(topic); Assert.Equal(model.IsGroup, topic.IsGroup); Assert.Equal(model.Name, topic.Name); Assert.Equal(model.IsGroup, topic.IsGroup); Assert.Equal(1, topic.MemberCount); if (model.RelatedWork != null) { Assert.Equal(model.RelatedWork, topic.RelatedWork.ToString()); } // Check member var members = await Context.TopicMembers .Where(p => p.TopicId == Guid.Parse(topicId.ToString())).ToListAsync(); Assert.Single(members); var member = members[0]; if (model.IsGroup == true) { Assert.Equal(Domain.TopicMemberAG.MemberRole.Super, member.Role); } else { Assert.Equal(Domain.TopicMemberAG.MemberRole.Normal, member.Role); } }
public async Task <IActionResult> CreateTopic(CreateTopicModel model) { var request = new CreateTopicOperationRequest { ParentTopic = model.ParentTopic, Description = model.Description, Subject = model.Subject }; try { await _createTopicOperation.Execute(request); } catch (TopicAlreadyExistsException ex) { return(BadRequest(new ErrorModel(ex.Message))); } return(Ok()); }
public ActionResult Edit(int topicId) { try { LoadValidationErrors(); var topic = Storage.GetTopic(topicId); var model = new CreateTopicModel(topic.ChapterRef, Storage.GetCourses(), topic.CourseRef, Storage.GetTopicTypes(), topic.TopicTypeRef, topic.Name); ViewData["DisciplineName"] = topic.Chapter.Discipline.Name; ViewData["ChapterName"] = topic.Chapter.Name; ViewData["TopicName"] = topic.Name; return(View(model)); } catch (Exception e) { throw e; } }
async Task JoinTopicAndSendDiscussionAndGet() { var a = await ClientSesion.RandomInstance(); var b = await ClientSesion.RandomInstance(); // b create topic (not group) var model = new CreateTopicModel(false, "some-topic-not-group", "aaaa", null); var idRes = await b.Api <TopicApi>().CreateTopicAsync(model); var topicId = idRes.Id; // a send discussion without joining topic await Assert.ThrowsAnyAsync <Exception>( () => a.Api <TopicApi>().SendDiscussionAsync(new SendDiscussionModel(topicId, "aasd", null))); // a join topic await a.Api <TopicApi>().JoinTopicAsync(new JoinTopicModel(topicId.ToString())); // Check member var members = await Context.TopicMembers .Where(p => p.TopicId == Guid.Parse(topicId.ToString())).ToListAsync(); Assert.Equal(2, members.Count); var member = members.Where(p => p.UserId == a.UserId).FirstOrDefault(); Assert.NotNull(member); Assert.Equal(Domain.TopicMemberAG.MemberRole.Normal, member.Role); // a send discussion idRes = await a.Api <TopicApi>().SendDiscussionAsync(new SendDiscussionModel(topicId, "hello1")); // b send discussion idRes = await b.Api <TopicApi>().SendDiscussionAsync(new SendDiscussionModel(topicId, "hello2")); // get posts var posts = await a.Api <TopicApi>().GetDiscussionsAsync(topicId, 0); Assert.Equal(2, posts.Count); }
async Task DoAdmin() { var a = await ClientSesion.RandomInstance(); // Create topic (IsGroup=true) var model = new CreateTopicModel(true, "pin-test-topic", "haha", null); var idRes = await a.Api <TopicApi>().CreateTopicAsync(model); var topicId = idRes.Id.ToString(); // Send Posts await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId, "123", "123123asd1dasd25")); await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId, "123", "123123asd1dasd25")); idRes = await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId, "123", "123123asd1dasd25")); var pinnedId = idRes.Id; await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId, "123", "123123asd1dasd25")); var deleteId = (await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId, "123", "123123asd1dasd25"))).Id; var essenseId = (await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId, "123", "123123asd1dasd25"))).Id; // do admin await a.Api <TopicApi>().DoAdminAsync(new DoAdminModel(pinnedId.ToString(), AdminAction.IsPinned, true)); await a.Api <TopicApi>().DoAdminAsync(new DoAdminModel(deleteId.ToString(), AdminAction.Remove, true)); await a.Api <TopicApi>().DoAdminAsync(new DoAdminModel(essenseId.ToString(), AdminAction.IsEssence, true)); // check var posts = await a.Api <TopicApi>().GetPostsAsync(topicId, 0); Assert.Equal(5, posts.Count); Assert.Equal(pinnedId, posts[0].Id); Assert.DoesNotContain(posts, p => p.Id == deleteId); Assert.Contains(posts, p => p.Id == essenseId && p.IsEssense); }
public static void UpdateFromModel(this Topic topic, CreateTopicModel model) { var testTopicType = model.TestCourseId == Constants.TestWithoutCourseId ? TopicTypeEnum.TestWithoutCourse : model.TestCourseId == Constants.NoCourseId ? (TopicTypeEnum?)null : TopicTypeEnum.Test; var theoryTopicType = model.TheoryCourseId == Constants.NoCourseId ? (TopicTypeEnum?)null : TopicTypeEnum.Theory; topic.ChapterRef = model.ChapterId; topic.Name = model.TopicName; topic.TestCourseRef = model.TestCourseId != Constants.NoCourseId ? model.TestCourseId : (int?)null; topic.TestTopicTypeRef = (int?)testTopicType; topic.TheoryCourseRef = model.TheoryCourseId != Constants.NoCourseId ? model.TheoryCourseId : (int?)null; topic.TheoryTopicTypeRef = (int?)theoryTopicType; }
public ActionResult Edit(int topicId, CreateTopicModel model) { var topic = Storage.GetTopic(topicId); topic.Name = model.TopicName; topic.TestCourseRef = model.BindTestCourse ? model.TestCourseId : (int?)null; topic.TestTopicTypeRef = model.BindTestCourse ? model.TestTopicTypeId : (int?)null; topic.TheoryCourseRef = model.BindTheoryCourse ? model.TheoryCourseId : (int?)null; topic.TheoryTopicTypeRef = model.BindTheoryCourse ? model.TheoryTopicTypeId : (int?)null; AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors); if (ModelState.IsValid) { Storage.UpdateTopic(topic); return(RedirectToRoute("Topics", new { action = "Index", ChapterId = topic.ChapterRef })); } else { SaveValidationErrors(); return(RedirectToAction("Edit")); } }
public JsonResult Create(CreateTopicModel model) { try { var topic = new Topic(); topic.UpdateFromModel(model); AddValidationErrorsToModelState(Validator.ValidateTopic(topic).Errors); if (ModelState.IsValid) { Storage.AddTopic(topic); var viewTopic = topic.ToViewTopicModel(Storage); return(Json(new { success = true, chapterId = model.ChapterId, topicRow = PartialViewAsString("TopicRow", viewTopic) })); } var m = new CreateTopicModel(Storage.GetCourses(), topic); return(Json(new { success = false, chapterId = model.ChapterId, html = PartialViewAsString("Create", m) })); } catch (Exception ex) { return(Json(new { success = false, html = ex.Message })); } }
public ActionResult Create(int chapterId) { var model = new CreateTopicModel(Storage.GetCourses(), new Topic()); return(PartialView("Create", model)); }
async Task JoinTopicAndSendPostAndGetPosts() { var a = await ClientSesion.RandomInstance(); var b = await ClientSesion.RandomInstance(); // b create topic var model = new CreateTopicModel(true, "some-topic", "haha", null); var idRes = await b.Api <TopicApi>().CreateTopicAsync(model); var topicId = idRes.Id; // a send post without join topic await Assert.ThrowsAnyAsync <Exception>( () => a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId.ToString(), "hello", "Hello everyone!"))); // a join topic await a.Api <TopicApi>().JoinTopicAsync(new JoinTopicModel(topicId.ToString())); // Check member var members = await Context.TopicMembers .Where(p => p.TopicId == Guid.Parse(topicId.ToString())).ToListAsync(); Assert.Equal(2, members.Count); var member = members.Where(p => p.UserId == a.UserId).FirstOrDefault(); Assert.NotNull(member); Assert.Equal(Domain.TopicMemberAG.MemberRole.Normal, member.Role); // a send post idRes = await a.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId.ToString(), "hello1", "Hello everyone!")); var post = await a.Api <TopicApi>().GetPostByIdAsync(idRes.Id.ToString()); Assert.Equal("hello1", post.Title); // b send post idRes = await b.Api <TopicApi>().SendPostAsync(new SendPostModel(topicId.ToString(), "hello2", "Hello everyone!")); post = await b.Api <TopicApi>().GetPostByIdAsync(idRes.Id.ToString()); Assert.Equal("hello2", post.Title); // get posts var posts = await a.Api <TopicApi>().GetPostsAsync(topicId.ToString(), 0); Assert.Equal(2, posts.Count); // Send reply var postId = posts[0].Id; idRes = await a.Api <TopicApi>().SendReplyAsync(new SendReplyModel(postId.ToString(), "123123asd1dasd25字数asd12e12312asd")); var replyId = idRes.Id; // Check reply var replies = await a.Api <TopicApi>().GetRepliesAsync(postId.ToString(), 0); Assert.Single(replies); Assert.Equal(replyId, replies[0].Id); }
public ActionResult CreateTopic(CreateTopicModel model) { if (ModelState.IsValid) { ModelContext modelContext = new ModelContext(); decimal topicID = 0; decimal voteTimeID; decimal optionID = 0; foreach (Votetopic votetopic in modelContext.Votetopics) { topicID++; } voteTimeID = topicID; modelContext.Votetimes.Add(new Votetime { Votetimeid = voteTimeID, Votestarttime = model.topicModel.VoteStart, Votestoptime = model.topicModel.VoteEnd }); foreach (Option option in modelContext.Options) { optionID++; } modelContext.Options.Add(new Option { Optionid = optionID, Optiongroupid = topicID, Information = model.topicModel.OptionA.Information, Votes = 0 }); optionID++; modelContext.Options.Add(new Option { Optionid = optionID, Optiongroupid = topicID, Information = model.topicModel.OptionB.Information, Votes = 0 }); modelContext.Votetopics.Add(new Votetopic { Votetopicid = topicID, Maininformation = model.topicModel.Maininformation, Votetimeid = topicID, Optiongroupid = topicID }); List <string> users = model.users.Split(' ').ToList(); List <User> allUsersDB = modelContext.Users.ToList(); decimal permissionID = 0; foreach (var permission in modelContext.Permissions.ToList()) { permissionID++; } foreach (var user in users) { foreach (var userDB in allUsersDB) { if (user == userDB.Emailadress) { modelContext.Permissions.Add(new Permission { Permissionid = permissionID, Usersid = userDB.Userid, Topicsid = topicID, Canvote = 1 }); permissionID++; } } } modelContext.SaveChanges(); modelContext.Dispose(); return(RedirectToAction("ViewTopics")); } return(View()); }