コード例 #1
0
        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()));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }