예제 #1
0
    public override async Task <PaginateEmployeesResponse> PaginateEmployees(PaginateEmployeesRequest request, ServerCallContext context)
    {
        var options = new EmployeeOptions
        {
            PageIndex    = request.PageIndex,
            PageSize     = request.PageSize,
            DepartmentId = request.DepartmentId,
        };
        var employees = await _organizationApp.GetEmployeesAsync(options);

        var items = employees.Items.Select(x => new PaginateEmployeesResponse.Types.Employee
        {
            Id           = x.Id,
            Name         = x.Name,
            DisplayName  = x.DisplayName,
            DepartmentId = x.DepartmentId,
            JobId        = x.JobId,
        });
        var result = new PaginateEmployeesResponse
        {
            PageIndex = employees.PageIndex,
            PageSize  = employees.PageSize,
            ItemCount = employees.ItemCount,
        };

        result.Items.AddRange(items);

        return(result);
    }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            EmployeeOptions options = Configuration.GetSection("DefaultEmployee").Get <EmployeeOptions>();

            app.SeedIdentityData(userManager, roleManager, options);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapHub <ReservationHub>("/reservationHub");
            });
        }
예제 #3
0
    public async Task <PaginationResult <EmployeeSummary> > GetEmployeesAsync(EmployeeOptions options)
    {
        var itemCount = await _employeeRepository.GetEmployeesCountAsync(options.DepartmentId);

        var result = new PaginationResult <EmployeeSummary>(options, itemCount);

        if (itemCount == 0)
        {
            return(result);
        }

        var count = await _employeeRepository.GetEmployeesCountAsync(options.DepartmentId);

        var employees = await _employeeRepository.GetEmployeesAsync(options.DepartmentId, result.Offset, result.Limit);

        result.Items = employees
                       .Select(x => new EmployeeSummary
        {
            Id           = x.Id,
            Name         = x.Name,
            DisplayName  = x.DisplayName,
            DepartmentId = x.DepartmentId,
            JobId        = x.JobId,
        })
                       .ToList();

        return(result);
    }
        public static void SeedUsers(UserManager <IdentityUser> userManager, EmployeeOptions options)
        {
            if (userManager.FindByNameAsync(options.Email).Result == null)
            {
                IdentityUser identityUser = new IdentityUser
                {
                    Email    = options.Email,
                    UserName = options.Email
                };

                IdentityResult result = userManager.CreateAsync(identityUser, options.Password).Result;
                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(identityUser, RoleNames.Employee).Wait();
                }
            }
        }
 public static IApplicationBuilder SeedIdentityData(this IApplicationBuilder app, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, EmployeeOptions options)
 {
     SeedRoles(roleManager);
     SeedUsers(userManager, options);
     return(app);
 }