示例#1
0
 public UserService(IOptions <AuthSettings> authSettings, IUserFinder UserFinder,
                    IBaseModuleService BaseService)
 {
     _authSettings = authSettings.Value;
     _userFinder   = UserFinder;
     _baseService  = BaseService;
 }
示例#2
0
        public PersonModule(IBaseModuleService baseModuleService, IPersonFinder personFinder, IUserFinder userFinder, IUserService userService) : base("person", baseModuleService, personFinder)
        {
            Post("/register", async ctx =>
            {
                var userDTO = await ctx.Request.Bind <UserDTO>();

                var person = new Person()
                {
                    Email = userDTO.Username
                };

                personFinder.Insert(person);

                var user = new User()
                {
                    Username   = userDTO.Username,
                    Password   = HashHandle.CalculateHash(userDTO.Password),
                    UserTypeId = person.Id
                };

                userFinder.Insert(user);

                userDTO = userService.Authenticate(userDTO.Username, userDTO.Password);

                await baseModuleService.RespondWithEntitiyDTO(ctx, userDTO);
            });

            Post("/{id:int}/addItem", async ctx =>
            {
                var person = this.GetById <Person>(ctx.GetRouteData().As <int>("id"), personFinder);

                var itemDTO = await ctx.Request.Bind <ItemDTO>();

                var item = baseModuleService.ConvertToEntity <ItemDTO, Item>(itemDTO);

                item.Creation = DateTime.Now;

                item.ItemState = new ItemState()
                {
                    State   = State.New,
                    Changed = DateTime.Now
                };

                person.Items.Add(item);

                personFinder.Update(person);

                await baseModuleService.RespondWithEntitiyDTO <Item, ItemDTO>(ctx, item);
            });
        }
示例#3
0
        public BaseApiModule(string Route, IBaseModuleService BaseModuleService, IBaseFinder <TEntity> BaseFinder)
            : base(Route)
        {
            Get("/", parameters =>
            {
                var entities = BaseFinder.Get();

                return(BaseModuleService.RespondWithListOfEntitiesDTO <TEntity, TDTO>(this, entities));
            });

            Get("/{ID}", parameters =>
            {
                var entity = this.GetById <TEntity>((string)parameters.ID, BaseFinder);

                return(BaseModuleService.RespondWithEntitiyDTO <TEntity, TDTO>(this, entity));
            });
        }
示例#4
0
        public UserModule(IBaseModuleService baseModuleService, IUserService userService,
                          IUserFinder userFinder) : base("user", baseModuleService, userFinder)
        {
            Post("/login", async ctx =>
            {
                var userDTO = await ctx.Request.Bind <UserDTO>();

                var user = userService.Authenticate(userDTO.Username, userDTO.Password);

                if (user == null)
                {
                    ctx.Response.StatusCode = 400;
                    await ctx.Response.AsJson(new { message = "Username or password is incorrect" });
                    return;
                }

                await baseModuleService.RespondWithEntitiyDTO(ctx, user);
            });
        }
示例#5
0
        public BaseApiModule(string route, IBaseModuleService baseModuleService, IBaseFinder <TEntity> baseFinder) : base(route)
        {
            Get("/", async ctx =>
            {
                var a        = ctx.Response;
                var entities = baseFinder.Get();

                await baseModuleService.RespondWithListOfEntitiesDTO <TEntity, TDTO>(ctx, entities);
            });

            Get("/{id:int}", async ctx =>
            {
                var entity = this.GetById <TEntity>(ctx.GetRouteData().As <int>("id"), baseFinder);

                await baseModuleService.RespondWithEntitiyDTO <TEntity, TDTO>(ctx, entity);
            });

            Post("/", async ctx =>
            {
                var entityDTO = await ctx.Request.Bind <TDTO>();
                var entity    = baseModuleService.ConvertToEntity <TDTO, TEntity>(entityDTO);

                BeforeInsertNewEntity?.Invoke(entity, entityDTO);

                baseFinder.Insert(entity);

                await baseModuleService.RespondWithEntitiyDTO <TEntity, TDTO>(ctx, entity);
            });

            Put("/{id:int}", async ctx =>
            {
                var entityDTO = await ctx.Request.Bind <TDTO>();

                var entity = this.GetById <TEntity>(ctx.GetRouteData().As <int>("id"), baseFinder);

                entity = baseModuleService.ConvertToEntity <TDTO, TEntity>(entityDTO, entity);

                baseFinder.Update(entity);

                await baseModuleService.RespondWithEntitiyDTO <TEntity, TDTO>(ctx, entity);
            });
        }
示例#6
0
 public CategoryModule(IBaseModuleService baseModuleService, ICategoryFinder categoryFinder) : base("category", baseModuleService, categoryFinder)
 {
 }
示例#7
0
 public CategoryModule(IBaseModuleService BaseModuleService, ICategoryFinder CategoryFinder) :
     base("category", BaseModuleService, CategoryFinder)
 {
 }
示例#8
0
 public ItemModule(IBaseModuleService baseModuleService, IItemFinder itemFinder) : base("item", baseModuleService, itemFinder)
 {
     this.RequiresAuthorization();
 }