示例#1
0
        public async Task <string> SaveMember(TeamMember teamMember)
        {
            var essTeam = EssTeam(teamMember.TeamId);

            if (essTeam == null || essTeam.statuscode == DynamicsInactiveStatus)
            {
                throw new Exception($"team {teamMember.TeamId} not found");
            }

            var essTeamUser = teamMember.Id == null
                ? CreateTeamUser()
                : EssTeamUsers
                              .Where(u => u._era_essteamid_value == Guid.Parse(teamMember.TeamId) && u.era_essteamuserid == Guid.Parse(teamMember.Id))
                              .SingleOrDefault();

            if (essTeamUser == null)
            {
                throw new Exception($"team member {teamMember.Id} not found in team {teamMember.TeamId}");
            }

            //TODO: move to automapper profile
            essTeamUser.era_firstname              = teamMember.FirstName;
            essTeamUser.era_lastname               = teamMember.LastName;
            essTeamUser.era_email                  = teamMember.Email;
            essTeamUser.era_phone                  = teamMember.Phone;
            essTeamUser.era_externalsystemuser     = teamMember.ExternalUserId;
            essTeamUser.era_externalsystemtype     = (int)ExternalSystemOptionSet.Bceid;
            essTeamUser.era_externalsystemusername = teamMember.UserName;
            essTeamUser.era_electronicaccessagreementaccepteddate = teamMember.AgreementSignDate;
            essTeamUser.era_label = string.IsNullOrEmpty(teamMember.Label) ? (int?)null : (int)Enum.Parse <TeamUserLabelOptionSet>(teamMember.Label);
            essTeamUser.era_role  = string.IsNullOrEmpty(teamMember.Role) ? (int?)null : (int)Enum.Parse <TeamUserRoleOptionSet>(teamMember.Role);
            essTeamUser.era_lastsuccessfullogin = teamMember.LastSuccessfulLogin;

            if (teamMember.IsActive)
            {
                context.ActivateObject(essTeamUser);
            }
            else
            {
                context.DeactivateObject(essTeamUser);
            }

            context.UpdateObject(essTeamUser);
            context.AddLink(essTeam, nameof(era_essteam.era_essteamuser_ESSTeamId), essTeamUser);
            await context.SaveChangesAsync();

            context.DetachAll();

            return(essTeamUser.era_essteamuserid.Value.ToString());
        }
示例#2
0
        public async Task <bool> DeleteMember(string teamId, string teamMemberId)
        {
            var member = EssTeamUsers
                         .Where(u => u._era_essteamid_value == Guid.Parse(teamId) && u.era_essteamuserid == Guid.Parse(teamMemberId))
                         .SingleOrDefault();

            if (member == null)
            {
                return(false);
            }

            context.DeactivateObject(member, (int)TeamMemberStatus.SoftDelete);

            await context.SaveChangesAsync();

            context.DetachAll();
            return(true);
        }