コード例 #1
0
ファイル: ProductService.cs プロジェクト: msmansoori/eShop
        public override Task <ProductResponse> AddProduct(ProductRequest request, ServerCallContext context)
        {
            UserValidation();

            var brand   = GetBrand(request.Brand);
            var product = new eShop.ProductEntities.Entities.Product
            {
                AvailableStock = Convert.ToInt32(request.AvailableStock),
                Brand          = brand
            };

            _kernel.AddEntity(entity: product, saveChanges: true);
            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(MapToResponse(product: product)));
        }
コード例 #2
0
ファイル: RetailerService.cs プロジェクト: msmansoori/eShop
        public override Task <RetailerResponse> AddRetailer(RetailerRequest request, ServerCallContext context)
        {
            if (request.PersonalEmail.IsEmpty() || request.Password.IsEmpty())
            {
                throw new Exception("Email and password are required");
            }
            var user = _kernel.GetEntities <User>().FirstOrDefault(user => user.PersonalEmail.ToLower() == request.PersonalEmail.Trim().ToLower());

            if (!user.IsNull())
            {
                throw new Exception("Email address already exist");
            }

            user = new User
            {
                PersonalEmail = request.PersonalEmail,
                BusinessEmail = request.BusinessEmail,
                City          = request.City,
                ContactNumber = request.ContactNumber,
                Line1         = request.Line1,
                Line2         = request.Line2,
                Name          = request.Name,
                Password      = request.Password,
                State         = request.State,
                UserType      = UserType.Retailer,
                Zipcode       = request.Zipcode
            };
            _kernel.AddEntity(entity: user, saveChanges: true);
            ValidateUserType(user);
            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(MapToResponse(user: user)));
        }
コード例 #3
0
ファイル: BasketService.cs プロジェクト: msmansoori/eShop
        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()
            }));
        }
コード例 #4
0
ファイル: AuthService.cs プロジェクト: msmansoori/eShop
        private string GenerateToken(User user)
        {
            var token = _kernel.AddEntity(new UserToken {
                Token = user.ExternalId.ToString(), ExpiryDate = DateTime.UtcNow.AddMinutes(10)
            }, saveChanges: true);

            return(token.Token);
        }
コード例 #5
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);
        }