public async Task <IList <ResponsibleResponseTO> > ListAsync(ResponsibleFilterTO filterTO) { var responsibleSpecification = new BaseSpecification <ResponsibleEntity>(); responsibleSpecification.AddCriteria(filterTO.UnifiedProcessNumber, responsible => responsible.ProcessResponsible.Any(processResponsible => processResponsible.Process != null && !string.IsNullOrEmpty(processResponsible.Process.UnifiedProcessNumber) && processResponsible.Process.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty).Contains(filterTO.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty)))); responsibleSpecification.AddCriteria(filterTO.Cpf, responsible => responsible.Cpf == Convert.ToInt64(filterTO.Cpf.Replace(".", string.Empty).Replace("-", string.Empty))); responsibleSpecification.AddCriteria(filterTO.Name, responsible => responsible.Name.Trim().ToUpper().Contains(filterTO.Name.Trim().ToUpper())); responsibleSpecification.ApplyOrderByDescending(responsible => responsible.Name); responsibleSpecification.ApplyPaging(filterTO.Page.GetValueOrDefault(), filterTO.PerPage.GetValueOrDefault()); var listResponsible = await _responsibleRepository.ListAsync(responsibleSpecification); return(listResponsible.ToList().ToListResponsibleResponseTO()); }
private async Task <List <ErrorsTO> > ValidateLinkedProcessId(ProcessRequestTO processRequestTO) { var errors = new List <ErrorsTO>(); var processSpecification = new BaseSpecification <ProcessEntity>(); processSpecification.AddCriteria(process => process.Id == processRequestTO.LinkedProcessId); var processFather = (await _processRepository.ListAsync(processSpecification)).FirstOrDefault(); var cont = 0; while (processFather != null && processFather.LinkedProcessId != null) { cont++; processSpecification = new BaseSpecification <ProcessEntity>(); processSpecification.AddCriteria(process => process.Id == processRequestTO.LinkedProcessId); processFather = (await _processRepository.ListAsync(processSpecification)).FirstOrDefault(); } if (cont > 4) { errors.Add(new ErrorsTO { Field = "LinkedProcessId", Validation = Messaging.ExceededLimitOfHierarchyLinkedProcessId }); } return(errors); }
public async Task <List <MessageViewModel> > GetMessages(Guid senderId, Guid receiverId, int pageIndex) { Group group = await _groupRepository.GetByIdAsync(receiverId); BaseSpecification <Message> messageSpec; if (group != null) { messageSpec = new BaseSpecification <Message>(); messageSpec.AddCriteria(x => x.ToGroupId == receiverId); } else { messageSpec = new BaseSpecification <Message>(); messageSpec.AddCriteria(x => x.FromUserId == senderId && x.ToUserId == receiverId || x.FromUserId == receiverId && x.ToUserId == senderId); } messageSpec.ApplyPaging(pageIndex * Constants.ItemsPerPage, Constants.ItemsPerPage); messageSpec.ApplyOrderByDescending(x => x.Created); messageSpec.AddInclude(x => x.FromUser); IReadOnlyList <Message> messagesOnPage = await _messageRepository.ListAsync(messageSpec); ChatViewModel result = new ChatViewModel(); return(messagesOnPage.Select(x => ConvertTo(x, senderId, receiverId)).ToList()); }
public async Task <List <SelectListItem> > GetUsers(Guid currentUserId) { BaseSpecification <User> spec = new BaseSpecification <User>(); spec.AddCriteria(x => x.Id != currentUserId); IReadOnlyList <User> users = await _userRepository.ListAsync(spec); return(users.Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList()); }
private async Task <List <ErrorsTO> > ValidateDoubleUnifiedProcessNumber(Guid?processId, ProcessRequestTO processRequestTO) { var errors = new List <ErrorsTO>(); var processSpecification = new BaseSpecification <ProcessEntity>(); processSpecification.AddCriteria(processId, process => process.Id != processId); processSpecification.AddCriteria(process => process.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty) == processRequestTO.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty)); var listProcess = await _processRepository.ListAsync(processSpecification); if (listProcess.Any()) { errors.Add(new ErrorsTO { Field = "UnifiedProcessNumber", Validation = Messaging.DoubleUnifiedProcessNumber }); } return(errors); }
public override async Task OnDisconnectedAsync(Exception exception) { if (Guid.TryParse(Context.UserIdentifier, out Guid userId)) { BaseSpecification <GroupUser> spec = new BaseSpecification <GroupUser>(); spec.AddCriteria(x => x.UserId == userId); IReadOnlyList <GroupUser> groupUsers = await _groupUserRepository.ListAsync(spec); foreach (GroupUser groupUser in groupUsers) { await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupUser.GroupId.ToString()); } } await base.OnDisconnectedAsync(exception); }
public async Task <List <ReceiverViewModel> > GetReceivers(Guid currentUserId, int pageIndex) { BaseSpecification <Group> groupSpec = new BaseSpecification <Group>(); groupSpec.AddCriteria(x => x.GroupUsers.Any(y => y.UserId == currentUserId)); groupSpec.ApplyPaging(pageIndex * Constants.ItemsPerPage, Constants.ItemsPerPage); groupSpec.ApplyOrderBy(x => x.Name); IReadOnlyList <Group> groups = await _groupRepository.ListAsync(groupSpec); List <ReceiverViewModel> results = groups.Select(x => new ReceiverViewModel() { Id = x.Id, Name = x.Name, IconUrl = "https://ptetutorials.com/images/user-profile.png" //todo: need add to db }).ToList(); if (Constants.ItemsPerPage == results.Count) { return(results); } int groupCount = await _groupRepository.CountAsync(new BaseSpecification <Group>()); int gropupPage = (int)Math.Floor((decimal)(groupCount / Constants.ItemsPerPage)); pageIndex -= gropupPage; int skip = pageIndex > 0 ? (((gropupPage + 1) * Constants.ItemsPerPage) - groupCount) + ((pageIndex - 1) * Constants.ItemsPerPage) : 0; BaseSpecification <User> userSpec = new BaseSpecification <User>(); userSpec.AddCriteria(x => x.Id != currentUserId); userSpec.ApplyPaging(skip, Constants.ItemsPerPage - results.Count); userSpec.ApplyOrderBy(x => x.Name); IReadOnlyList <User> users = await _userRepository.ListAsync(userSpec); results.AddRange(users.Select(x => new ReceiverViewModel() { Id = x.Id, Name = x.Name, IconUrl = "https://ptetutorials.com/images/user-profile.png" //todo: need add to db }).ToList()); return(results); }
public async Task <IList <ProcessResponseTO> > ListAsync(ProcessFilterTO filterTO) { var processSpecification = new BaseSpecification <ProcessEntity>(); processSpecification.AddCriteria(filterTO.UnifiedProcessNumber, process => process.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty) == filterTO.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty)); processSpecification.AddCriteria(filterTO.DistributionDateStart, process => process.DistributionDate >= filterTO.DistributionDateStart); processSpecification.AddCriteria(filterTO.DistributionDateEnd, process => process.DistributionDate <= filterTO.DistributionDateEnd); processSpecification.AddCriteria(filterTO.JusticeSecret, process => process.JusticeSecret == filterTO.JusticeSecret); processSpecification.AddCriteria(filterTO.ClientPhysicalFolder, process => process.ClientPhysicalFolder.Trim().ToUpper().Contains(filterTO.ClientPhysicalFolder.Trim().ToUpper())); processSpecification.AddCriteria(filterTO.SituationId, process => process.SituationId == filterTO.SituationId); processSpecification.AddCriteria(filterTO.ResponsibleName, process => process.ProcessResponsible.Any(processResponsible => processResponsible.Responsible != null && !string.IsNullOrEmpty(processResponsible.Responsible.Name) && processResponsible.Responsible.Name.Trim().ToUpper().Contains(filterTO.ResponsibleName.Trim().ToUpper()))); processSpecification.ApplyOrderByDescending(responsible => responsible.UnifiedProcessNumber); processSpecification.ApplyPaging(filterTO.Page.GetValueOrDefault(), filterTO.PerPage.GetValueOrDefault()); var listProcess = await _processRepository.ListAsync(processSpecification); return(listProcess.ToList().ToListProcessResponseTO()); }
public async Task <Message> CreateMessageAsync(Guid userId, string text, Guid?ToUserId, Guid?ToGroupId) { Guard.Against.NullOrEmpty(text, nameof(text)); if (ToUserId == null && ToGroupId == null) { throw new Exception("Missed receiver."); } Message message = new Message() { Created = DateTime.UtcNow, FromUserId = userId, Text = text, ToUserId = ToUserId, ToGroupId = ToGroupId }; await _messageRepository.AddAsync(message); BaseSpecification <Message> messageSpec = new BaseSpecification <Message>(); messageSpec.AddCriteria(x => x.Id == message.Id); messageSpec.AddInclude(x => x.FromUser); return(await _messageRepository.FirstOrDefaultAsync(messageSpec)); }