public async Task <ApiResult <PagedResult <CustomersDto> > > GetCustomersPagingAsync(int pageIndex, int pageSize) { var customers = await(from c in _context.Customers join employee in _context.Employees on c.EmployeeId equals employee.Id into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join appuser in _context.AppUsers on c.AppUserId equals appuser.Id into AppUserGroup from au in AppUserGroup.DefaultIfEmpty() where c.IsDelete == false select new CustomersDto() { Id = c.Id, Name = c.Name, EmployeeName = e.Name, PhoneNumber = c.PhoneNumber, UserName = au.UserName }).GetPagedAsync(pageIndex, pageSize); if (customers == null) { return(new ApiResult <PagedResult <CustomersDto> >(HttpStatusCode.NoContent)); } return(new ApiResult <PagedResult <CustomersDto> >(HttpStatusCode.OK, customers)); }
public async Task <ApiResult <EmployeeDto> > GetEmployeeAsync(string employeeId) { var employee = await(from e in _context.Employees join appuser in _context.AppUsers on e.AppuserId equals appuser.Id into AppUserGroup from au in AppUserGroup.DefaultIfEmpty() join branch in _context.Branches on e.BranchId equals branch.Id into BranchsGroup from b in BranchsGroup.DefaultIfEmpty() join department in _context.Departments on e.DepartmentId equals department.Id into DepartmentsGroup from d in DepartmentsGroup.DefaultIfEmpty() where e.Id == employeeId select new EmployeeDto() { Id = e.Id, Address = e.Address, Description = e.Description, Dob = e.Dob, Gender = e.Gender, Name = e.Name, PhoneNumber = e.PhoneNumber, UserName = au.UserName, IsDelete = e.IsDelete, DepartmentName = d.Name, BranchName = b.Name }).SingleOrDefaultAsync(); if (employee == null) { return(new ApiResult <EmployeeDto>(HttpStatusCode.NotFound, $"Không tìm thấy nhân viên có mã: {employeeId}")); } return(new ApiResult <EmployeeDto>(HttpStatusCode.OK, employee)); }
partial void appUser(IServiceProvider services) { AppUser = new AppUserGroup ( source.AddGroup ( nameof(AppUser), HubInfo.ModCategories.Apps, Access.WithAllowed(HubInfo.Roles.ViewApp, HubInfo.Roles.ViewUser) ), new AppUserGroupFactory(services) ); }
public async Task <ApiResult <IEnumerable <CustomerDto> > > SearchCustomerAsync(string customerName) { var customers = await(from c in _context.Customers join employee in _context.Employees on c.EmployeeId equals employee.Id into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join appuser in _context.AppUsers on c.AppUserId equals appuser.Id into AppUserGroup from au in AppUserGroup.DefaultIfEmpty() join customertype in _context.CustomerTypes on c.CustomerTypeId equals customertype.Id into CustomerTypeGroup from ct in CustomerTypeGroup.DefaultIfEmpty() let customerDebt = (_context.Orders.Where(x => x.CustomerId == c.Id && x.TransactionStatusId != GlobalProperties.CancelTransactionId && x.TransactionStatusId != GlobalProperties.WaitingTransactionId) .Sum(x => (decimal?)x.TotalAmount) ?? 0) + (_context.PaymentVouchers.Where(x => x.CustomerId == c.Id) .Sum(x => (decimal?)x.Paid) ?? 0) - (_context.ReceiptVouchers.Where(x => x.CustomerId == c.Id) .Sum(x => (decimal?)x.Received) ?? 0) where c.Name.ToLower().Contains(customerName.ToLower()) && c.IsDelete == false select new CustomerDto() { Address = c.Address, Description = c.Description, Dob = c.Dob, Fax = c.Fax, Gender = c.Gender, Id = c.Id, Name = c.Name, Website = c.Website, EmployeeName = e.Name, IsDelete = c.IsDelete, UserName = au.UserName, PhoneNumber = c.PhoneNumber, CustomerTypeName = ct.Name, TotalDebt = customerDebt, Email = string.IsNullOrEmpty(c.Email)?au.Email:c.Email }).ToListAsync(); return(new ApiResult <IEnumerable <CustomerDto> >() { Code = HttpStatusCode.OK, ResultObj = customers }); }
public async Task <ApiResult <CustomerDto> > GetCustomerAsync(string customerId) { var totalAmountOrders = await _context.Orders.Where(x => x.CustomerId == customerId && x.TransactionStatusId != GlobalProperties.CancelTransactionId && x.TransactionStatusId != GlobalProperties.WaitingTransactionId).SumAsync(x => x.TotalAmount); var totalPaymentVouchers = await _context.PaymentVouchers.Where(x => x.CustomerId == customerId).SumAsync(x => x.Paid); var totalReceiptVouchers = await _context.ReceiptVouchers.Where(x => x.CustomerId == customerId).SumAsync(x => x.Received); var customer = await(from c in _context.Customers join employee in _context.Employees on c.EmployeeId equals employee.Id into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join appuser in _context.AppUsers on c.AppUserId equals appuser.Id into AppUserGroup from au in AppUserGroup.DefaultIfEmpty() join customertype in _context.CustomerTypes on c.CustomerTypeId equals customertype.Id into CustomerTypeGroup from ct in CustomerTypeGroup.DefaultIfEmpty() where c.Id == customerId && c.IsDelete == false select new CustomerDto() { Address = c.Address, Description = c.Description, Dob = c.Dob, Fax = c.Fax, Gender = c.Gender, Id = c.Id, Name = c.Name, Website = c.Website, EmployeeName = e.Name, PhoneNumber = c.PhoneNumber, IsDelete = c.IsDelete, UserName = au.UserName, CustomerTypeName = ct.Name, TotalDebt = totalAmountOrders + totalPaymentVouchers - totalReceiptVouchers }).SingleOrDefaultAsync(); if (customer == null) { return(new ApiResult <CustomerDto>(HttpStatusCode.NotFound, $"Không tìm thấy khách hàng có mã: {customerId}")); } return(new ApiResult <CustomerDto>(HttpStatusCode.OK, customer)); }
public async Task <ApiResult <ReportCustomerSupplierDebtDto> > GetAllCustomerDebtAsync(int pageIndex, int pageSize) { var customers = from c in _context.Customers join employee in _context.Employees on c.EmployeeId equals employee.Id into EmployeeGroup from e in EmployeeGroup.DefaultIfEmpty() join appuser in _context.AppUsers on c.AppUserId equals appuser.Id into AppUserGroup from au in AppUserGroup.DefaultIfEmpty() join ct in _context.CustomerTypes on c.CustomerTypeId equals ct.Id let customerDebt = (_context.Orders.Where(x => x.CustomerId == c.Id && x.TransactionStatusId != GlobalProperties.CancelTransactionId && x.TransactionStatusId != GlobalProperties.WaitingTransactionId) .Sum(x => (decimal?)x.TotalAmount) ?? 0) + (_context.PaymentVouchers.Where(x => x.CustomerId == c.Id) .Sum(x => (decimal?)x.Paid) ?? 0) - (_context.ReceiptVouchers.Where(x => x.CustomerId == c.Id) .Sum(x => (decimal?)x.Received) ?? 0) where (int)customerDebt != 0 select new CustomersSuppliersForReportDto() { Id = c.Id, Name = c.Name, PhoneNumber = c.PhoneNumber, TotalDebt = customerDebt, Address = c.Address, Email = au.Email, }; decimal totalDebt = 0; foreach (var c in await customers.ToListAsync()) { totalDebt += c.TotalDebt; } var reportCustomer = new ReportCustomerSupplierDebtDto() { Targets = await customers.GetPagedAsync(pageIndex, pageSize), TotalDebt = totalDebt }; return(new ApiResult <ReportCustomerSupplierDebtDto>(HttpStatusCode.OK, reportCustomer)); }
public static void SeedData(IdentityDBContext context) { Console.WriteLine("Applying database migrations..."); context.Database.Migrate(); Console.WriteLine("Seeding initial data..."); bool newEntry = false; Maybe <AppUser> adminUser = context.AppUser.FirstOrDefault(e => e.Username == "*****@*****.**"); if (adminUser.HasNoValue) { adminUser = new AppUser( firstName: "Dhanuka", lastName: "Jayasinghe", username: Email.Create("*****@*****.**").Value, password: Password.Create("Admin@#456").Value ); context.AppUser.Add(adminUser.Value); newEntry = true; } Maybe <AppPermission> iamAdminPermission = context.AppPermission.FirstOrDefault(e => e.Name == Permission.UserAccountAdmin.ToString()); if (iamAdminPermission.HasNoValue) { iamAdminPermission = new AppPermission( name: Permission.UserAccountAdmin.ToString(), description: EnumInfo.GetDescription(Permission.UserAccountAdmin) ); context.AppPermission.Add(iamAdminPermission.Value); newEntry = true; } Maybe <AppGroup> adminGroup = context.AppGroup.FirstOrDefault(e => e.Name == SystemUserGroup.ADMIN.ToString()); if (adminGroup.HasNoValue) { adminGroup = new AppGroup(SystemUserGroup.ADMIN.ToString(), "System administrator permissions"); context.AppGroup.Add(adminGroup.Value); newEntry = true; } if (newEntry) { context.SaveChanges(); newEntry = false; } if (!context.AppGroupPermission.Any(e => e.PermissionId == iamAdminPermission.Value.Id && e.AppGroupId == adminGroup.Value.Id)) { AppGroupPermission groupPermission = new AppGroupPermission(iamAdminPermission, adminGroup); context.AppGroupPermission.Add(groupPermission); newEntry = true; } if (!context.AppUserGroup.Any(e => e.AppUserId == adminUser.Value.Id && e.AppGroupId == adminGroup.Value.Id)) { AppUserGroup adminUserGroup = new AppUserGroup(adminUser, adminGroup); context.AppUserGroup.Add(adminUserGroup); newEntry = true; } if (newEntry) { context.SaveChanges(); } Console.WriteLine("Seeding complete"); }