Example #1
0
        private TEntity AddBefore <TEntity>(TEntity entity) where TEntity : BaseField
        {
            var currentUser = _audience.EntityId();

            if (currentUser > 0)
            {
                entity.CreatedById = currentUser;
            }
            entity.Active     = true;
            entity.CreatedOn  = DateTime.UtcNow;
            entity.ExternalId = Guid.NewGuid();
            return(entity);
        }
Example #2
0
        public override Task <BasketResponse> RemoveFromBasket(BasketRequest request, ServerCallContext context)
        {
            if (request.ProductId.IsEmpty())
            {
                throw new Exception("Invalid product");
            }


            var product = _kernel.GetEntity <eShop.ProductEntities.Entities.Product>(externalId: Guid.Parse(request.ProductId));

            if (product.IsNull())
            {
                throw new Exception("Invalid product");
            }
            else
            {
                var basketProduct = _kernel.GetEntities <eShop.ProductEntities.Entities.Basket>()
                                    .FirstOrDefault(basket => basket.ProductId == product.Id && basket.CreatedById == _audience.EntityId());
                _kernel.DeleteEntity(basketProduct, saveChanges: true);
            }

            return(Task.FromResult(new BasketResponse
            {
                ProductId = product.ExternalId.ToString()
            }));
        }