Exemplo n.º 1
0
        public void UpdateSkills(int participantId, List <GoSkills> skills, string token)
        {
            MpObjectAttributeConfiguration configuration;

            if (token == String.Empty)
            {
                token         = _apiUserService.GetToken();
                configuration = MpObjectAttributeConfigurationFactory.Contact();
            }
            else
            {
                configuration = MpObjectAttributeConfigurationFactory.MyContact();
            }

            var contactObs = Observable.Start(() => _contactService.GetContactByParticipantId(participantId));

            contactObs.Subscribe(con =>
            {
                var attrs = Observable.Start(() => _objectAttributeService.GetObjectAttributes(token, con.Contact_ID, configuration));

                attrs.Subscribe(attr =>
                {
                    var curSk = attr.MultiSelect
                                .FirstOrDefault(kvp => kvp.Value.AttributeTypeId == _configurationWrapper.GetConfigIntValue("AttributeTypeIdSkills")).Value.Attributes
                                .Where(attribute => attribute.Selected).ToList();

                    var skillsEndDate = SkillsToEndDate(skills, curSk).Select(sk =>
                    {
                        sk.EndDate = DateTime.Now;
                        return(sk);
                    });

                    var addSkills    = SkillsToAdd(skills, curSk).ToList();
                    var allSkills    = addSkills.Concat(skillsEndDate).ToList();
                    var allSkillsObs = allSkills.ToObservable();
                    try
                    {
                        allSkillsObs.ForEachAsync(skill =>
                        {
                            _objectAttributeService.SaveObjectMultiAttribute(token, con.Contact_ID, skill, configuration, true);
                        });
                    }
                    catch (Exception e)
                    {
                        throw new ApplicationException("Updating skills caused an error");
                    }
                });
            });
        }
Exemplo n.º 2
0
        public GroupDTO getGroupDetails(int groupId, int contactId, MpParticipant participant, string authUserToken)
        {
            int     participantId = participant.ParticipantId;
            MpGroup g             = _mpGroupRepository.getGroupDetails(groupId);

            var signupRelations = _mpGroupRepository.GetGroupSignupRelations(g.GroupType);

            var currRelationships = _contactRelationshipService.GetMyCurrentRelationships(contactId, authUserToken);

            var events = _mpGroupRepository.getAllEventsForGroup(groupId);

            MpContactRelationship[] familyToReturn = null;

            if (currRelationships != null)
            {
                familyToReturn = currRelationships.Where(
                    c => signupRelations.Select(s => s.RelationshipId).Contains(c.Relationship_Id)).ToArray();
            }

            var apiToken        = _apiUserService.GetToken();
            var configuration   = MpObjectAttributeConfigurationFactory.Group();
            var attributesTypes = _objectAttributeService.GetObjectAttributes(apiToken, groupId, configuration);

            var detail = new GroupDTO();

            {
                detail.ContactId            = g.ContactId;
                detail.CongregationId       = g.CongregationId;
                detail.KidsWelcome          = g.KidsWelcome;
                detail.GroupName            = g.Name;
                detail.GroupDescription     = g.GroupDescription;
                detail.GroupId              = g.GroupId;
                detail.GroupFullInd         = g.Full;
                detail.WaitListInd          = g.WaitList ?? false;
                detail.ChildCareAvailable   = g.ChildCareAvailable;
                detail.WaitListGroupId      = g.WaitListGroupId;
                detail.OnlineRsvpMinimumAge = g.MinimumAge;
                detail.MeetingFrequencyID   = g.MeetingFrequencyID;
                detail.AvailableOnline      = g.AvailableOnline;
                detail.MeetingTime          = g.MeetingTime;
                detail.MeetingDayId         = g.MeetingDayId;
                detail.Address              = Mapper.Map <MpAddress, AddressDTO>(g.Address);
                detail.StartDate            = g.StartDate;
                detail.Participants         = (g.Participants.Count > 0) ? g.Participants.Select(p => Mapper.Map <MpGroupParticipant, GroupParticipantDTO>(p)).ToList() : null;

                if (events != null)
                {
                    detail.Events = events.Select(Mapper.Map <MpEvent, Event>).ToList();
                }
                //the first instance of family must always be the logged in user
                var fam = new SignUpFamilyMembers
                {
                    EmailAddress    = participant.EmailAddress,
                    PreferredName   = participant.PreferredName,
                    UserInGroup     = _mpGroupRepository.checkIfUserInGroup(participantId, g.Participants),
                    ParticpantId    = participantId,
                    ChildCareNeeded = false
                };
                detail.SignUpFamilyMembers = new List <SignUpFamilyMembers> {
                    fam
                };

                if (familyToReturn != null)
                {
                    foreach (var f in familyToReturn)
                    {
                        var fm = new SignUpFamilyMembers
                        {
                            EmailAddress  = f.Email_Address,
                            PreferredName = f.Preferred_Name,
                            UserInGroup   = _mpGroupRepository.checkIfUserInGroup(f.Participant_Id, g.Participants),
                            ParticpantId  = f.Participant_Id,
                        };
                        detail.SignUpFamilyMembers.Add(fm);
                    }
                }

                detail.AttributeTypes   = attributesTypes.MultiSelect;
                detail.SingleAttributes = attributesTypes.SingleSelect;
            }

            return(detail);
        }