public void AcceptInvitaion(int memberId, AcceptGroupInvitationRequestModel model) { if (!model.GroupId.HasValue) { throw new OrgException("Invalid group Id"); } using (OrgCommEntities dbc = new OrgCommEntities(DBConfigs.OrgCommConnectionString)) { if (!dbc.Members.Any(r => (r.Id.Equals(memberId)))) { throw new OrgException("Member not found"); } if (!dbc.Groups.Any(r => (r.Id.Equals(model.GroupId.Value)))) { throw new OrgException("Group not found"); } var groupmember = dbc.GroupMembers.SingleOrDefault(r => r.GroupId.Equals(model.GroupId.Value) && r.MemberId.Equals(memberId)); if (groupmember == null) { throw new OrgException(1, "No group invitation"); } else { switch (groupmember.JoinedStatus) { case (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Active: throw new OrgException("Already in group"); case (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Block: throw new OrgException(2, "No group invitation"); case (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Requested: throw new OrgException(3, "No group invitation"); case (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Suspend: throw new OrgException(4, "No group invitation"); default: break; //(int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Invited } } try { groupmember.JoinedStatus = (int)OrgComm.Data.Models.GroupMember.JoinedStatusType.Active; groupmember.JoinedDate = DateTime.Now; dbc.SaveChanges(); } catch (System.Exception ex) { throw new OrgException("Cannot member to group", ex); } } }
public ResultModel AcceptGroupInvitation(AcceptGroupInvitationRequestModel param) { ResultModel result = new ResultModel(); try { int?memberId = IdentityHelper.GetMemberId(); if (!memberId.HasValue) { throw new OrgException("Invalid MemberId"); } GroupBL bl = new GroupBL(); bl.AcceptInvitaion(memberId.Value, param); result.Status = true; result.Message = "Joined group successfully"; } catch (OrgException oex) { result.Status = false; result.Message = oex.Message; } catch (Exception ex) { result.Status = false; result.Message = AppConfigs.InternalErrorMessage; if (AppConfigs.DebugInternalMessage) { result.InternalMessage = ex.Message; } } return(result); }