コード例 #1
0
        public void Handle(IStrategyContext context)
        {
            var book = context.Resolve <BookDto>();

            using (var dbContext = new LibraryEntities())
            {
                if (book.Id != Guid.Empty)
                {
                    var entity = dbContext.Books
                                 .Where(x => x.Id == book.Id)
                                 .SingleOrDefault();
                    Mapper.Map(book, entity);
                    context.Response = entity.Id;
                }
                else
                {
                    var entity = Mapper.Map <Book>(book);
                    entity.Id        = Guid.NewGuid();
                    context.Response = entity.Id;

                    dbContext.Books.Add(entity);
                }

                dbContext.SaveChanges();
            }
        }
コード例 #2
0
        /// <summary>
        /// Finds the implementor of requested TargetStrategyType. The default implementation just takes the first implementor.
        /// Override to do complex matching (e.g. pattern matching) based on context strategy traits
        /// </summary>
        protected virtual Type FindMatchingImplementor(IStrategyContext context)
        {
            var match = StrategyPatternAttribute.MatchBest(context, m_List);

            if (match.any)
            {
                return(match.type);
            }

            return(m_List.FirstOrDefault());
        }
コード例 #3
0
        public void Handle(IStrategyContext context)
        {
            var id = context.Resolve <Guid>();

            using (var dbContext = new LibraryEntities())
            {
                var entity = dbContext.Books.FirstOrDefault(x => x.Id == id);
                if (entity != null)
                {
                    dbContext.Books.Remove(entity);
                    dbContext.SaveChanges();
                }
            }
        }
コード例 #4
0
        public void Handle(IStrategyContext context)
        {
            var dto = context.Resolve<MovieDto>();
            using (var dbContext = new LibraryEntities())
            {
                var entity = dbContext.Movies
                    .Where(x => x.Id == dto.Id)
                    .SingleOrDefault();

                Mapper.Map(dto, entity);

                dbContext.SaveChanges();
            }
        }
コード例 #5
0
        public void Handle(IStrategyContext context)
        {
            var dto = context.Resolve <MovieDto>();

            using (var dbContext = new LibraryEntities())
            {
                var entity = Mapper.Map <Book>(dto);
                entity.Id = Guid.NewGuid();

                dbContext.Books.Add(entity);
                dbContext.SaveChanges();

                context.Response = entity.Id;
            }
        }
コード例 #6
0
        public void Handle(IStrategyContext context)
        {
            var id = context.Resolve <Guid>();

            using (var dbContext = new LibraryEntities())
            {
                if (id != Guid.Empty)
                {
                    var entity = dbContext.Books.FirstOrDefault(x => x.Id == id);
                    context.Response = Mapper.Map <BookDto>(entity);
                }
                else
                {
                    context.Response = dbContext.Books
                                       .AsEnumerable()
                                       .Select(x => Mapper.Map <BookDto>(x))
                                       .ToList();
                }
            }
        }
コード例 #7
0
        public void Execute(IStrategyContext context)
        {
            var interfaceType = typeof(IStrategy);

            var strategyType = Assembly.GetAssembly(interfaceType).GetTypes()
                               .FirstOrDefault(x => x.GetInterfaces().Any(y => interfaceType.IsAssignableFrom(y)) &&
                                               x.CustomAttributes.Any(y => typeof(ApiActionAttribute).IsAssignableFrom(y.AttributeType) &&
                                                                      y.ConstructorArguments.Any(z => z.Value.ToString() == context.Action))

                                               && x.CustomAttributes.Any(y => typeof(ApiVersionAttribute).IsAssignableFrom(y.AttributeType) &&
                                                                         y.ConstructorArguments.Any(z => z.Value.ToString() == context.Version))

                                               && x.CustomAttributes.Any(y => typeof(ApiCommandAttribute).IsAssignableFrom(y.AttributeType) &&
                                                                         y.ConstructorArguments.Any(z => z.Value.ToString() == context.Command)));

            if (strategyType == null)
            {
                strategyType = typeof(NotFoundStrategy);
            }

            var strategy = Activator.CreateInstance(strategyType) as IStrategy;

            strategy.Handle(context);
        }
コード例 #8
0
 public AuthController(IMapper mapper,
                       IStrategyContext strategyContext,
                       IHandleValidation handleValidation) : base(mapper, strategyContext, handleValidation)
 {
 }
コード例 #9
0
 protected BaseApiController(IMapper mapper, IStrategyContext strategyContext, IHandleValidation handleValidation)
 {
     Mapper           = mapper;
     StrategyContext  = strategyContext;
     HandleValidation = handleValidation;
 }
コード例 #10
0
 public void SetContext(IStrategyContext strategyContext)
 {
     this.strategyContext = strategyContext;
 }
コード例 #11
0
 public StrategyContext(IStrategyContext strategyContext)            // Strategy1,Strategy2,Strategy3
 {
     this.strategyContext = strategyContext;
 }
コード例 #12
0
 public AcaoPermissaoHandler(IStrategyContext strategyContext)
 {
     StrategyContext = strategyContext;
 }
コード例 #13
0
 /// <summary>
 /// 事件触发动作
 /// </summary>
 /// <param name="context"></param>
 /// <param name="args"></param>
 public virtual void DoAction(IStrategyContext context, EventArgs args)
 {
 }
コード例 #14
0
 public void Handle(IStrategyContext context)
 {
     throw new NotFoundException();
 }
コード例 #15
0
 public BotActionSelector(ILogger <BotActionSelector> logger, IStrategyContext strategyContext, IBotContext botContext)
 {
     Logger          = logger;
     StrategyContext = strategyContext;
     BotContext      = botContext;
 }
コード例 #16
0
 public EmpreendimentoController(IMapper mapper,
                                 IStrategyContext strategyContext,
                                 IHandleValidation handleValidation) : base(mapper, strategyContext, handleValidation)
 {
 }