public async Task <ResultList <FullUserModel> > List(FilterModel model) => await _membershipServiceApi.MembershipUserApiService.List(model.ToMembershipFilterModel());
public Task <ResultList <InvoiceCoreModel> > List(FilterModel model) => ResultList <InvoiceCoreModel> .TryAsync(async() => { var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin); var invoices = new ResultList <Invoice>(); if (isAdmin) { invoices = (await _repository.ListAsNoTrackingAsync <Invoice>(i => (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title) && (model.Status == null || i.Status == model.Status) && (model.Enabled == null || i.Enabled == model.Enabled), new PagingModel { PageNumber = 0, PageSize = 1000 } )); } else { invoices = (await _repository.ListAsNoTrackingAsync <Invoice>(i => i.UserId == generalDataService.User.Id && i.Enabled // (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title) // && (model.Status == null || i.Status == model.Status) , new PagingModel { PageNumber = 0, PageSize = 1000 } )); } try { if (!isAdmin) { var linkedUsers = (await _membershipServiceApi.MembershipLinkedUserApiService.ListByUser( new MembershipService.ApiClient.Models.BaseModel { Id = generalDataService.User.Id })).Data.Select(a => a.FirstUser.Id).ToList(); var linkedUserInvoices = (await _repository.ListAsync <Invoice>(i => linkedUsers.Contains(i.UserId) && (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title), new PagingModel { PageNumber = 0, PageSize = 1000 })).Items.ToList(); var merged = new List <Invoice>(); merged.AddRange(linkedUserInvoices); merged.AddRange(invoices.Items.ToList()); invoices.Items = merged.AsEnumerable(); } } catch (Exception e) { } if (invoices == null) { return(ResultList <InvoiceCoreModel> .Failed(Error.WithData(1000, new[] { "invoices not found " }))); } var userIds = invoices.Items.Select(i => i.UserId).ToList(); var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data; if (users == null) { return(ResultList <InvoiceCoreModel> .Failed(Error.WithData(1000, new[] { "Users not found " }))); } return(ResultList <InvoiceCoreModel> .Successful(invoices.Items.OrderBy(a => a.CreationDate).Reverse() .Skip(model.PageNumber *model.PageSize).Take(model.PageSize).Select(invoice => new InvoiceCoreModel { Id = invoice.Id, Amount = invoice.Amount, Description = invoice.Description, CreationDate = invoice.CreationDate, Status = (InvoiceStatus)invoice.Status, Title = invoice.Title, Enabled = invoice.Enabled, User = users.FirstOrDefault(u => u.Id == invoice.UserId) }), invoices.TotalCount, model.PageNumber, model.PageSize)); });
public Task <ResultList <AppointmentCoreModel> > List(FilterModel model) => ResultList <AppointmentCoreModel> .TryAsync(async() => { var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin); var appointmentes = new List <Appointment>(); if (isAdmin) { appointmentes = (await _repository.ListAsNoTrackingAsync <Appointment>(i => (model.DateTime == null || model.DateTime.Value.ToString("d") == i.Date.ToString("d")) && (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title), a => a.Invoice)) .Data ?.ToList(); } else { appointmentes = (await _repository.ListAsNoTrackingAsync <Appointment>(i => i.UserId == generalDataService.User.Id && (model.DateTime == null || model.DateTime.Value.ToString("d") == i.Date.ToString("d")) && (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title), a => a.Invoice)) .Data ?.ToList(); } if (appointmentes == null) { return(ResultList <AppointmentCoreModel> .Failed(Error.WithCode(ErrorCodes.NotFound))); } var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(appointmentes .Select(a => a.UserId) .Union(appointmentes .Select(a => a.RepresentativeId != null ? a.RepresentativeId.Value : Guid.Empty) .Where(a => a != Guid.Empty)).ToList())).Data; var appointmentModels = appointmentes.Select(appointment => new AppointmentCoreModel { Id = appointment.Id, Title = appointment.Title, Description = appointment.Description, User = users.FirstOrDefault(u => u.Id == appointment.UserId), Representative = users.FirstOrDefault(u => u.Id == appointment.RepresentativeId), CreationDate = appointment.CreationDate, Date = appointment.Date, Type = appointment.Type, Duration = appointment.Duration, Invoice = appointment.Invoice != null ? new InvoiceCoreModel { Id = appointment.Invoice.Id, Amount = appointment.Invoice.Amount, Enabled = appointment.Invoice.Enabled, CreationDate = appointment.Invoice.CreationDate, Description = appointment.Invoice.Description, Title = appointment.Invoice.Title } : null, Approved = appointment.Approved }).OrderBy(a => a.CreationDate).Reverse().ToList(); return(ResultList <AppointmentCoreModel> .Successful(appointmentModels)); });
public Task <ResultList <SurveyTaxModel> > List(FilterModel model) => ResultList <SurveyTaxModel> .TryAsync(async() => { var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin); var taxes = new ResultList <Tax>(); if (isAdmin) { taxes = await _repository.ListAsync <Tax>(i => (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title) && (model.UserId == null || model.UserId.Value == i.UserId), new PagingModel { PageNumber = 0, PageSize = 1000000 }, t => t.UserSurvey.Survey, t => t.UserSurvey.Tax.Select(tt => tt.TaxFile.ExtraTaxFile), t => t.TaxFile.ExtraTaxFile ); } else { taxes = (await _repository.ListAsync <Tax>(i => i.UserId == generalDataService.User.Id && (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title), new PagingModel { PageNumber = 0, PageSize = 1000000 }, t => t.UserSurvey.Survey, t => t.UserSurvey.Tax.Select(tt => tt.TaxFile.ExtraTaxFile), t => t.TaxFile.ExtraTaxFile )); } if (taxes == null) { return(ResultList <SurveyTaxModel> .Failed(Error.WithData(1000, new[] { "Taxes Not Found" }))); } var userIds = taxes.Items.SelectMany(i => i.UserSurvey.Tax).Select(t => t.UserId).ToList(); var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data; if (users == null) { return(ResultList <SurveyTaxModel> .Failed(Error.WithData(1000, new[] { "Users not found " }))); } taxes.Items.ToList().ForEach(tax => { if (tax.UserId == generalDataService.User.Id) { tax.IsChecked = true; } }); await _repository.CommitAsync(); var allLinkedUsers = await _membershipServiceApi.SystemLinkedUserApiService.ListAll(); users.ToList().ForEach(u => u.Role.Feature = null); var surveyTaxModels = taxes.Items.Select(t => t.UserSurvey).Distinct().Select(tt => new SurveyTaxModel { SurveyName = tt.Survey.Name, SurveyId = tt.Survey.Id, Status = (TaxStatus)tt.Tax .Where(t => t.UserSurvey != null && t.UserSurvey.Id == tt.Id).FirstOrDefault().Status, MainUser = users.FirstOrDefault(u => u.Id == tt.UserId), Taxes = tt.Tax .Where(t => t.UserSurvey != null && t.UserSurvey.Id == tt.Id).Select(tax => new TaxCoreModel { Id = tax.Id, Title = tax.Title, Description = tax.Description, User = users.FirstOrDefault(u => u.Id == tax.UserId), RelationType = allLinkedUsers.Data.FirstOrDefault(a => a.FirstUser.Id == tax.UserId && a.SecondUser.Id == users.FirstOrDefault(u => u.Id == tt.UserId).Id) != null ? allLinkedUsers.Data.FirstOrDefault(a => a.FirstUser.Id == tax.UserId && a.SecondUser.Id == users.FirstOrDefault(u => u.Id == tt.UserId).Id).RelationType : "", TaxFile = tax.TaxFile != null ? new TaxFileModel { EngagementBlobId = tax.TaxFile.EngagementBlobId, TaxFormBlobId = tax.TaxFile.TaxFormBlobId, UserSignedEngagementId = tax.TaxFile.UserSignedEngagementId, UserSignedTaxFormId = tax.TaxFile.UserSignedTaxFormId, ExtraTaxFile = tax.TaxFile.ExtraTaxFile != null && tax.TaxFile.ExtraTaxFile.Any() ? tax.TaxFile.ExtraTaxFile.Select(e => new ExtraTaxFileModel { Name = e.Name, BlobId = e.BlobId, BlobName = e.Name, SetByAdmin = e.SetByAdmin != null ? e.SetByAdmin.Value : true, Efile = e.Efile != null ? e.Efile.Value : false }).ToList() : null } : null, Amount = tax.Amount, CreationDate = tax.CreationDate, Status = (TaxStatus)tax.Status, Enabled = tax.Enabled }).ToList() }).ToList(); var results = surveyTaxModels.OrderBy(t => t.Taxes.FirstOrDefault().CreationDate).Reverse() .Skip(model.PageNumber *model.PageSize).Take(model.PageSize).ToList(); // var blobIds = results.SelectMany(a => a.Taxes.Select(t => t.TaxFile?.ExtraTaxFile)).Where(a=>a!=null).SelectMany(a=>a).Select(e=>e.BlobId).ToList(); // var blobs = await _repository.ListAsNoTrackingAsync<Blob>(b => blobIds.Contains(b.Id)); // results.ForEach(r=>r.Taxes.ForEach(t=>t.TaxFile.ExtraTaxFile.ForEach(e => // { // var blob = blobs.Data.FirstOrDefault(v => v.Id == e.BlobId); // if (blob != null) // e.BlobName = blob.Title; // }))); return(ResultList <SurveyTaxModel> .Successful( results, taxes.TotalCount, model.PageNumber, model.PageSize)); });
public Task <ResultList <MessageCoreModel> > List(FilterModel model) => ResultList <MessageCoreModel> .TryAsync(async() => { var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin); var messages = new ResultList <Message>(); if (isAdmin) { messages = (await _repository.ListAsync <Message>(i => i.FromUserId == generalDataService.User.Id || i.ToUserId == Guid.Empty || i.ToUserId == generalDataService.User.Id && (model.Status == null || i.Priority == model.Status) && (model.Enabled == null || i.Enabled == model.Enabled) && (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title), new PagingModel { PageNumber = 0, PageSize = 1000 })); } else { messages = (await _repository.ListAsync <Message>(i => i.ToUserId == generalDataService.User.Id && (model.Status == null || i.Priority == model.Status) && (model.Enabled == null || i.Enabled == model.Enabled) && (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title), new PagingModel { PageNumber = 0, PageSize = 1000 })); } if (messages == null) { return(ResultList <MessageCoreModel> .Failed(Error.WithData(1000, new[] { "Messages not found " }))); } var userIds = messages.Items.SelectMany(m => new List <Guid> { m.FromUserId, m.ToUserId }).ToList(); var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data; messages.Items.ToList().ForEach(message => { if (message.ToUserId == generalDataService.User.Id || message.ToUserId == Guid.Empty) { message.IsRead = true; } }); await _repository.CommitAsync(); return(ResultList <MessageCoreModel> .Successful(messages.Items.OrderBy(m => m.CreationDate) .Skip(model.PageSize *model.PageNumber).Take(model.PageSize).Select(message => new MessageCoreModel { Id = message.Id, Body = message.Body, Title = message.Title, Priority = (MessagePriority)message.Priority, FromUser = users.FirstOrDefault(u => u.Id == message.FromUserId), ToUser = users.FirstOrDefault(u => u.Id == message.ToUserId), Enabled = message.Enabled, CreationDate = message.CreationDate }), messages.TotalCount, model.PageNumber, model.PageSize)); });