public void RemoveAccessForClass(long attachmentId, long classId) { Attachment a = GetObject(attachmentId); if (((Account)Server.HttpContext.Session["Account"]).Id != a.UploaderId) { throw new Exception("只有附件上传者才可以修改附件的访问者"); } IAttachmentClassRepository attachmentClassRepository = StructureMap.ObjectFactory.GetInstance <IAttachmentClassRepository>(); var o = attachmentClassRepository.GetFirstOrDefaultObject(x => x.AccessableAttachments_Id == attachmentId && x.AccessableClasses_Id == classId); attachmentClassRepository.Delete(o); }
public void GiveAccessToClass(long attachmentId, long classId) { Attachment a = GetObject(attachmentId); if (((Account)Server.HttpContext.Session["Account"]).Id != a.UploaderId) { throw new Exception("只有附件上传者才可以修改附件的访问者"); } IAttachmentClassRepository attachmentClassRepository = StructureMap.ObjectFactory.GetInstance <IAttachmentClassRepository>(); attachmentClassRepository.Add(new AttachmentClass() { AccessableAttachments_Id = attachmentId, AccessableClasses_Id = classId }); attachmentClassRepository.SaveChanges(); }