public void Update(string newName, string newSlug, int entityId, EntityTypeWithId entityTypeId) { var entity = _entityRepository.Query().First(x => x.EntityId == entityId && x.EntityTypeId == (int)entityTypeId); entity.Name = newName; entity.Slug = newSlug; }
/// <summary> /// 自动好评 /// </summary> /// <param name="entityId"></param> /// <param name="entityTypeId"></param> /// <param name="sourceId"></param> /// <param name="sourceType"></param> /// <returns></returns> public async Task ReviewAutoGood(int entityId, EntityTypeWithId entityTypeId, int?sourceId, ReviewSourceType?sourceType) { var systemUserId = (int)UserWithId.System; User user = null; if (sourceType != null && sourceId != null) { if (sourceType == ReviewSourceType.Order && entityTypeId == EntityTypeWithId.Product) { var anyProduct = _orderRepository.Query().Any(c => c.Id == sourceId.Value && c.OrderItems.Any(x => x.ProductId == entityId)); if (!anyProduct) { return; } var order = await _orderRepository.Query().FirstOrDefaultAsync(c => c.Id == sourceId.Value); if (order == null) { return; } if (order.OrderStatus != OrderStatus.Complete) { return; } user = await _userRepository.FirstOrDefaultAsync(order.CustomerId); } } // 一个用户 // 评论 某订单 某商品只能一次 // 评论 无订单关联 评论商品只能一次 var any = await _reviewRepository.Query().AnyAsync(c => c.EntityTypeId == (int)entityTypeId && c.EntityId == entityId && c.SourceId == sourceId && c.SourceType == sourceType); if (any) { return; } var review = new Review { Rating = 5, Comment = "默认好评", EntityId = entityId, EntityTypeId = (int)entityTypeId, SourceId = sourceId, SourceType = sourceType, UserId = user?.Id ?? systemUserId, IsSystem = true, IsAnonymous = true, Status = ReviewStatus.Approved, ReviewerName = user == null ? "***" : $"{user.FullName.First()}***{user.FullName.Last()}" }; _reviewRepository.Add(review); await _reviewRepository.SaveChangesAsync(); }
public async Task Remove(int entityId, EntityTypeWithId entityTypeId) { var entity = _entityRepository.Query().FirstOrDefault(x => x.EntityId == entityId && x.EntityTypeId == (int)entityTypeId); if (entity != null) { await _mediator.Publish(new EntityDeleting { EntityId = entity.Id }); _entityRepository.Remove(entity); } }
public void Add(string name, string slug, int entityId, EntityTypeWithId entityTypeId) { var entity = new Entity { Name = name, Slug = slug, EntityId = entityId, EntityTypeId = (int)entityTypeId }; _entityRepository.Add(entity); }
public string ToSafeSlug(string slug, int entityId, EntityTypeWithId entityTypeId) { if (string.IsNullOrWhiteSpace(slug)) { throw new ArgumentNullException(nameof(slug)); } var i = 2; while (true) { var entity = _entityRepository.Query().FirstOrDefault(x => x.Slug == slug); if (entity != null && !(entity.EntityId == entityId && entity.EntityTypeId == (int)entityTypeId)) { slug = string.Format("{0}-{1}", slug, i); i++; } else { break; } } return(slug); }
public Entity Get(int entityId, EntityTypeWithId entityTypeId) { return(_entityRepository.Query().FirstOrDefault(x => x.EntityId == entityId && x.EntityTypeId == (int)entityTypeId)); }