public HttpResponseMessage GetContributor( string calendarYear, [ModelBinder(typeof(Guids))] IEnumerable<Guid> schoolSuperiorId = null, [ModelBinder(typeof(Ints))] IEnumerable<int> schoolClassificationId = null, [ModelBinder(typeof(Ints))] IEnumerable<int> schoolId = null, [ModelBinder(typeof(Ints))] IEnumerable<int> positionId = null) { try { var result = ContributorBusiness.Get(claimData.UserId, claimData.GroupId, calendarYear, schoolSuperiorId, schoolClassificationId, schoolId, positionId); return Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception exc) { var logId = LogBusiness.Error(exc); return Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorModel(logId)); } }
/// <summary> /// Envia a notificação para os usuários baseados nos filtros e nas permissões do usuário logado /// </summary> /// <param name="userId">Id do usuário logado</param> /// <param name="groupId">Id do gruopo logado</param> /// <param name="entity"></param> /// <returns></returns> public static Guid Save(Guid userId, Guid groupId, Notification.Entity.API.Notification entity) { if (entity.Recipient == null) { throw new NotificationRecipientIsEmptyException(); } if ((entity.Recipient.SystemRecipient == null || !entity.Recipient.SystemRecipient.Any()) && (entity.Recipient.ContributorRecipient == null || !entity.Recipient.ContributorRecipient.Any()) && (entity.Recipient.TeacherRecipient == null || !entity.Recipient.TeacherRecipient.Any())) { throw new NotificationRecipientIsEmptyException(); } var groupRep = new GroupRepository(); var userRep = new UserRepository(); var userSGPRep = new UserSGPRepository(); var groupUser = groupRep.GetById(groupId); var ltUser = new List <Guid>(); if (entity.Recipient.SystemRecipient != null && entity.Recipient.SystemRecipient.Any()) { foreach (var item in entity.Recipient.SystemRecipient) { //pendente de testes if (groupUser.VisionId > 1) { //se não passar Escola, buscar todas as escolas das DRE's selecionadas, e/ou todas que o usuário logado tenha permissão (mesmo se a listagem vier nula) if (!item.AdministrativeUnit.Any()) { item.AdministrativeUnit = SchoolBusiness.GetAUByPermission(userId, groupId, item.AdministrativeUnitSuperior); } //Mesmo se a lista de unidades administrativas vier com valores, dentro do método é preciso garantir que o usuário tenha permissão nelas, por isso executo a verificação novamente dentro dele. ltUser.AddRange(userRep.GetByVisionAll(userId, groupId, item.SystemId, item.GroupId, item.AdministrativeUnitSuperior, item.AdministrativeUnit).Select(u => u.Id)); } else if ((item.AdministrativeUnit != null && item.AdministrativeUnit.Any()) || (item.AdministrativeUnitSuperior != null && item.AdministrativeUnitSuperior.Any())) { if (groupUser.VisionId == 1) { if ((item.AdministrativeUnit != null && item.AdministrativeUnit.Any()) || (item.AdministrativeUnitSuperior != null && item.AdministrativeUnitSuperior.Any())) { ltUser.AddRange(userSGPRep.GetByVisionAdministrator(userId, item.SystemId.First(), item.GroupId, item.AdministrativeUnitSuperior, item.AdministrativeUnit).Select(u => u.Id)); } } //else if(item.AdministrativeUnitSuperior != null && item.AdministrativeUnitSuperior.Any()) // ltUser.AddRange(userRep.GetByVisionAdministrator(userId, item.SystemId.First(), item.GroupId, item.AdministrativeUnitSuperior).Select(u => u.Id)); } else if (item.GroupId != null && item.GroupId.Any()) { if (groupUser.VisionId == 1) { ltUser.AddRange(userRep.GetByVisionAdministrator(userId, item.SystemId.First(), item.GroupId).Select(u => u.Id)); } } else { if (groupUser.VisionId == 1) { ltUser.AddRange(userRep.GetByVisionAdministrator(userId, item.SystemId).Select(u => u.Id)); } } } } if (entity.Recipient.ContributorRecipient != null && entity.Recipient.ContributorRecipient.Any()) { foreach (var item in entity.Recipient.ContributorRecipient) { ltUser.AddRange(ContributorBusiness.Get(userId, groupId, item.Calendar.Name, item.SchoolSuperior, item.SchoolClassification, item.School, item.Position).Select(u => u.Id)); } } if (entity.Recipient.TeacherRecipient != null && entity.Recipient.TeacherRecipient.Any()) { foreach (var item in entity.Recipient.TeacherRecipient) { ltUser.AddRange(TeacherBusiness.Get(userId, groupId, item.Calendar.Name, item.SchoolSuperior, item.SchoolClassification, item.School, item.Position, item.Course, item.CoursePeriod, item.Discipline, item.Team).Select(u => u.Id)); } } if (ltUser != null && ltUser.Any()) { ltUser = ltUser.Distinct().ToList(); return(Save(entity, ltUser, userId)); } else { throw new NotificationWithoutRecipientException(); } }