Example #1
0
        public void Link(IRepositoryManager repositoryManager, TDestination @object)
        {
            var sourceRepo      = repositoryManager.GetCommonRepository <TSource>();
            var collectionValue = GetReverseCollection(@object);

            var predicate = ReversePredicate(@object);

            foreach (var related in sourceRepo.Find().Where(predicate).Where(CanAddToCollectionPredicate(collectionValue)))
            {
                collectionValue.Add(related);
            }

            if (collectionValue != null)
            {
                foreach (var collectionItem in collectionValue)
                {
                    if (@object.Id != 0)
                    {
                        _fkIdAccessor.SetValue(collectionItem, @object.Id);
                    }
                    if (_navPropertyAccessor.GetValue(collectionItem) == null)
                    {
                        _navPropertyAccessor.SetValue(collectionItem, @object);
                    }
                }
            }
        }
Example #2
0
        public void Link(IRepositoryManager repositoryManager, TSource @object)
        {
            var destRepo         = repositoryManager.GetCommonRepository <TDestination>();
            var idValue          = _fkIdAccessor.GetValue(@object);
            var navPropertyValue = _navPropertyAccessor.GetValue(@object);
            var idHasValue       = idValue != null && idValue != 0;

            if (!idHasValue && navPropertyValue != null)
            {
                _fkIdAccessor.SetValue(@object, navPropertyValue.Id);
            }
            else if (idHasValue)
            {
                navPropertyValue = destRepo.FindById(idValue.Value);
                _navPropertyAccessor.SetValue(@object, navPropertyValue);
            }
            if (navPropertyValue != null && _reverseAccessor != null)
            {
                var collection = GetReverseCollection(navPropertyValue);
                if (CanAddToCollectionPredicate(collection)(@object))
                {
                    collection.Add(@object);
                }
            }
        }
        private OrganizationEntity SaveOrganization(UserInfo userInfo)
        {
            var  repository = _repositoryManager.GetCommonRepository <OrganizationEntity>();
            var  entity     = repository.Find(x => x.Inn == userInfo.OrganizationInn).FirstOrDefault();
            bool isNew      = entity == null;

            entity      = entity ?? new OrganizationEntity();
            entity.Id   = entity?.Id ?? 0;
            entity.Inn  = userInfo.OrganizationInn;
            entity.Name = userInfo.OrganizationName;
            if (isNew)
            {
                repository.Add(entity);
            }
            return(entity);
        }
Example #4
0
        public void Register(UserDto user)
        {
            if (_userRepository.GetAll().Where(x => x.Email == user.Email).Any())
            {
                throw new ServiceException(ServiceExceptionType.UserAlreadyExist);
            }

            var _user = new DbUser {
                Email = user.Email, Name = user.Name, Password = user.Password
            };
            var _account = new DbAccount {
                UserId = _user.Id, Balance = 100
            };

            _userRepository.Add(_user);

            _repositoryManager.GetCommonRepository <DbAccount>().Add(_account);
            _repositoryManager.SaveChanges();
        }