Пример #1
0
 public Task <ResultList <FeatureModel> > List(FilterModel model)
 => ResultList <FeatureModel> .TryAsync(async() =>
 {
     var resultList = await _repository.ListAsNoTrackingAsync <Feature>(
         f =>
         string.IsNullOrEmpty(model.Keyword) || f.Name.ToLower().Contains(model.Keyword.ToLower()),
         new PagingModel {
         PageNumber = 0, PageSize = 200
     }, r =>
         r.FeaturePermission.Select(fp => fp.Permission));
     if (!resultList.Success || resultList.Items == null)
     {
         return(ResultList <FeatureModel> .Failed(Error.WithCode(ErrorCodes.NotFound)));
     }
     var features = resultList.Items;
     return(ResultList <FeatureModel> .Successful(features.OrderBy(f => f.Name).Take(model.PageSize)
                                                  .Skip(model.PageSize *model.PageNumber).Select(feature => new FeatureModel
     {
         Id = feature.Id,
         Name = feature.Name,
         Permissions = feature.FeaturePermission?.Select(rf => new PermissionModel
         {
             Id = (PermissionType)rf.Permission.Id,
             Name = rf.Permission.Name,
         }).ToList()
     }), resultList.TotalCount, model.PageNumber, model.PageSize));
 });
Пример #2
0
 public Task <ResultList <PermissionModel> > List(PagingModel model)
 => ResultList <PermissionModel> .TryAsync(async() =>
 {
     var resultList = await _repository.ListAsNoTrackingAsync <Permission>(model);
     if (!resultList.Success || resultList.Items == null)
     {
         return(ResultList <PermissionModel> .Failed(Error.WithCode(ErrorCodes.NotFound)));
     }
     var permissions = resultList.Items;
     return(ResultList <PermissionModel> .Successful(permissions.Select(p => new PermissionModel
     {
         Id = (PermissionType)p.Id,
         Name = p.Name,
     }), resultList.TotalCount, resultList.PageNumber, resultList.PageSize));
 });
Пример #3
0
        public async Task <ResultList <AppointmentExceptionModel> > List(FilterModel model)
        {
            var result =
                await _repository.ListAsNoTrackingAsync <AppointmentException>(new PagingModel
                                                                               { PageSize = 1000, PageNumber = 0 });

            if (!result.Success || result.Items == null)
            {
                return(ResultList <AppointmentExceptionModel> .Failed(Error.WithData(1000,
                                                                                     new[] { "AppointmentException Not Found" })));
            }

            return(ResultList <AppointmentExceptionModel> .Successful(result.Items.Take(model.PageSize)
                                                                      .Skip(model.PageSize *model.PageNumber).Select(a => new AppointmentExceptionModel
            {
                Id = a.Id,
                FromDate = a.FromDate,
                ToDate = a.ToDate
            }).ToList(), result.TotalCount, model.PageNumber, model.PageSize));
        }
        public Task <ResultList <FullUserModel> > List(FilterModel model)
        => ResultList <FullUserModel> .TryAsync(async() =>
        {
            var admin = false;
            if (model.RoleId != null)
            {
                if (model.RoleId.Value == new Guid("6c98c773-5cf8-4993-b78b-32af01858111"))
                {
                    admin = false;
                }
                else
                {
                    admin = true;
                }
            }
            ResultList <User> resultList = new ResultList <User>();

            if (model.RoleId != null)
            {
                resultList = await _repository.ListAsNoTrackingAsync <User>(
                    u => (string.IsNullOrEmpty(model.Keyword) || u.Username.ToLower().Contains(model.Keyword)) &&
                    (model.RoleId == null || admin ? u.RoleId != new Guid("6c98c773-5cf8-4993-b78b-32af01858111") : u.RoleId == model.RoleId),
                    new PagingModel {
                    PageNumber = 0, PageSize = 3000
                },
                    u =>
                    u.Role);
            }
            else
            {
                resultList = await _repository.ListAsNoTrackingAsync <User>(
                    u => (string.IsNullOrEmpty(model.Keyword) || u.Username.ToLower().Contains(model.Keyword)),
                    new PagingModel {
                    PageNumber = 0, PageSize = 3000
                },
                    u =>
                    u.Role);
            }

            if (!resultList.Success || resultList.Items == null)
            {
                return(ResultList <FullUserModel> .Failed(Error.WithCode(ErrorCodes.NotFound)));
            }

            return(ResultList <FullUserModel> .Successful(resultList.Items.OrderBy(a => a.CreationDate).Reverse()
                                                          .Skip(model.PageSize *model.PageNumber).Take(model.PageSize).Select(user => new FullUserModel
            {
                Id = user.Id,
                Firstname = user.Firstname,
                Lastname = user.Lastname,
                Username = user.Username,
                Gender = user.Gender,
                Email = user.Email,
                Mobile = user.Mobile,
                AvatarId = user.AvatarId,
                Address = user.Address,
                Province = user.Province,
                City = user.City,
                PoBox = user.PoBox,
                Enabled = user.Enabled,
                PostalCode = user.PostalCode,
                UnitNumber = user.UnitNumber,
                MaritalStatus = user.MaritalStatus,
                DateOfBirth = user.DateOfBirth,
                SinNumber = user.SinNumber,
                Receipts = user.Receipt.Select(r => new BlobMembershipModel {
                    Id = r.BlobId
                }).ToList(),
                Role = new RoleModel
                {
                    Id = user.Role.Id,
                    Name = user.Role.Name,
                    Feature = user.Role.RoleFeature.Select(rf => new FeatureModel
                    {
                        Id = rf.Feature.Id,
                        Permissions = rf.Feature.FeaturePermission.Select(fp => new PermissionModel
                        {
                            Id = (PermissionType)fp.Permission.Id, Name = fp.Permission.Name
                        }).ToList()
                    }).ToList()
                }
            }), resultList.TotalCount, model.PageNumber, model.PageSize));
        });
        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));
        });
Пример #6
0
        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 <TicketCoreModel> > List(FilterModel model)
        => ResultList <TicketCoreModel> .TryAsync(async() =>
        {
            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);
            var tickets = new List <Ticket>();
            if (isAdmin)
            {
                var list = await _repository.ListAsNoTrackingAsync <Ticket>(i =>
                                                                            (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title) &&
                                                                            (model.UserId == null || i.UserId == model.UserId.Value) &&
                                                                            (model.CreationDate == null ||
                                                                             model.CreationDate.Value.ToString("d") == i.CreationDate.ToString("d")),
                                                                            new PagingModel {
                    PageSize = 1000, PageNumber = 0
                }, t => t.Comment);
                tickets = list.Items.ToList();
            }

            else
            {
                var list = await _repository.ListAsNoTrackingAsync <Ticket>(i =>
                                                                            i.UserId == generalDataService.User.Id &&
                                                                            (string.IsNullOrEmpty(model.Keyword) || model.Keyword == i.Title),
                                                                            new PagingModel {
                    PageSize = 1000, PageNumber = 0
                }, t => t.Comment);
                tickets = list.Items.ToList();
                tickets = tickets.Where(t => t.Title != "Survey").ToList();
            }

            if (tickets == null)
            {
                return(ResultList <TicketCoreModel> .Failed(Error.WithData(1000, new[] { "Tickets Not Found" })));
            }

            var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(tickets
                                                                                    .Select(a => a.UserId)
                                                                                    .Union(tickets
                                                                                           .Select(a => a.RepresentativeId != null ? a.RepresentativeId.Value : Guid.Empty)
                                                                                           .Where(a => a != Guid.Empty)).Union(tickets?.SelectMany(t => t.Comment)?.Select(t => t.UserId))
                                                                                    .ToList())).Data;

            var ticketModels = tickets.OrderBy(t => t.CreationDate).Reverse().Take(model.PageSize)
                               .Skip(model.PageSize *model.PageNumber).Select(ticket => new TicketCoreModel
            {
                Id             = ticket.Id,
                Title          = ticket.Title,
                Text           = ticket.Text,
                User           = users.FirstOrDefault(u => u.Id == ticket.UserId),
                Representative = users.FirstOrDefault(u => u.Id == ticket.RepresentativeId),
                BlobId         = ticket.BlobId,
                Active         = ticket.Active,
                CreationDate   = ticket.CreationDate,
                Priority       = (TicketPriority)ticket.Priority,
                Comment        = ticket.Comment?.Select(c => new CommentCoreModel
                {
                    Id           = c.Id,
                    BlobId       = c.BlobId,
                    CreationDate = c.CreationDate,
                    Text         = c.Text,
                    User         = users.FirstOrDefault(u => u.Id == c.UserId)
                }).ToList(),
            });
            return(ResultList <TicketCoreModel> .Successful(ticketModels));
        });
        public Task <ResultList <LinkedUserModel> > List(FilterModel model)
        => ResultList <LinkedUserModel> .TryAsync(async() =>
        {
            ResultList <LinkedUser> resultList = null;

            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);

            if (isAdmin)
            {
                resultList = await _repository.ListAsNoTrackingAsync <LinkedUser>(
                    l => model.Status == null || l.LinkStatus == model.Status, model, u =>
                    u.FirstUser.Role, u => u.SecondUser.Role);
            }
            else
            {
                resultList = await _repository.ListAsNoTrackingAsync <LinkedUser>(
                    l => (l.FirstUserId == model.Id ||
                          l.SecondUserId == model.Id) && model.Status == null ||
                    l.LinkStatus == model.Status, model, u =>
                    u.FirstUser.Role, u => u.SecondUser.Role);
            }

            if (!resultList.Success || resultList.Items == null)
            {
                return(ResultList <LinkedUserModel> .Failed(Error.WithCode(ErrorCodes.NotFound)));
            }

            return(ResultList <LinkedUserModel> .Successful(resultList.Items.Select(linkedUser =>
                                                                                    new LinkedUserModel
            {
                Id = linkedUser.Id,
                Status = (LinkStatus)linkedUser.LinkStatus,
                RelationType = linkedUser.RelationType,
                FirstUser = new LightUserModel
                {
                    Id = linkedUser.FirstUser.Id,
                    Firstname = linkedUser.FirstUser.Firstname,
                    Lastname = linkedUser.FirstUser.Lastname,
                    Username = linkedUser.FirstUser.Username,
                    Gender = linkedUser.FirstUser.Gender,
                    Role = new RoleModel
                    {
                        Id = linkedUser.FirstUser.Role.Id,
                        Name = linkedUser.FirstUser.Role.Name,
                        Feature = new List <FeatureModel>()
                    }
                },
                SecondUser = new LightUserModel
                {
                    Id = linkedUser.SecondUser.Id,
                    Firstname = linkedUser.SecondUser.Firstname,
                    Lastname = linkedUser.SecondUser.Lastname,
                    Username = linkedUser.SecondUser.Username,
                    Gender = linkedUser.SecondUser.Gender,
                    Role = new RoleModel
                    {
                        Id = linkedUser.SecondUser.Role.Id,
                        Name = linkedUser.SecondUser.Role.Name,
                        Feature = new List <FeatureModel>()
                    }
                },
            }
                                                                                    ), resultList.TotalCount, resultList.PageNumber, resultList.PageSize));
        });
        public Task <ResultList <UserSurveyModel> > List(FilterModel model)
        => ResultList <UserSurveyModel> .TryAsync(async() =>
        {
            var isAdmin     = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);
            var userSurveys = new List <UserSurvey>();

            if (isAdmin)
            {
                userSurveys = (await _repository.ListAsNoTrackingAsync <UserSurvey>(
                                   us => model.Id == null || us.UserId == model.Id.Value && us.Invoice.IsPaid,
                                   us => us.UserAnswer.Select(ua =>
                                                              ua.Answer.Question.Survey.Question.Select(q => q.Answer.Select(a => a.UserAnswer))),
                                   us => us.UserAnswer.Select(ua =>
                                                              ua.Answer.Question.Survey.Question.Select(q => q.Answer.Select(a => a.MustAnswered))),
                                   us => us.Survey,
                                   us => us.UserAnswer.Select(ua => ua.Answer.Question.MustAnswered))).Data.ToList();
            }
            else
            {
                userSurveys = (await _repository.ListAsNoTrackingAsync <UserSurvey>(
                                   us => us.UserId == generalDataService.User.Id && us.Survey.Enabled.Value,
                                   us => us.UserAnswer.Select(ua =>
                                                              ua.Answer.Question.Survey.Question.Select(q => q.Answer.Select(a => a.UserAnswer))),
                                   us => us.UserAnswer.Select(ua =>
                                                              ua.Answer.Question.Survey.Question.Select(q => q.Answer.Select(a => a.MustAnswered))),
                                   us => us.Survey,
                                   us => us.UserAnswer.Select(ua => ua.Answer.Question.MustAnswered))).Data.ToList();
            }


            var joinedSurveyIds  = userSurveys?.Select(us => us.SurveyId);
            var notJoinedSurveys = await _repository.ListAsNoTrackingAsync <Survey>(
                s =>
                s.Enabled.Value &&
                !joinedSurveyIds.Contains(s.Id),
                s => s.Question.Select(
                    q => q.Answer.Select(a => a.Action)),
                s => s.Question.Select(q => q.MustAnswered.Select(ma => ma.Answer)));

            if (!notJoinedSurveys.Success || notJoinedSurveys.Data == null)
            {
                return(ResultList <UserSurveyModel> .Failed(Error.WithCode(ErrorCodes.NotFound)));
            }

            var userIds = userSurveys.Select(us => us.UserId).ToList();
            userIds.Add(generalDataService.User.Id);
            userIds   = userIds.Distinct().ToList();
            var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data;

            var userSurveyModels = userSurveys?.Where(us => isAdmin || !us.IsFinsihed).Select(us =>
                                                                                              new UserSurveyModel
            {
                SurveyId          = us.Survey.Id,
                SurveyName        = us.Survey?.Name,
                SurveyDescription = us.Survey?.Description,
                QuestionCount     = us.Survey.Question.Count,
                IsFinished        = us.IsFinsihed,
                IsStarted         = true,
                NextQuestion      = !SurveyIsFinished(us).Data
                            ? CalculateNextQuestion(
                    us.UserAnswer.OrderBy(ua => ua.Answer.Question.Number).LastOrDefault()?.Answer, us)
                            : null,
                User = users.FirstOrDefault(u => u.Id == us.UserId)
            }).ToList();

            if (!isAdmin && notJoinedSurveys.Success && notJoinedSurveys.Data != null)
            {
                userSurveyModels.AddRange(notJoinedSurveys.Data.Select(s =>
                {
                    var firstQuestion = s.Question.OrderBy(q => q.Number).FirstOrDefault();
                    return(new UserSurveyModel
                    {
                        SurveyId = s.Id,
                        SurveyName = s.Name,
                        SurveyDescription = s.Description,
                        IsFinished = false,
                        IsStarted = false,
                        QuestionCount = s.Question.Count,
                        NextQuestion = firstQuestion != null
                                ? new QuestionCoreModel
                        {
                            Id = firstQuestion.Id,
                            Text = firstQuestion.Text,
                            Number = firstQuestion.Number,
                            MustAnsweredNumber = firstQuestion.MustAnswered.Select(ma => ma.Answer.Number)
                                                 .ToList(),
                            Answers = firstQuestion.Answer?.OrderBy(d => d.Number).Select(a =>
                                                                                          new AnswerCoreModel
                            {
                                Id = a.Id,
                                Number = a.Number,
                                Type = (AnswerType)a.Type,
                                Text = a.Text,
                                Actions = a.Action.Select(aa => new ActionCoreModel
                                {
                                    Id = aa.Id,
                                    Type = (ActionType)aa.Type,
                                    Value = aa.Value
                                }).ToList()
                            }).ToList()
                        }
                                : null,
                        User = users.FirstOrDefault(u => u.Id == generalDataService.User.Id)
                    });
                }));
            }
            return(ResultList <UserSurveyModel> .Successful(userSurveyModels));
        });
        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));
        });
Пример #11
0
        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));
        });
        public Task <ResultList <SurveyCoreModel> > List(PagingModel model)
        => ResultList <SurveyCoreModel> .TryAsync(async() =>
        {
            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);

            ResultList <Survey> result = null;
            if (isAdmin)
            {
                result = await _repository.ListAsNoTrackingAsync <Survey>(model,
                                                                          s => s.Question.Select(
                                                                              q => q.Answer.Select(a => a.Action)),
                                                                          s => s.Question.Select(q => q.MustAnswered.Select(ma => ma.Answer)));
            }

            else
            {
                result = await _repository.ListAsNoTrackingAsync <Survey>(s => s.Enabled != null && s.Enabled.Value,
                                                                          model,
                                                                          s => s.Question.Select(
                                                                              q => q.Answer.Select(a => a.Action)),
                                                                          s => s.Question.Select(q => q.MustAnswered.Select(ma => ma.Answer)));
            }
            if (!result.Success || result.Items == null)
            {
                return(ResultList <SurveyCoreModel> .Failed(Error.WithData(1000, new[] { "Users not found " })));
            }


            var userIds = result.Items.Select(s => s.CreatedBy).ToList();
            var users   = await _membershipServiceApi.SystemUserApiService.ListByIds(userIds);
            if (!users.Success || users.Data == null)
            {
                return(ResultList <SurveyCoreModel> .Failed(Error.WithData(1000, new[] { "Users not found " })));
            }

            var surveyModels = result.Items.Select(survey => new SurveyCoreModel
            {
                Id          = survey.Id,
                Name        = survey.Name,
                Description = survey.Description,
                Enabled     = survey.Enabled ?? true,
                CreatedBy   = isAdmin ? users.Data.FirstOrDefault(u => u.Id == survey.CreatedBy) : null,
                Questions   = survey.Question?.OrderBy(o => o.Number).Select(q => new QuestionCoreModel
                {
                    Id                 = q.Id,
                    Text               = q.Text,
                    Number             = q.Number,
                    MustAnsweredNumber = q.MustAnswered.Select(ma => ma.Answer.Number).ToList(),
                    Answers            = q.Answer?.OrderBy(d => d.Number).Select(a => new AnswerCoreModel
                    {
                        Id      = a.Id,
                        Number  = a.Number,
                        Type    = (AnswerType)a.Type,
                        Text    = a.Text,
                        Actions = a.Action.Select(aa => new ActionCoreModel
                        {
                            Id    = aa.Id,
                            Type  = (ActionType)aa.Type,
                            Value = aa.Value
                        }).ToList()
                    }).ToList()
                }).ToList()
            });
            return(ResultList <SurveyCoreModel> .Successful(surveyModels, result.TotalCount, result.PageNumber,
                                                            result.PageSize));
        });