public LessonCommentDTO(LessonComment lessonComment) { Id = lessonComment.Id; Comment = lessonComment.Comment; CreatedBy = new UserDTO(lessonComment.CreatedBy); CreatedTime = lessonComment.CreatedTime; }
private bool BeNotRepliedComment(DeleteCommentCommand command, Guid lessonId) { Lesson lesson = repo.GetById <Lesson>(lessonId); LessonComment comment = lesson.Comments.FirstOrDefault(c => c.ParentId.Equals(command.CommentId)); return(comment == null); }
public ActionResult PushComment(int speakerID, String comment) { int?hearerID = models.GetTable <LessonComment>().Where(c => c.HearerID == speakerID) .OrderByDescending(c => c.CommentDate) .Select(c => (int?)c.SpeakerID).FirstOrDefault(); if (!hearerID.HasValue) { hearerID = models.GetTable <RegisterLesson>().Where(r => r.UID == speakerID) .OrderByDescending(r => r.RegisterID) .Select(r => r.AdvisorID).FirstOrDefault(); } if (hearerID.HasValue) { LessonComment item = new LessonComment { Comment = comment, HearerID = hearerID.Value, SpeakerID = speakerID, CommentDate = DateTime.Now, Status = (int)Naming.IncommingMessageStatus.未讀 }; models.GetTable <LessonComment>().InsertOnSubmit(item); models.SubmitChanges(); return(View("~/Views/LearnerFacet/Module/LessonCommentItem.ascx", item)); } return(new EmptyResult()); }
public LessonComment AddComment(LessonComment comment) { LessonComment insertComment = _ctx.LessonComments.Add(comment); _ctx.SaveChanges(); return(insertComment); }
public IHttpActionResult GetComment(int id) { LessonComment comment = _lessonRepository.GetComment(id); if (comment != null) { return(Ok(new LessonCommentDTO(comment))); } return(NotFound()); }
public bool AddLessonComment(LessonComment comment) { var db = new ClassAppContext(); try { var added = db.LessonComment.Add(comment); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public ActionResult PushComment(int hearerID, String comment) { var profile = HttpContext.GetUser(); LessonComment item = new LessonComment { Comment = comment, HearerID = hearerID, SpeakerID = profile.UID, CommentDate = DateTime.Now, Status = (int)Naming.IncommingMessageStatus.未讀 }; models.GetTable <LessonComment>().InsertOnSubmit(item); models.SubmitChanges(); return(View("~/Views/CoachFacet/Module/LessonCommentItem.ascx", item)); }
public Result <LessonComment> AddComment(int lessonId, LessonCommentDTO dto) { //todo: check has enrolled/attended class LessonComment comment = new LessonComment() { Comment = dto.Comment, CreatedTime = DateTime.UtcNow, CreatedById = UserId, LessonId = lessonId }; _lessonRepository.AddComment(comment); //var response = Request.CreateResponse(HttpStatusCode.Created); // Generate a link to the new book and set the Location header in the response. //string uri = Url.Link("GetCommentById", new { lessonId = lessonId, id = comment.Id }); //response.Headers.Location = new Uri(uri); //return response; Result <LessonComment> res = new Result <LessonComment>(true, comment); return(res); }
public void Handle(DeletedCommentEvent @event) { using (var db = new DisciturContext()) { // get read-model Ids (ID-maps) int lessonId = _identityMapper.GetModelId <Lesson>(@event.Id); int commentId = _identityMapper.GetModelId <LessonComment>(@event.CommentId); Lesson lesson = db.Lessons.Find(lessonId); LessonComment comment = db.LessonComments.Find(commentId); comment.LastModifDate = @event.Date; comment.RecordState = Constants.RECORD_STATE_DELETED; // Persist changes db.Entry(comment).State = EntityState.Modified; // TODO: is it correct to update readModel "devops fields" of lesson in this case? UpdateLessonArchFields(lesson, comment.LastModifUser, @event.Date, @event.Version); // Persist changes db.Entry(lesson).State = EntityState.Modified; db.SaveChanges(); } }
public void Handle(AddedNewCommentEvent @event) { using (var db = new DisciturContext()) { // get read-model Ids (ID-maps) int lessonId = _identityMapper.GetModelId <Lesson>(@event.Id); int userId = _identityMapper.GetModelId <User>(@event.AuthorId); int?parentId = @event.ParentId.Equals(Guid.Empty) ? null : (int?)_identityMapper.GetModelId <LessonComment>(@event.ParentId); // get involved read-model entities User author = db.Users.Find(userId); Lesson lesson = db.Lessons.Find(lessonId); // Create new Read-Model Lesson's Comment LessonComment comment = new LessonComment(); comment.Content = @event.Content; comment.CreationDate = @event.Date; comment.Date = @event.Date; comment.LastModifDate = @event.Date; comment.LessonId = lessonId; comment.Level = @event.Level; comment.ParentId = parentId; comment.Vers = 1; comment.RecordState = Constants.RECORD_STATE_ACTIVE; comment.UserId = userId; comment.Author = author; comment.LastModifUser = author.UserName; db.LessonComments.Add(comment); // Update Lesson's version // TODO: is it correct to update readModel "devops fields" of lesson in this case? UpdateLessonArchFields(lesson, author.UserName, @event.Date, @event.Version); // Persist changes db.Entry(lesson).State = EntityState.Modified; db.SaveChanges(); // Map new IDs // NOTE: Comment is NOT and AR, but it's mapped with it's own Id-map for compatibility with existant read-model _identityMapper.Map <LessonComment>(comment.Id, @event.CommentId); } }
public void Handle(LessonMementoPropagatedEvent @event) { using (var db = new DisciturContext()) { int itemId = _identityMapper.GetModelId <Lesson>(@event.Memento.Id); if (itemId.Equals(0)) { int userId = _identityMapper.GetModelId <User>(@event.Memento.AuthorId); User _user = db.Users.Find(userId); Lesson lesson = new Lesson(); lesson.Title = @event.Memento.Title; lesson.Discipline = @event.Memento.Discipline; lesson.School = @event.Memento.School; lesson.Classroom = @event.Memento.Classroom; lesson.Author = _user; lesson.UserId = _user.UserId; lesson.Content = @event.Memento.Content; lesson.Conclusion = @event.Memento.Conclusion; lesson.PublishDate = @event.Memento.CreationDate; lesson.CreationDate = @event.Memento.CreationDate; UpdateLessonArchFields(lesson, _user.UserName, @event.Memento.CreationDate, @event.Memento.Version); //lesson.LastModifDate = @event.CreationDate; //lesson.LastModifUser = _user.UserName; //lesson.Vers = 1; lesson.RecordState = Constants.RECORD_STATE_ACTIVE; // Create FeedBacks Collection @event.Memento.FeedBacks.ToList() .ForEach(feedback => { LessonFeedback fb = new LessonFeedback() { Feedback = feedback.Feedback, Nature = feedback.Nature, LessonFeedbackGuid = feedback.Id }; lesson.FeedBacks.Add(fb); }); // Create Tags Collection @event.Memento.Tags.ToList() .ForEach(tag => { LessonTag t = new LessonTag() { LessonTagName = tag.LessonTagName }; lesson.Tags.Add(t); }); db.Lessons.Add(lesson); db.SaveChanges(); //Ids mapping _identityMapper.Map <Lesson>(lesson.LessonId, @event.Memento.Id); if (lesson.FeedBacks.Count > 0) { lesson.FeedBacks.ToList() .ForEach(feedback => _identityMapper.Map <LessonFeedback>(feedback.LessonFeedbackId, feedback.LessonFeedbackGuid)); } // Create Ratings Collection List <int> ratingsList = new List <int>(); @event.Memento.Ratings.ToList() .ForEach(r => { int authorId = _identityMapper.GetModelId <User>(r.UserId); User author = db.Users.Find(userId); ratingsList.Add(r.Rating); LessonRating rating = new LessonRating() { LessonId = lesson.LessonId, UserId = authorId, Author = author, Rating = r.Rating, Content = r.Content ?? string.Empty, CreationDate = r.CreationDate, LastModifDate = r.LastModifDate, LastModifUser = r.LastModifUser, Vers = r.Vers, RecordState = Constants.RECORD_STATE_ACTIVE }; // Add new Lesson's Rating db.LessonRatings.Add(rating); db.SaveChanges(); _identityMapper.Map <LessonRating>(rating.Id, r.Id); }); lesson.Rate = ratingsList.Count > 0 ? Math.Max((int)Math.Round(ratingsList.Average()), 1) : 0; // Create Comments Collection @event.Memento.Comments.ToList() .ForEach(c => { // get read-model Ids (ID-maps) int _userId = _identityMapper.GetModelId <User>(c.AuthorId); int?parentId = c.ParentId == null ? null : (int?)_identityMapper.GetModelId <LessonComment>(c.ParentId.Value); // get involved read-model entities User author = db.Users.Find(userId); // Create new Read-Model Lesson's Comment LessonComment comment = new LessonComment() { LessonId = lesson.LessonId, Content = c.Content, CreationDate = c.CreationDate, Date = c.Date, LastModifDate = c.Date, Level = c.Level, ParentId = parentId, Vers = c.Vers, RecordState = Constants.RECORD_STATE_ACTIVE, UserId = _userId, Author = author, LastModifUser = author.UserName }; db.LessonComments.Add(comment); db.SaveChanges(); // Map new IDs // NOTE: Comment is NOT and AR, but it's mapped with it's own Id-map for compatibility with existant read-model _identityMapper.Map <LessonComment>(comment.Id, c.Id); }); // Persist changes db.Entry(lesson).State = EntityState.Modified; db.SaveChanges(); } // otherwise it could be used for maintenance purposes } }