예제 #1
0
        public override Task <LoginResponse> HandleLogin(LoginRequest request, ServerCallContext context)
        {
            if (request.Email.IsEmpty())
            {
                throw new Exception("please enter email address");
            }

            if (request.Password.IsEmpty())
            {
                throw new Exception("please enter password");
            }

            var user = _kernel.GetEntities <User>().FirstOrDefault(user => user.PersonalEmail != null &&
                                                                   user.PersonalEmail.ToLower() == request.Email.ToLower().Trim());

            if (user.IsNull())
            {
                throw new Exception("Invalid email address");
            }
            else if (user.Password != request.Password)
            {
                throw new Exception("Incorrect password");
            }

            return(Task.FromResult(new LoginResponse
            {
                FullName = user.Name,
                Token = GenerateToken(user: user)
            }));
        }
예제 #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()
            }));
        }
예제 #3
0
        public override Task <PaginatedRetailerResponse> GetRetailers(RetailerItemsRequest request, ServerCallContext context)
        {
            var result = _kernel.GetEntities <User>().Where(user => user.UserType == UserType.Retailer);

            if (!string.IsNullOrWhiteSpace(request.Search))
            {
                result = result.Where(user => user.Name.Contains(request.Search));
            }

            var itemsOnPage = result
                              .OrderBy(c => c.ModifiedOn).ThenBy(c => c.ModifiedOn)
                              .Skip(request.PageSize * request.PageIndex).Take(request.PageSize).ToList();
            var model = this.MapToResponse(itemsOnPage, result.Count(), request.PageIndex, request.PageSize);

            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(model));
        }
예제 #4
0
        private User AddUpdateUser(string name, Guid referenceId, UserType type)
        {
            var user = _kernel.GetEntities <User>().FirstOrDefault(user => user.InternalReference == referenceId);

            if (user.IsNull())
            {
                user = new User {
                    Name = name, InternalReference = referenceId, UserType = type
                };
                _kernel.AddEntity(entity: user);
            }
            else
            {
                user.Name = name;
                _kernel.UpdateEntity(entity: user);
            }
            _kernel.SaveChanges();
            return(user);
        }