Esempio n. 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();
            }
        }
Esempio n. 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());
        }
        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();
                }
            }
        }
        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();
            }
        }
        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;
            }
        }
        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();
                }
            }
        }
Esempio n. 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);
        }
 public AuthController(IMapper mapper,
                       IStrategyContext strategyContext,
                       IHandleValidation handleValidation) : base(mapper, strategyContext, handleValidation)
 {
 }
 protected BaseApiController(IMapper mapper, IStrategyContext strategyContext, IHandleValidation handleValidation)
 {
     Mapper           = mapper;
     StrategyContext  = strategyContext;
     HandleValidation = handleValidation;
 }
Esempio n. 10
0
 public void SetContext(IStrategyContext strategyContext)
 {
     this.strategyContext = strategyContext;
 }
Esempio n. 11
0
 public StrategyContext(IStrategyContext strategyContext)            // Strategy1,Strategy2,Strategy3
 {
     this.strategyContext = strategyContext;
 }
Esempio n. 12
0
 public AcaoPermissaoHandler(IStrategyContext strategyContext)
 {
     StrategyContext = strategyContext;
 }
Esempio n. 13
0
 /// <summary>
 /// 事件触发动作
 /// </summary>
 /// <param name="context"></param>
 /// <param name="args"></param>
 public virtual void DoAction(IStrategyContext context, EventArgs args)
 {
 }
 public void Handle(IStrategyContext context)
 {
     throw new NotFoundException();
 }
Esempio n. 15
0
 public BotActionSelector(ILogger <BotActionSelector> logger, IStrategyContext strategyContext, IBotContext botContext)
 {
     Logger          = logger;
     StrategyContext = strategyContext;
     BotContext      = botContext;
 }
Esempio n. 16
0
 public EmpreendimentoController(IMapper mapper,
                                 IStrategyContext strategyContext,
                                 IHandleValidation handleValidation) : base(mapper, strategyContext, handleValidation)
 {
 }