public async Task <ApiResult <PagedResult <AccountsDto> > > GetAccountsPagingAsync(int pageIndex, int pageSize) { var accounts = await(from au in _context.AppUsers join emp in _context.Employees on au.Id equals emp.AppuserId into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join cus in _context.Customers on au.Id equals cus.AppUserId into CustomerGroup from c in CustomerGroup.DefaultIfEmpty() join sup in _context.Suppliers on au.Id equals sup.AppUserId into SupplierGroup from s in SupplierGroup.DefaultIfEmpty() select new AccountsDto() { Id = au.Id, UserName = au.UserName, Email = au.Email, EmployeeName = e.Name, CustomerName = c.Name, SupplierName = s.Name, PhoneNumber = au.PhoneNumber }).GetPagedAsync(pageIndex, pageSize); return(new ApiResult <PagedResult <AccountsDto> >(HttpStatusCode.OK, accounts)); }
public async Task <ApiResult <AccountDto> > GetAccountAsync(Guid userId) { var checkAccount = await _userManager.FindByIdAsync(userId.ToString(("D"))); if (checkAccount == null) { return(new ApiResult <AccountDto>(HttpStatusCode.NotFound, $"Không tìm thấy tài khoản có mã: {userId}")); } var roles = await _userManager.GetRolesAsync(checkAccount); var accountRoles = new List <AccountRolesDto>(); foreach (var r in roles) { var role = await _roleManager.FindByNameAsync(r); if (role != null) { accountRoles.Add(ObjectMapper.Mapper.Map <AppRole, AccountRolesDto>(role)); } } var accountDetail = await(from au in _context.AppUsers join emp in _context.Employees on au.Id equals emp.AppuserId into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join cus in _context.Customers on au.Id equals cus.AppUserId into CustomerGroup from c in CustomerGroup.DefaultIfEmpty() join sup in _context.Suppliers on au.Id equals sup.AppUserId into SupplierGroup from s in SupplierGroup.DefaultIfEmpty() where au.Id == userId select new AccountDto() { Id = au.Id, Address = e.Address != null ? e.Address : (c.Address != null ? c.Address : (s.Address != null ? s.Address : "")), Email = au.Email, Name = e.Name != null ? e.Name : (c.Name != null ? c.Name : (s.Name != null ? s.Name : "")), PhoneNumber = au.PhoneNumber != null ? au.PhoneNumber : (e.PhoneNumber != null ? e.PhoneNumber : (c.PhoneNumber != null ? c.PhoneNumber : ( s.PhoneNumber != null ? s.PhoneNumber : ""))), UserName = au.UserName, InRoles = accountRoles }).SingleOrDefaultAsync(); return(new ApiResult <AccountDto>(HttpStatusCode.OK, accountDetail)); }
public async Task <ApiResult <PagedResult <ReceiptVouchersDto> > > GetReceiptVoucherPagingAsync(int pageIndex, int pageSize, string accountId) { var checkEmployee = await _context.Employees.Where(x => x.AppuserId.ToString() == accountId) .SingleOrDefaultAsync(); if (checkEmployee == null) { return(new ApiResult <PagedResult <ReceiptVouchersDto> >(HttpStatusCode.NotFound, $"Lỗi tài khoản đăng nhập")); } var receiptVouchers = await(from rv in _context.ReceiptVouchers join employee in _context.Employees on rv.EmployeeId equals employee.Id into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join customer in _context.Customers on rv.CustomerId equals customer.Id into CustomerGroup from c in CustomerGroup.DefaultIfEmpty() join supplier in _context.Suppliers on rv.SupplierId equals supplier.Id into SupplierGroup from s in SupplierGroup.DefaultIfEmpty() join b in _context.Branches on rv.BranchId equals b.Id join pm in _context.PaymentMethods on rv.PaymentMethodId equals pm.Id where rv.BranchId == checkEmployee.BranchId select new ReceiptVouchersDto() { Id = rv.Id, Received = rv.Received, BranchName = b.Name, PaymentMethodName = pm.Name, ReceivedDate = rv.ReceivedDate, PersonName = string.IsNullOrEmpty(rv.CustomerId) ? $"Nhà cung cấp {s.Name}" : $"Khách hàng {c.Name}", EmployeeName = e.Name } ).GetPagedAsync(pageIndex, pageSize); return(new ApiResult <PagedResult <ReceiptVouchersDto> >(HttpStatusCode.OK, receiptVouchers)); }