public IHttpActionResult DeleteAssignments(Guid userId, EmailNotificationType flag) { if (userId == Guid.Empty) { return(BadRequest("user id is empty")); } var recipient = UnitOfWork.EmailRecipientsRepository .AllAsNoTracking .SingleOrDefault(x => x.OrgUserId == userId); if (recipient == null) { return(NotFound()); } var entry = UnitOfWork.EmailRecipientsRepository.AssignEmailNotification(userId, flag, enabled: false); if (entry != null) { var result = Mapper.Map <EmailRecipientDTO>(entry); MemoryCacher.DeleteStartingWith(CACHE_KEY); return(Ok(result)); } return(Ok(new EmailRecipientDTO())); }
private EmailRecipient FlagEmailNotification(EmailRecipient recipient, EmailNotificationType accessLevel, bool enabled) { switch (accessLevel) { case EmailNotificationType.Feedbacks: { recipient.Feedbacks = enabled; break; } case EmailNotificationType.NewMobileUsers: { recipient.NewMobileUsers = enabled; break; } case EmailNotificationType.OrgRequests: { recipient.OrgRequests = enabled; break; } case EmailNotificationType.OrgConnectionRequests: { recipient.OrgConnectionRequests = enabled; break; } default: break; } return(recipient); }
public IHttpActionResult AddAssignments(Guid userId, EmailNotificationType flag) { if (userId == Guid.Empty) { return(BadRequest("user id is empty")); } var orgUser = UnitOfWork.OrgUsersRepository.Find(userId); if (orgUser == null) { return(NotFound()); } var recipient = UnitOfWork.EmailRecipientsRepository.AssignEmailNotification(userId, flag, enabled: true); var result = Mapper.Map <EmailRecipientDTO>(recipient); // invalidate cache MemoryCacher.DeleteStartingWith(CACHE_KEY); return(Ok(result)); }
public EmailRecipient AssignEmailNotification(Guid userId, EmailNotificationType flags, bool enabled) { var recipient = this.AllAsNoTracking.SingleOrDefault(x => x.OrgUserId == userId); if (recipient != null) { recipient = FlagEmailNotification(recipient, flags, enabled); this.InsertOrUpdate(recipient); } else { recipient = new EmailRecipient() { OrgUserId = userId }; recipient = FlagEmailNotification(recipient, flags, enabled); this.InsertOrUpdate(recipient); } this.CurrentUOW.Save(); return(this.AllAsNoTracking.SingleOrDefault(x => x.OrgUserId == userId)); }