Esempio n. 1
0
        public override Task <ProductResponse> GetProductById(ProductItemRequest request, ServerCallContext context)
        {
            var product = _kernel.GetEntity <eShop.ProductEntities.Entities.Product>(externalId: ParseUserID(id: request.Id));

            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(MapToResponse(product: product)));
        }
Esempio n. 2
0
        public override Task <BasketResponse> AddToBacket(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
            {
                _kernel.AddEntity <eShop.ProductEntities.Entities.Basket>(new eShop.ProductEntities.Entities.Basket
                {
                    Product = product
                }, saveChanges: true);
            }

            return(Task.FromResult(new BasketResponse
            {
                ProductId = product.ExternalId.ToString()
            }));
        }
Esempio n. 3
0
        public override Task <RetailerResponse> GetRetailer(RetailerItemRequest request, ServerCallContext context)
        {
            var user = _kernel.GetEntity <User>(externalId: ParseUserID(id: request.Id));

            ValidateUserType(user);
            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(MapToResponse(user: user)));
        }
Esempio n. 4
0
        public override Task <TokenResponse> ValidToken(TokenRequest request, ServerCallContext context)
        {
            if (request.Token.IsEmpty())
            {
                throw new Exception("please enter token");
            }

            var userToken = _kernel.GetEntities <UserToken>().FirstOrDefault(token => !token.IsExpired && token.ExpiryDate > DateTime.UtcNow &&
                                                                             token.Token == request.Token.Trim());

            User user = null;

            if (!userToken.IsNull())
            {
                user = _kernel.GetEntity <User>(externalId: Guid.Parse(userToken.Token));
            }

            return(Task.FromResult(new TokenResponse
            {
                Id = user.IsNull() ? 0 : user.Id,
                UserType = user.UserType.ToString(),
                IsValid = !userToken.IsNull()
            }));
        }