Inheritance: BaseEntity
        async Task <Game> IRequestHandler <SaveCommentCommand, Game> .Handle(SaveCommentCommand command, CancellationToken cancellationToken)
        {
            var user = _context.Users.FirstOrDefault(item => item.Id == Guid.Parse(command.UserId));

            var game = _context.Games.FirstOrDefault(item => item.Id == Guid.Parse(command.GameId));

            var comment = new Domain.Entities.Comment()
            {
                Id              = new Guid(),
                Text            = command.Comment,
                User            = user,
                Game            = game,
                PublicationDate = DateTime.Now
            };

            _context.Comments.Add(comment);
            await _context.SaveChangesAsync(cancellationToken);

            var result = _context.Games
                         .Include(c => c.Comments).ThenInclude(u => u.User)
                         .FirstOrDefault(item => item.Id == Guid.Parse(command.GameId));

            if (result == null)
            {
                return(null);
            }

            var sortedComments = from c in result.Comments
                                 orderby c.PublicationDate descending
                                 select c;

            result.Comments = sortedComments.ToList();

            return(result);
        }
 private static void CreateNewComments(Candidate destination, CandidateDTO source)
 {
     source.Comments.Where(x => x.IsNew()).ToList().ForEach(newComment =>
     {
         var toDomain = new Comment();
         toDomain.Update(newComment);
         destination.Comments.Add(toDomain);
     });
 }
示例#3
0
        public Order(Customer customer, List<GoodsRow> goods, Comment comment)
        {
            Customer = customer;
            goodsList = new List<GoodsRow>();
            comments = new List<Comment>();

            foreach (GoodsRow row in goods)
            {
                 goodsList.Add(row);
                 TotalCost += row.Price;
            }

            comments.Add(comment);
        }
示例#4
0
 public void SaveComment(Comment comment)
 {
     if (comment.CommentID == 0)
     {
         context.Comments.Add(comment);
     }
     else
     {
         Comment dbEntry = context.Comments.Find(comment.CommentID);
         if (dbEntry != null)
         {
             dbEntry.Name = comment.Name;
             dbEntry.AddedDate = DateTime.Now;
             dbEntry.Review = comment.Review;
             dbEntry.RestarauntID = comment.RestarauntID;
         }
     }
     context.SaveChanges();
 }
 public void AddNewComment(Comment value)
 {
     order.Comments.Add(value);
     commentModel.Add(value);
 }
 /// <summary>
 /// Adds a comment to a blog posts
 /// </summary>
 /// <param name="blogPost"></param>
 /// <param name="comment"></param>
 public void AddCommentToBlogPost(BlogPost blogPost, Comment comment)
 {
     comment.CommentDate = DateTime.Now;
     comment.CommentContent = FormatCommentComment(comment.CommentContent);
     blogPost.Comments.Add(comment);
 }
 /// <summary>
 /// Deletes a comment
 /// </summary>
 /// <param name="comment"></param>
 public void DeleteComment(Comment comment)
 {
     GetUnitOfWork.Comments.DeleteObject(comment);
 }
示例#8
0
        private void saveGoodsButton1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (addGoodsTextBoxName.Text == "" || addGoodsTextBoxSKU.Text == "" || addGoodsTextBoxPrice.Text == "" ||
               addGoodsTextBoxCount.Text == "")
            { MessageBox.Show("Вы заполнили не все поля");
            return;
            }
            if (addGoodsTextBoxName.Text.Length > 255)
            { MessageBox.Show("Значие поля Название слишком длинное");
            return;
            }

            if (addGoodsTextBoxSKU.Text.Length > 50)
            { MessageBox.Show("Значение поля Артикул слишком длинное");
            return;
            }
            double price;
            Int16 count;
            Goods goods = new Goods();
            goods.Name = addGoodsTextBoxName.Text;
            goods.SKU = addGoodsTextBoxSKU.Text;
            if (!Double.TryParse(addGoodsTextBoxPrice.Text, out price))
            { MessageBox.Show("Вы заполнили поле Цена неправильно");
            return;
            };
            goods.Price = price;
            Comment newComment = new Comment();
            newComment.Message = addGoodsTextBoxComent.Text;
            goods.Coments.Add(newComment);
            if (!Int16.TryParse(addGoodsTextBoxCount.Text, out count))
            { MessageBox.Show("Вы заполнили поле Количество неправильно");
            return;
            };
            goods.Count = count;

            if (addGoodsCheckBoxIsActive.Checked)
            {
                goods.IsActive = true;
            }
            else goods.IsActive = false;

            var categorySt = addGoodsLookUpEditCategory.GetColumnValue("Id");
            //goods.Category=categorySt;
            bs.EndEdit();
            presenter.Save();
        }