private bool _SetUnitDocumentState(Guid id, Guid docId, Guid?mDocId, MemberUnitDocumentActions allowedActions, Model.DocumentStatus targetState, bool fromUser) { MemberUnitDocument doc = null; Model.MemberUnitDocument modelDoc = null; if (mDocId.HasValue) { modelDoc = db.MemberUnitDocuments.Include("Document.Unit", "Member").Single(f => f.Id == mDocId); doc = MemberUnitDocument.MemberUnitDocumentConversion.Compile()(modelDoc); } else { var unitDoc = db.UnitDocuments.Include("Unit").Single(f => f.Id == docId); var member = db.Members.Single(f => f.Id == id); modelDoc = new Model.MemberUnitDocument { Member = member, Document = unitDoc, Status = Model.DocumentStatus.NotStarted, }; member.UnitDocuments.Add(modelDoc); doc = db.UnitDocuments.Where(f => f.Id == docId).Select(MemberUnitDocument.UnitDocumentConversion).Single(); } FilterUnitDocActions(id, doc); if ((doc.Actions & allowedActions) == MemberUnitDocumentActions.None) { ThrowAuthError(); } modelDoc.Status = targetState; if (fromUser) { modelDoc.UnitAction = DateTime.Now; } else { modelDoc.MemberAction = DateTime.Now; } db.SaveChanges(); return(true); }
private MemberUnitDocument FilterUnitDocActions(Guid memberId, MemberUnitDocument doc) { var self = this.Permissions.IsSelf(memberId); if (!self) { doc.Actions = doc.Actions & ~MemberUnitDocumentActions.UserReview; } if (!this.Permissions.IsAdmin) { if (!this.Permissions.IsRoleForUnit("applicants", doc.Unit.Id) && !this.Permissions.IsMembershipForUnit(doc.Unit.Id)) { // If not management, remove the unit-level links doc.Actions = doc.Actions & ~(MemberUnitDocumentActions.Complete | MemberUnitDocumentActions.Reject); // If not management and not editing yourself, remove the 'submit' action. if (!self) { doc.Actions = doc.Actions & ~MemberUnitDocumentActions.Submit; } } } return(doc); }
private MemberUnitDocument FilterUnitDocActions(Guid memberId, MemberUnitDocument doc) { var self = this.Permissions.IsSelf(memberId); if (!self) doc.Actions = doc.Actions & ~MemberUnitDocumentActions.UserReview; if (!this.Permissions.IsAdmin) { if (!this.Permissions.IsRoleForUnit("applicants", doc.Unit.Id) && !this.Permissions.IsMembershipForUnit(doc.Unit.Id)) { // If not management, remove the unit-level links doc.Actions = doc.Actions & ~(MemberUnitDocumentActions.Complete | MemberUnitDocumentActions.Reject); // If not management and not editing yourself, remove the 'submit' action. if (!self) doc.Actions = doc.Actions & ~MemberUnitDocumentActions.Submit; } } return doc; }