Beispiel #1
0
 /// <summary>
 /// Initialize App Core Structure
 /// </summary>
 /// <param name="mvvmConfig">Mvvm configurations</param>
 public static async Task Init(MvvmConfig mvvmConfig = null)
 {
     IocService.Init();
     RegisterServices(mvvmConfig);
     if (mvvmConfig?.Mappings != null)
     {
         await RunApp(mvvmConfig);
     }
 }
Beispiel #2
0
        public IActionResult UpdateUser([FromBody] UserRequest userRequest)
        {
            IContainer           container = IocService.BeginRequest();
            ServiceResult <Guid> result    = container.GetInstance <IUserService>().UpdateUser(userRequest);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #3
0
        public IActionResult GetPeriods(Guid employeeId, Guid schoolId, DateTime startDateTime, DateTime endDateTime)
        {
            IContainer container = IocService.BeginRequest();
            ServiceResult <List <PeriodDto> > result = container.GetInstance <IPeriodService>().GetPeriods(employeeId, schoolId, startDateTime, endDateTime);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #4
0
        public IActionResult RemoveHomework(Guid homeworkId)
        {
            IContainer container = IocService.BeginRequest();
            ServiceResult <HomeworkDto> result = container.GetInstance <IHomeworkService>().RemoveHomework(homeworkId);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #5
0
        public IActionResult UpdateHomework([FromBody] HomeworkRequest homeworkRequest)
        {
            IContainer container = IocService.BeginRequest();
            ServiceResult <HomeworkDto> result = container.GetInstance <IHomeworkService>().UpdateHomework(homeworkRequest);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #6
0
        public IActionResult GetUserSession(string username)
        {
            IContainer container = IocService.BeginRequest();
            ServiceResult <UserSessionDto> result = container.GetInstance <IUserService>().GetUserSession(username);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #7
0
        public IActionResult GetAlexaUsersForDevice(string deviceId)
        {
            IContainer container = IocService.BeginRequest();
            ServiceResult <List <AlexaUserDto> > result = container.GetInstance <IUserService>().GetAlexaUsersForDevice(deviceId);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #8
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddDbContext <CustomerHubDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            var config = new AutoMapper.MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new DtoToDomainProfile());
                cfg.AddProfile(new DomainToDtoProfile());
            });
            var mapper = config.CreateMapper();

            services.AddSingleton(mapper);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = "CustomerHub",
                    ValidAudience    = "CustomerHub",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecurityKey"]))
                };

                options.Events = new JwtBearerEvents
                {
                    OnAuthenticationFailed = context =>
                    {
                        Console.WriteLine($"Invalid Token: {context.Exception.Message}");
                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = context =>
                    {
                        Console.WriteLine($"Token OK: {context.SecurityToken}");
                        return(Task.CompletedTask);
                    }
                };
            });

            services.AddOData();
            IocService.Register(services);
        }
Beispiel #9
0
        public ActionResult IocTest()
        {
            ViewBag.Message = "Your IocTest page.";

            UserInfo userInfo = IocService.GetObject("UserInfo") as UserInfo;

            if (userInfo != null)
            {
                ViewBag.Message = "Your IocTest page.userInfo Is Not NULL";
            }
            else
            {
                ViewBag.Message = "Your IocTest page.userInfo Is NULL";
            }

            return(View());
        }
Beispiel #10
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <TasklistDbContext>(options =>
                                                      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddOData();
            services.AddControllers(mvcOptions =>
                                    mvcOptions.EnableEndpointRouting = false);

            services.AddMvc().AddFluentValidation();

            IocService.Register(services);
            IocDomain.Register(services);

            ConfigureMappingService(services);
            ConfigureAuthenticationService(services);
            ConfigureSwaggerService(services);
        }
Beispiel #11
0
        public IActionResult GetPastHomework(Guid schoolId, Guid employeeId, Guid subjectId, Guid studentGroupId)
        {
            IContainer container = IocService.BeginRequest();

            Expression <Func <HomeworkDto, object> >[] includes = new Expression <Func <HomeworkDto, object> >[]
            {
                include => include.Students
            };
            ServiceResult <List <HomeworkDto> > result = container.GetInstance <IHomeworkService>().GetPastHomework(schoolId, employeeId, subjectId, studentGroupId, includes);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #12
0
        public IActionResult GetHomeworkForLesson(Guid lessonId)
        {
            IContainer container = IocService.BeginRequest();

            Expression <Func <HomeworkDto, object> >[] includes = new Expression <Func <HomeworkDto, object> >[]
            {
                include => include.Resources
            };
            ServiceResult <List <HomeworkDto> > result = container.GetInstance <IHomeworkService>().GetHomeworkForLesson(lessonId, includes);

            IocService.EndRequest(container);

            if (result.ResultType == ResultType.Error)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
Beispiel #13
0
 private static void RegisterServices(MvvmConfig mvvmConfig = null)
 {
     IocService.RegisterService <IMessagingCenter, MessagingCenter>();
     IocService.RegisterService <INavigationService, NavigationService>();
 }
Beispiel #14
0
 /// <summary>
 /// Resolve an intance of your interface from DI service
 /// </summary>
 /// <typeparam name="T">interface</typeparam>
 /// <returns>implementation</returns>
 public static T ResolveViewModel <T>() where T : class, new()
 {
     return(IocService.ResolveType <T>(typeof(T)));
 }
Beispiel #15
0
 /// <summary>
 /// Resolve an intance of your interface from DI service
 /// </summary>
 /// <typeparam name="T">interface</typeparam>
 /// <returns>implementation</returns>
 public static T ResolveService <T>()
 {
     return(IocService.ResolveService <T>());
 }
Beispiel #16
0
 /// <summary>
 /// Register Your Service in DI
 /// </summary>
 /// <typeparam name="TInterface">interface</typeparam>
 /// <typeparam name="T">implementation</typeparam>
 public static void RegisterService <TInterface, T>() where T : TInterface
 {
     IocService.RegisterService <TInterface, T>();
 }
Beispiel #17
0
 private static async Task RunApp(MvvmConfig mvvmConfig)
 {
     var nav = IocService.ResolveService <INavigationService>();
     await nav.InitializeAsync(mvvmConfig.MainWindow, mvvmConfig.Mappings);
 }