public ActionResult Create(FeedbackCreateModel model) { if (this.ModelState.IsValid) { var feedback = new Feedback { Title = model.Title, Content = model.Content }; if (this.User.Identity.IsAuthenticated) { feedback.AuthorId = this.User.Identity.GetUserId(); } this.feedRepo.Add(feedback); this.feedRepo.Save(); this.TempData["Notification"] = "Thanks for the feedback!"; return(this.Redirect("/")); } return(this.View(model)); }
public async Task <SessionFeedbackDto> HandleAsync(FeedbackCreateModel model) { var sessionId = model.SessionId.Value; var userId = model.UserId.Value; var rating = model.Rating.Value; var session = await _gameSessionService.GetAsync(sessionId); if (session == null) { throw new SessionNotFoundException(model.SessionId.Value); } var count = await _feedbackService.GetFeedbackCountPerUserSessionAsync(sessionId : sessionId, userId : userId); if (count > 0) { throw new FeedbackCreateRequestNotAllowedException(sessionId: sessionId, userId: userId); } return(await _feedbackService.AddFeedbackAsync( sessionId : sessionId, userId : userId, rating : rating )); }
public IHttpActionResult CreateNewFeedback(FeedbackCreateModel model) { try { using (DbEntities _db = new DbEntities()) { Feedback _new = new Feedback(); _new.Header = model.Header; _new.Template = model.Template; _new.CreatedBy = model.CreatedBy; _new.CreatedDate = model.Created; _new.UpdatedBy = model.CreatedBy; _db.Feedback.Add(_new); _db.SaveChanges(); return(Ok(_new.Id)); } } catch (Exception ex) { //Debug.WriteLine(ex.Message); return(Ok()); //return ex.InnerException.Message.ToString(); } }
public FeedbackCreateModel Create(string requestBody, IHeaderDictionary headers, Guid?sessionId) { var ratingModel = JsonConvert.DeserializeObject <RatingModel>(requestBody ?? string.Empty); var model = new FeedbackCreateModel() { SessionId = sessionId }; if (!String.IsNullOrEmpty(ratingModel?.Rating)) { if (byte.TryParse(ratingModel.Rating, out var ratingValue)) { model.Rating = ratingValue; } } if (headers != null && headers.Any() && headers.TryGetValue(UserIdHeaderName, out var headerValue)) { var strUserId = headerValue.FirstOrDefault(); if (!String.IsNullOrEmpty(strUserId)) { if (Guid.TryParse(strUserId, out var userId)) { model.UserId = userId; } } } return(model); }
public void HandleAsync_InvalidSessionId_ExceptionThrown() { //Arrange var gameSessionServiceMock = new Mock <IGameSessionService>(); GameSessionDto nullDto = null; gameSessionServiceMock.Setup(m => m.GetAsync(It.IsAny <Guid>())).ReturnsAsync <IGameSessionService, GameSessionDto>(nullDto); var feedbackServiceMock = new Mock <IFeedbackService>(); var handler = new FeedbackCreateRequestHandler(gameSessionServiceMock.Object , feedbackServiceMock.Object); var model = new FeedbackCreateModel { SessionId = ExpectedTestData.GameSessionIds[0], UserId = Guid.NewGuid(), Rating = 4 }; // Act AsyncTestDelegate actDelegate = async() => await handler.HandleAsync(model); //Assert Assert.ThrowsAsync <SessionNotFoundException>(actDelegate); gameSessionServiceMock.Verify(m => m.GetAsync(It.IsAny <Guid>()) , Times.Once()); }
public async Task HandleAsync_ValidData_Pass() { //Arrange var userId = Guid.NewGuid(); var sessionId = ExpectedTestData.GameSessionIds[0]; byte rating = 4; var gameSessionServiceMock = new Mock <IGameSessionService>(); GameSessionDto gameDto = new GameSessionDto() { Id = ExpectedTestData.GameSessionIds[0], }; var feedbackDto = new SessionFeedbackDto() { UserId = userId, SessionId = sessionId, Rating = rating }; gameSessionServiceMock.Setup(m => m.GetAsync(sessionId)).ReturnsAsync <IGameSessionService, GameSessionDto>(gameDto); var feedbackServiceMock = new Mock <IFeedbackService>(); feedbackServiceMock.Setup(m => m.GetFeedbackCountPerUserSessionAsync (sessionId, userId)).ReturnsAsync(0); feedbackServiceMock.Setup(f => f.AddFeedbackAsync(sessionId, userId, rating)) .ReturnsAsync(feedbackDto); var handler = new FeedbackCreateRequestHandler(gameSessionServiceMock.Object , feedbackServiceMock.Object); var createModel = new FeedbackCreateModel { SessionId = sessionId, UserId = userId, Rating = rating }; // Act var actualFeedbackDto = await handler.HandleAsync(createModel); //Assert Assert.NotNull(actualFeedbackDto); Assert.That(actualFeedbackDto.UserId, Is.EqualTo(feedbackDto.UserId)); Assert.That(actualFeedbackDto.SessionId, Is.EqualTo(feedbackDto.SessionId)); Assert.That(actualFeedbackDto.Rating, Is.EqualTo(feedbackDto.Rating)); gameSessionServiceMock.Verify(m => m.GetAsync(sessionId) , Times.Once()); feedbackServiceMock.Verify(m => m.GetFeedbackCountPerUserSessionAsync (sessionId, userId) , Times.Once()); feedbackServiceMock.Verify(m => m.AddFeedbackAsync (sessionId, userId, rating) , Times.Once()); }
public ActionResult Create() { var recentFeedback = _feedbackService.GetActiveItem(); if (recentFeedback == null || recentFeedback.Status == EnumFbStatus.Closed) { //测试的时候放到下面去了,还没拉上来呢... //这两句 var newFeedback = new FeedbackCreateModel(); return(View(newFeedback)); } return(Content("<script type='text/javascript'>alert('抱歉,因新的反馈处于待开始或进行中,导致现在不能创建!');history.go(-1);</script>")); }
public IActionResult AddFeedback(FeedbackCreateModel model) { Feedback feedback = new Feedback { Date = DateTime.Now, Email = model.Email, Message = model.Message, Name = model.Name }; if (model.UserName != null) { feedback.UserId = _userManager.FindByNameAsync(model.UserName).Result.Id; feedback.Email = _userManager.FindByNameAsync(model.UserName).Result.Email; } _repository.Create(feedback); return(RedirectToAction("MessageComplete")); }
public ActionResult Create(FeedbackCreateModel model) { if (!ModelState.IsValid) { return(View(model)); } var recentFeedback = _feedbackService.GetActiveItem(); if (recentFeedback == null || recentFeedback.Status == EnumFbStatus.Closed) { var feedbackDto = new FeedbackDto { FeedbackName = model.Title, StartTime = model.StartTime == null ? DateTime.Now : (DateTime)model.StartTime, EndTime = model.EndTime == null ? DateTime.Now : (DateTime)model.EndTime }; feedbackDto.JudgeStatus(); _feedbackService.AddFeedback(feedbackDto); return(RedirectToAction("Index")); } return(View(model)); }
public void HandleAsync_UserSubmitMoreThanOnceInSession_ExceptionThrown() { //Arrange var gameSessionServiceMock = new Mock <IGameSessionService>(); GameSessionDto gameDto = new GameSessionDto() { Id = ExpectedTestData.GameSessionIds[0], }; gameSessionServiceMock.Setup(m => m.GetAsync(It.IsAny <Guid>())).ReturnsAsync <IGameSessionService, GameSessionDto>(gameDto); var feedbackServiceMock = new Mock <IFeedbackService>(); feedbackServiceMock.Setup(m => m.GetFeedbackCountPerUserSessionAsync (It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(1); var handler = new FeedbackCreateRequestHandler(gameSessionServiceMock.Object , feedbackServiceMock.Object); var model = new FeedbackCreateModel { SessionId = ExpectedTestData.GameSessionIds[0], UserId = Guid.NewGuid(), Rating = 4 }; // Act AsyncTestDelegate actDelegate = async() => await handler.HandleAsync(model); //Assert Assert.ThrowsAsync <FeedbackCreateRequestNotAllowedException>(actDelegate); gameSessionServiceMock.Verify(m => m.GetAsync(It.IsAny <Guid>()) , Times.Once()); feedbackServiceMock.Verify(m => m.GetFeedbackCountPerUserSessionAsync (It.IsAny <Guid>(), It.IsAny <Guid>()) , Times.Once()); }
public async Task <ActionResult> Edit(CreateOrEditContentModel model, string SubmitType = "Save") { if (ModelState.IsValid) { model.CreatedBy = CurrentUser.UserId.Value; var currentFileName = model.File; model.File = null; var modelFileDocument = model.FileDocument; // check slideshare url and change to embed code if (model.ContentType == CourseContentType.Document) { await GetAllDocument(model.CourseId, model.ContentFileId != null?model.ContentFileId.Value : -1); if (model.DocumentType == DocumentType.UseSlideshare) { if (!model.Url.Contains("embed_code")) { model.Url = await SlideshareHelper.GetEmbedCode(model.Url); } } } if (model.IsFeedbackOn > 0) { if (model.FeedbackId == null) { FeedbackCreateModel _new = new FeedbackCreateModel(); _new.CreatedBy = model.CreatedBy; _new.Created = model.CreatedDate; var _createFeedback = await WepApiMethod.SendApiAsync <int>(HttpVerbs.Post, ContentApiUrl.CreateFeedback, _new); if (_createFeedback.isSuccess) { model.FeedbackId = _createFeedback.Data; } } } var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, ContentApiUrl.Edit, model); if (response.isSuccess) { TempData["SuccessMessage"] = "Content successfully edited."; await LogActivity(Modules.Learning, "Edit content : " + model.Title); // Check if this creation include fileupload, which will require us to save the file model.File = currentFileName; if (((model.ContentType == CourseContentType.Video && model.VideoType == VideoType.UploadVideo) || (model.ContentType == CourseContentType.Audio && model.AudioType == AudioType.UploadAudio) || (model.ContentType == CourseContentType.Document && model.DocumentType == DocumentType.UploadDocument) || (model.ContentType == CourseContentType.Flash) || (model.ContentType == CourseContentType.Pdf) || (model.ContentType == CourseContentType.Powerpoint)) && model.File != null) { // upload the file var result = await new FileController().UploadToApi <List <FileDocumentModel> >(model.File); if (result.isSuccess) { var data = result.Data; var fileDocument = data[0]; fileDocument.FileType = model.ContentType.ToString(); fileDocument.CreatedBy = CurrentUser.UserId.Value; fileDocument.ContentFileType = model.FileType; fileDocument.CourseId = model.CourseId; fileDocument.ContentId = model.Id; if (model.ContentType == CourseContentType.Audio) { fileDocument.ContentFileType = FileType.Audio; } if (model.ContentType == CourseContentType.Video) { fileDocument.ContentFileType = FileType.Video; } if (model.ContentType == CourseContentType.Document) { fileDocument.ContentFileType = FileType.Document; } var resultUpload = await WepApiMethod.SendApiAsync <string>(HttpVerbs.Post, FileApiUrl.UploadInfo, fileDocument); if (resultUpload.isSuccess) { model.ContentFileId = int.Parse(resultUpload.Data); } else { TempData["ErrorMessage"] = "Cannot upload file"; } } } if (SubmitType.Equals("SaveAndView")) { return(RedirectToAction("View", "CourseContents", new { area = "eLearning", @id = model.Id })); } else { return(RedirectToAction("Content", "CourseModules", new { area = "eLearning", @id = model.CourseModuleId })); } } } TempData["ErrorMessage"] = "Cannot edit content."; await GetAllQuestions(model.CourseId); return(View(model)); }