public void After(EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (operation.IsEntity(Notification.ENTITY) && operation is EntityUpdate && context.Get <bool>(CTXKEY_CREATENOTIFICATION) && result.Success) { var update = operation as EntityUpdate; var method = ReplyMethods.ByNotification;//default if (update.ContainsProperty("Method")) { method = update.Get <ReplyMethods>("Method"); } var recipientUpdate = update.GetRelationUpdate(User.ENTITY, Roles.Recipient); var attachments = update.GetMultipleRelationUpdates(NbuLibrary.Core.Domain.File.ENTITY, Roles.Attachment); if (attachments != null) { foreach (var att in attachments) { _fileService.GrantAccess(att.Id.Value, FileAccessType.Read, new User(recipientUpdate.Id.Value)); } } var recipientQuery = new EntityQuery2(User.ENTITY, recipientUpdate.Id.Value); recipientQuery.AddProperty("Email"); var recipient = _repository.Read(recipientQuery); var to = recipient.GetData <string>("Email"); var body = update.Get <string>("Body"); var subject = update.Get <string>("Subject"); } }
public void After(Services.tmp.EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) && operation is EntityDelete && result.Success) { var file = context.Get <NbuLibrary.Core.Domain.File>(CTXKEY_FILEDELETION); if (file != null) { _fileService.DeleteFileContent(Guid.Parse(file.ContentPath)); } } }
public void After(EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (!result.Success) return; if (!operation.IsEntity(User.ENTITY)) return; var update = operation as EntityUpdate; if (update == null) return; if (context.Get<bool>(CTXKEY_USER_PASSWORDRECOVERY)) { var user = new User(_repository.Read(new EntityQuery2(update.Entity, update.Id.Value) { AllProperties = true })); var template = _templateService.Get(new Guid(NotificationTemplates.USER_PASSWORDRECOVERY)); string subject = null, body = null; Dictionary<string, Entity> templateContext = new Dictionary<string, Entity>(StringComparer.InvariantCultureIgnoreCase); templateContext.Add("User", user); _templateService.Render(template, templateContext, out subject, out body); //TODO: async execution _notificationService.SendEmail(user.Email, subject, body, null); } if (context.Get<bool>(CTXKEY_USER_CREATION)) { var user = new User(_repository.Read(new EntityQuery2(update.Entity, update.Id.Value) { AllProperties = true })); var pwd = context.Get<string>(CTXKEY_PASSWORD_UPDATE); user.SetData<String>("Password", pwd); var template = _templateService.Get(new Guid(NotificationTemplates.USER_CREATED)); string subject = null, body = null; Dictionary<string, Entity> templateContext = new Dictionary<string, Entity>(StringComparer.InvariantCultureIgnoreCase); templateContext.Add("User", user); _templateService.Render(template, templateContext, out subject, out body); //TODO: async execution _notificationService.SendEmail(user.Email, subject, body, null); if (update.ContainsProperty("IsActive") && update.Get<bool>("IsActive")) SendUserActivationEmail(user); } else if (update.ContainsProperty("IsActive") && update.Get<bool>("IsActive")) { var user = new User(_repository.Read(new EntityQuery2(update.Entity, update.Id.Value) { AllProperties = true })); SendUserActivationEmail(user); } else if (context.Get<int>(CTXKEY_UPDATE_PROFILE) > 0) { if (update.ContainsRelation("UserGroup", "UserGroup") || update.ContainsProperty("FacultyNumber") || update.ContainsProperty("CardNumber")) { var user = new User(context.Get<int>(CTXKEY_UPDATE_PROFILE)); user.IsActive = false; _repository.Update(user); _securityService.Logout(); result.Data.Add("account_warning_logged_out", true); } if (update.ContainsProperty("Email")) { _securityService.UpdateCurrentUserEmail(update.Get<string>("Email")); result.Data.Add("account_event_email_changed", update.Get<string>("Email")); } } }
public void After(EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (!result.Success) { return; } if (!operation.IsEntity(User.ENTITY)) { return; } var update = operation as EntityUpdate; if (update == null) { return; } if (context.Get <bool>(CTXKEY_USER_PASSWORDRECOVERY)) { var user = new User(_repository.Read(new EntityQuery2(update.Entity, update.Id.Value) { AllProperties = true })); var template = _templateService.Get(new Guid(NotificationTemplates.USER_PASSWORDRECOVERY)); string subject = null, body = null; Dictionary <string, Entity> templateContext = new Dictionary <string, Entity>(StringComparer.InvariantCultureIgnoreCase); templateContext.Add("User", user); _templateService.Render(template, templateContext, out subject, out body); //TODO: async execution _notificationService.SendEmail(user.Email, subject, body, null); } if (context.Get <bool>(CTXKEY_USER_CREATION)) { var user = new User(_repository.Read(new EntityQuery2(update.Entity, update.Id.Value) { AllProperties = true })); var pwd = context.Get <string>(CTXKEY_PASSWORD_UPDATE); user.SetData <String>("Password", pwd); var template = _templateService.Get(new Guid(NotificationTemplates.USER_CREATED)); string subject = null, body = null; Dictionary <string, Entity> templateContext = new Dictionary <string, Entity>(StringComparer.InvariantCultureIgnoreCase); templateContext.Add("User", user); _templateService.Render(template, templateContext, out subject, out body); //TODO: async execution _notificationService.SendEmail(user.Email, subject, body, null); if (update.ContainsProperty("IsActive") && update.Get <bool>("IsActive")) { SendUserActivationEmail(user); } } else if (update.ContainsProperty("IsActive") && update.Get <bool>("IsActive")) { var user = new User(_repository.Read(new EntityQuery2(update.Entity, update.Id.Value) { AllProperties = true })); SendUserActivationEmail(user); } else if (context.Get <int>(CTXKEY_UPDATE_PROFILE) > 0) { if (update.ContainsRelation("UserGroup", "UserGroup") || update.ContainsProperty("FacultyNumber") || update.ContainsProperty("CardNumber")) { var user = new User(context.Get <int>(CTXKEY_UPDATE_PROFILE)); user.IsActive = false; _repository.Update(user); _securityService.Logout(); result.Data.Add("account_warning_logged_out", true); } if (update.ContainsProperty("Email")) { _securityService.UpdateCurrentUserEmail(update.Get <string>("Email")); result.Data.Add("account_event_email_changed", update.Get <string>("Email")); } } }
public void After(Services.tmp.EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (operation.IsEntity(NbuLibrary.Core.Domain.File.ENTITY) && operation is EntityDelete && result.Success) { var file = context.Get<NbuLibrary.Core.Domain.File>(CTXKEY_FILEDELETION); if (file != null) _fileService.DeleteFileContent(Guid.Parse(file.ContentPath)); } }
public void After(EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (!result.Success) return; if (operation.IsEntity(EntityConsts.Issue) && operation is EntityUpdate) { var update = operation as EntityUpdate; if (context.Get<bool>(CTXKEY_SEND_ISSUE)) { SendIssueToSubscribers(operation as EntityUpdate); } if (update.ContainsRelation(File.ENTITY, Roles.Content)) { var filesAttached = update.GetMultipleRelationUpdates(File.ENTITY, Roles.Content).Where(fu => fu.Operation == RelationOperation.Attach); if (filesAttached.Count() > 0) { var issue = update.ToEntity(); var q = new EntityQuery2(EntityConsts.Magazine); q.WhereRelated(new RelationQuery(EntityConsts.Issue, Roles.Issue, issue.Id)); q.Include(User.ENTITY, Roles.Subscriber); var mag = _repository.Read(q); var subscribers = mag.GetManyRelations(User.ENTITY, Roles.Subscriber).Select(r => new User(r.Entity)); foreach (var subscriber in subscribers) { foreach (var fileUpdate in filesAttached) { if (!_fileService.HasAccess(subscriber, fileUpdate.Id.Value)) _fileService.GrantAccess(fileUpdate.Id.Value, FileAccessType.Read, subscriber); } } } } } else if (operation is EntityUpdate) { var update = operation as EntityUpdate; if (update.IsEntity(User.ENTITY) && update.ContainsRelation(EntityConsts.Magazine, Roles.Subscriber)) { var rus = update.GetMultipleRelationUpdates(EntityConsts.Magazine, Roles.Subscriber).Where(ru => ru.Operation == RelationOperation.Attach); foreach (var ru in rus) { var q = new EntityQuery2(EntityConsts.Issue); q.WhereRelated(new RelationQuery(EntityConsts.Magazine, Roles.Issue, ru.Id.Value)); q.Include(File.ENTITY, Roles.Content); var issues = _repository.Search(q); foreach (var issue in issues) { //The user cannot give himself an access to file - only owner or administrator can. using (_securityService.BeginSystemContext()) { GiveFileAccessForIssue(issue, new User(update.ToEntity())); } } } } else if (update.IsEntity(EntityConsts.Magazine) && update.ContainsRelation(User.ENTITY, Roles.Subscriber)) { var rus = update.GetMultipleRelationUpdates(User.ENTITY, Roles.Subscriber).Where(ru => ru.Operation == RelationOperation.Attach); if (rus.Count() > 0) { var q = new EntityQuery2(EntityConsts.Issue); q.WhereRelated(new RelationQuery(EntityConsts.Magazine, Roles.Issue, update.Id.Value)); q.Include(File.ENTITY, Roles.Content); var issues = _repository.Search(q); foreach (var ru in rus) { foreach (var issue in issues) GiveFileAccessForIssue(issue, new User(ru.Id.Value)); } } } else if (update.IsEntity(EntityConsts.Magazine) && update.ContainsProperty("IsActive")) { var isActiveNew = update.Get<bool>("IsActive"); if (isActiveNew == false && context.Get<bool>(CTXKEY_ISACTIVEOLD)) { SendMagazineNotActiveToSubscribers(update); } } } }
public void After(EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (!result.Success) { return; } if (operation.IsEntity(EntityConsts.Issue) && operation is EntityUpdate) { var update = operation as EntityUpdate; if (context.Get <bool>(CTXKEY_SEND_ISSUE)) { SendIssueToSubscribers(operation as EntityUpdate); } if (update.ContainsRelation(File.ENTITY, Roles.Content)) { var filesAttached = update.GetMultipleRelationUpdates(File.ENTITY, Roles.Content).Where(fu => fu.Operation == RelationOperation.Attach); if (filesAttached.Count() > 0) { var issue = update.ToEntity(); var q = new EntityQuery2(EntityConsts.Magazine); q.WhereRelated(new RelationQuery(EntityConsts.Issue, Roles.Issue, issue.Id)); q.Include(User.ENTITY, Roles.Subscriber); var mag = _repository.Read(q); var subscribers = mag.GetManyRelations(User.ENTITY, Roles.Subscriber).Select(r => new User(r.Entity)); foreach (var subscriber in subscribers) { foreach (var fileUpdate in filesAttached) { if (!_fileService.HasAccess(subscriber, fileUpdate.Id.Value)) { _fileService.GrantAccess(fileUpdate.Id.Value, FileAccessType.Read, subscriber); } } } } } } else if (operation is EntityUpdate) { var update = operation as EntityUpdate; if (update.IsEntity(User.ENTITY) && update.ContainsRelation(EntityConsts.Magazine, Roles.Subscriber)) { var rus = update.GetMultipleRelationUpdates(EntityConsts.Magazine, Roles.Subscriber).Where(ru => ru.Operation == RelationOperation.Attach); foreach (var ru in rus) { var q = new EntityQuery2(EntityConsts.Issue); q.WhereRelated(new RelationQuery(EntityConsts.Magazine, Roles.Issue, ru.Id.Value)); q.Include(File.ENTITY, Roles.Content); var issues = _repository.Search(q); foreach (var issue in issues) { //The user cannot give himself an access to file - only owner or administrator can. using (_securityService.BeginSystemContext()) { GiveFileAccessForIssue(issue, new User(update.ToEntity())); } } } } else if (update.IsEntity(EntityConsts.Magazine) && update.ContainsRelation(User.ENTITY, Roles.Subscriber)) { var rus = update.GetMultipleRelationUpdates(User.ENTITY, Roles.Subscriber).Where(ru => ru.Operation == RelationOperation.Attach); if (rus.Count() > 0) { var q = new EntityQuery2(EntityConsts.Issue); q.WhereRelated(new RelationQuery(EntityConsts.Magazine, Roles.Issue, update.Id.Value)); q.Include(File.ENTITY, Roles.Content); var issues = _repository.Search(q); foreach (var ru in rus) { foreach (var issue in issues) { GiveFileAccessForIssue(issue, new User(ru.Id.Value)); } } } } else if (update.IsEntity(EntityConsts.Magazine) && update.ContainsProperty("IsActive")) { var isActiveNew = update.Get <bool>("IsActive"); if (isActiveNew == false && context.Get <bool>(CTXKEY_ISACTIVEOLD)) { SendMagazineNotActiveToSubscribers(update); } } } }
public void After(EntityOperation operation, EntityOperationContext context, EntityOperationResult result) { if (operation.IsEntity(Notification.ENTITY) && operation is EntityUpdate && context.Get<bool>(CTXKEY_CREATENOTIFICATION) && result.Success) { var update = operation as EntityUpdate; var method = ReplyMethods.ByNotification;//default if (update.ContainsProperty("Method")) method = update.Get<ReplyMethods>("Method"); var recipientUpdate = update.GetRelationUpdate(User.ENTITY, Roles.Recipient); var attachments = update.GetMultipleRelationUpdates(NbuLibrary.Core.Domain.File.ENTITY, Roles.Attachment); if (attachments != null) foreach (var att in attachments) { _fileService.GrantAccess(att.Id.Value, FileAccessType.Read, new User(recipientUpdate.Id.Value)); } var recipientQuery = new EntityQuery2(User.ENTITY, recipientUpdate.Id.Value); recipientQuery.AddProperty("Email"); var recipient = _repository.Read(recipientQuery); var to = recipient.GetData<string>("Email"); var body = update.Get<string>("Body"); var subject = update.Get<string>("Subject"); } }