public ActionResult JoinOrg( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInJoinOrg cjo = JsonConvert.DeserializeObject<CheckInJoinOrg>( dataIn.data ); OrganizationMember om = DbUtil.Db.OrganizationMembers.SingleOrDefault( m => m.PeopleId == cjo.peopleID && m.OrganizationId == cjo.orgID ); if( om == null && cjo.join ) om = OrganizationMember.InsertOrgMembers( DbUtil.Db, cjo.orgID, cjo.peopleID, MemberTypeCode.Member, DateTime.Today ); if( om != null && !cjo.join ) { om.Drop( DbUtil.Db, DateTime.Now ); DbUtil.LogActivity( $"Dropped {om.PeopleId} for {om.Organization.OrganizationId} via {dataIn.getSourceOS()} app", peopleid: om.PeopleId, orgid: om.OrganizationId ); } DbUtil.Db.SubmitChanges(); // Check Entry Point and replace if Check-In Person person = DbUtil.Db.People.FirstOrDefault( p => p.PeopleId == cjo.peopleID ); if( person?.EntryPoint != null && person.EntryPoint.Code == "CHECKIN" && om != null ) { person.EntryPoint = om.Organization.EntryPoint; DbUtil.Db.SubmitChanges(); } CheckInMessage br = new CheckInMessage(); br.setNoError(); br.count = 1; return br; }
public ActionResult JoinOrg(string data) { if (!Auth()) { return(BaseMessage.createErrorReturn("Authentication failed, please try again", BaseMessage.API_ERROR_INVALID_CREDENTIALS)); } BaseMessage dataIn = BaseMessage.createFromString(data); CheckInJoinOrg cjo = JsonConvert.DeserializeObject <CheckInJoinOrg>(dataIn.data); var om = DbUtil.Db.OrganizationMembers.SingleOrDefault(m => m.PeopleId == cjo.peopleID && m.OrganizationId == cjo.orgID); if (om == null && cjo.join) { om = OrganizationMember.InsertOrgMembers(DbUtil.Db, cjo.orgID, cjo.peopleID, MemberTypeCode.Member, DateTime.Now, null, false); } if (om != null && !cjo.join) { om.Drop(DbUtil.Db, DateTime.Today); DbUtil.LogActivity($"Dropped {om.PeopleId} for {om.Organization.OrganizationId} via {dataIn.getSourceOS()} app", peopleid: om.PeopleId, orgid: om.OrganizationId); } DbUtil.Db.SubmitChanges(); BaseMessage br = new BaseMessage(); br.setNoError(); br.count = 1; return(br); }