Exemple #1
0
        public UserDTO AssignUserGroup(Guid userid, IDList groupids)
        {
            List <Guid> gids = new List <Guid>();

            groupids.ForEach(m =>
            {
                Guid id = new Guid();
                if (Guid.TryParse(m, out id))
                {
                    gids.Add(id);
                }
            });
            var user = userRepository.Find(Specification <User> .Eval(u => u.ID.Equals(userid)));

            using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, bus))
            {
                if (user == null)
                {
                    throw new NullReferenceException("无法找指定的用户");
                }

                var groups = groupRespository.GetAll((Specification <Group> .Eval(g => gids.Contains(g.ID)))).ToList();
                user.Groups = groups;
                userRepository.Update(user);
                user.UpdateGroup();
                coordinator.Commit();
            }
            return(Mapper.Map <User, UserDTO>(user));
        }
Exemple #2
0
        public UserDTO AssignUserRole(Guid userid, IDList roleids)
        {
            List <Guid> rids = new List <Guid>();

            roleids.ForEach(m =>
            {
                Guid id = new Guid();
                if (Guid.TryParse(m, out id))
                {
                    rids.Add(id);
                }
            });
            var user = userRepository.Find(Specification <User> .Eval(u => u.ID.Equals(userid)));

            using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, bus))
            {
                if (user == null)
                {
                    throw new NullReferenceException("无法找指定的用户");
                }
                var roles = roleRepository.GetAll((Specification <Role> .Eval(r => rids.Contains(r.ID)))).ToList();;
                user.Roles = roles;
                userRepository.Update(user);
                user.UpdateRole();
                coordinator.Commit();
            }
            return(Mapper.Map <User, UserDTO>(user).ToViewModel());
        }
        public void Save(Product product)
        {
            //_context = ServiceLocator.Instance.GetService<IContext>();

            using (ITransactionCoordinator tran = TransactionCoordinatorFactory.Create(_context))
            {
                _event_Product.Save(product);
                tran.Commit();
            }
        }
Exemple #4
0
 /// <summary>
 /// 销售订单确认。
 /// </summary>
 /// <param name="orderID">需要被确认的销售订单的全局唯一标识。</param>
 public void Confirm(Guid orderID)
 {
     using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, EventBus))
     {
         var salesOrder = salesOrderRepository.GetByKey(orderID);
         salesOrder.Confirm();
         salesOrderRepository.Update(salesOrder);
         coordinator.Commit();
     }
 }
 /// <summary>
 /// 预定取消
 /// </summary>
 /// <param name="ReservationId">预定Id</param>
 public void Cancel(Guid ReservationId)
 {
     using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, bus))
     {
         Reservation reservation = reservationRepository.GetByKey(ReservationId);
         reservation.Cancel();
         reservationRepository.Update(reservation);
         coordinator.Commit();
     }
 }
 public void Dispatch(Guid orderID)
 {
     using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(Context, bus))
     {
         var salesOrder = salesOrderRepository.Get(orderID);
         salesOrder.Dispatch();
         salesOrderRepository.Update(salesOrder);
         coordinator.Commit();
     }
 }
        public void TestMethod1()
        {
            var context = RF.Concrete <IRepositoryContext>();// new EntityFrameworkRepositoryContext(new EFTestDbContext());
            var bus     = new MSMQEventBus(Helper.EventBus_MessageQueue);
            var repo    = RF.Concrete <IUserRepository>();
            var entity  = new User {
                ID = Guid.NewGuid(), Name = "EventsUnitTest", Email = "*****@*****.**", Password = "******"
            };

            repo.Create(entity);
            repo.Context.Commit();
            using (ITransactionCoordinator coordinator = TransactionCoordinatorFactory.Create(context, bus))
            {
                var tongz = repo.GetByKey(entity.ID);
                tongz.ChangeEmail("*****@*****.**");
                coordinator.Commit();
            }
        }
Exemple #8
0
        private IEnumerable <InfoRuleState> GetInfoRules()
        {
            IEnumerable <IInfoRule> validatorPlugs = null;

            using (var catalog = new DirectoryCatalog(Path.Combine(_acDomain.GetPluginBaseDirectory(PluginType.InfoConstraint), "Bin")))
            {
                using (var container = new CompositionContainer(catalog))
                {
                    var infoRuleImport = new InfoRuleImport();
                    infoRuleImport.ImportsSatisfied += (sender, e) =>
                    {
                        validatorPlugs = e.InfoRules;
                    };
                    container.ComposeParts(infoRuleImport);
                }
            }

            var  infoRuleRepository = _acDomain.RetrieveRequiredService <IRepository <InfoRule, Guid> >();
            var  oldEntities        = infoRuleRepository.AsQueryable().ToList();
            var  deleteList         = new List <InfoRule>();
            var  newList            = new List <InfoRule>();
            var  infoRules          = new List <InfoRuleState>();
            var  entities           = new List <InfoRule>();
            bool saveChanges        = false;

            foreach (var item in validatorPlugs)
            {
                var entity = new InfoRule(item.Id)
                {
                    IsEnabled = 0
                };
                var oldEntity = oldEntities.FirstOrDefault(a => a.Id == item.Id);
                if (oldEntity != null)
                {
                    ((IEntityBase)entity).CreateBy     = oldEntity.CreateBy;
                    ((IEntityBase)entity).CreateOn     = oldEntity.CreateOn;
                    ((IEntityBase)entity).CreateUserId = oldEntity.CreateUserId;
                    entity.IsEnabled = oldEntity.IsEnabled;
                    ((IEntityBase)entity).ModifiedBy     = oldEntity.ModifiedBy;
                    ((IEntityBase)entity).ModifiedOn     = oldEntity.ModifiedOn;
                    ((IEntityBase)entity).ModifiedUserId = oldEntity.ModifiedUserId;
                }
                entities.Add(entity);
                infoRules.Add(InfoRuleState.Create(entity, item));
            }
            // 待添加的新的
            foreach (var item in entities)
            {
                var item1 = item;
                var old   = oldEntities.FirstOrDefault(a => a.Id == item1.Id);
                if (old == null)
                {
                    newList.Add(item);
                }
            }
            // 待移除的旧的
            foreach (var oldEntity in oldEntities)
            {
                var item2  = oldEntity;
                var entity = entities.FirstOrDefault(a => a.Id == item2.Id);
                if (entity == null)
                {
                    deleteList.Add(oldEntity);
                }
            }
            if (newList.Count > 0)
            {
                saveChanges = true;
                foreach (var item in newList)
                {
                    infoRuleRepository.Context.RegisterNew(item);
                }
            }
            if (deleteList.Count > 0)
            {
                saveChanges = true;
                foreach (var item in deleteList)
                {
                    infoRuleRepository.Context.RegisterDeleted(item);
                }
            }
            if (saveChanges)
            {
                using (var coordinator = TransactionCoordinatorFactory.Create(infoRuleRepository.Context, _acDomain.EventBus))
                {
                    coordinator.Commit();
                }
            }

            return(infoRules);
        }