Exemplo n.º 1
0
        private Brand GetBrand(eShop.ProductAPI.ProductBrand brandDto)
        {
            if (brandDto.IsNull())
            {
                return(null);
            }

            var brand = _kernel.GetEntity <Brand>(externalId: ParseUserID(brandDto.Id));

            if (brand.IsNull())
            {
                brand = new Brand
                {
                    Name = brandDto.Name
                };
                _kernel.AddEntity(entity: brand, saveChanges: true);
            }
            else if (!brandDto.Name.Equals(brand.Name, StringComparison.OrdinalIgnoreCase))
            {
                brand.Name = brandDto.Name;
                _kernel.UpdateEntity(entity: brand, saveChanges: true);
            }

            return(brand);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public override Task <CustomerResponse> UpdateCustomer(CustomerUpdateRequest request, ServerCallContext context)
        {
            var user = _kernel.GetEntity <User>(externalId: ParseUserID(id: request.Id));

            ValidateUserType(user);

            user.PersonalEmail = request.Email;
            user.City          = request.City;
            user.ContactNumber = request.ContactNumber;
            user.ModifiedOn    = DateTime.UtcNow;
            user.Line1         = request.Line1;
            user.Line2         = request.Line2;
            user.Name          = request.Name;
            user.State         = request.State;
            user.Zipcode       = request.Zipcode;
            _kernel.UpdateEntity(entity: user, saveChanges: true);
            ValidateUserType(user);
            context.Status = new Status(StatusCode.OK, string.Empty);
            return(Task.FromResult(MapToResponse(user: user)));
        }