public static ItemCommentModel GetCommentModel(MenuItem menuItem) { ItemCommentModel commentModel = new ItemCommentModel(); commentModel.menuItem = menuItem; ApplicationDbContext db = new ApplicationDbContext(); List <MenuComment> menuComments = db.MenuComments.Where(item => item.ItemID == menuItem.ID).ToList(); commentModel.menuComments = new List <MenuComment>(); foreach (MenuComment menuComment in menuComments) { if (DateTime.Now.Subtract(menuComment.CommentDate).Days < 90) { commentModel.menuComments.Add(menuComment); } } return(commentModel); }
public async Task <CommentItemResult> CommentItemAsync(CommentItemModel commentItemModel) { var validRes = await validatorsStore.CommentItemModelValidator.ValidateAsync(commentItemModel); if (!validRes.Succeed) { return(new CommentItemResult(validRes)); } var comment = mapper.Map <CommentModel>(commentItemModel); await commentsCrudService.CreateAsync(comment); var itemComment = new ItemCommentModel { CommentId = comment.Id, ItemId = commentItemModel.ItemId }; await itemCommentCrudService.CreateAsync(itemComment); var result = mapper.Map <CommentItemResult>(comment); return(result); }