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(); } }
/// <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(); } } }
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; }
public void SetContext(IStrategyContext strategyContext) { this.strategyContext = strategyContext; }
public StrategyContext(IStrategyContext strategyContext) // Strategy1,Strategy2,Strategy3 { this.strategyContext = strategyContext; }
public AcaoPermissaoHandler(IStrategyContext strategyContext) { StrategyContext = strategyContext; }
/// <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(); }
public BotActionSelector(ILogger <BotActionSelector> logger, IStrategyContext strategyContext, IBotContext botContext) { Logger = logger; StrategyContext = strategyContext; BotContext = botContext; }
public EmpreendimentoController(IMapper mapper, IStrategyContext strategyContext, IHandleValidation handleValidation) : base(mapper, strategyContext, handleValidation) { }