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 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; }