コード例 #1
0
        public async Task <CommentLoadModel> Load()
        {
            var model = new CommentLoadModel()
            {
                Comments = await _commentRepository.GetAllBy(item => item.Map())
            };

            return(model);
        }
コード例 #2
0
        public async Task <int> Save_Update(CommentLoadModel model)
        {
            if (model.Id == 0)
            {
                var entity = await _commentRepository.Create(new RComment()
                {
                    Comment = model.Comment,
                    Name    = model.Name
                });

                return(entity.Id);
            }

            var e = await _commentRepository.GetById(model.Id);

            e.Comment = model.Comment;
            e.Name    = model.Name;
            await _commentRepository.Update(e);

            return(e.Id);
        }
コード例 #3
0
        public async Task <int> AddComment(CommentLoadModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                User         user    = VirtualBD.Users.Find(x => x.Email == User.Identity.Name);
                CommentModel comment = new CommentModel();

                comment.articleID = model.articleID;
                comment.Name      = user.Name;
                comment.Time      = DateTime.Now.ToString();
                comment.text      = model.text;
                comment.Creator   = user.Email;

                if (model.uploadedFile != null)
                {
                    await templateMetod.UploadFileAsync("/Img/UserImg/" + model.uploadedFile.FileName, model.uploadedFile, _appEnvironment);

                    comment.Img = "/Img/UserImg/" + model.uploadedFile.FileName;
                }
                else
                {
                    comment.Img = null;
                }

                try
                {
                    db.Comments.Add(comment);
                    await db.SaveChangesAsync();

                    VirtualBD.Comments.Add(comment);
                }
                catch (Exception e)
                {
                    _logger.LogError("LogError {0}", DateTime.Now.ToString() + "==>" + e.Message);
                }

                templateMetod.newEvent(db, $"Коментарий к <a href=\"/Articles/Article?id={model.articleID}\">статье</a>", User.Identity.Name, user.Name, model.text);
            }
            return(0);
        }
コード例 #4
0
        public async Task <IActionResult> CustomerComments_Save(CommentLoadModel model)
        {
            await _commentService.Save_Update(model);

            return(RedirectToAction("CustomerComments"));
        }