コード例 #1
0
        public virtual async Task <int> AddAsync(TblUserMessages record)
        {
            _dbContext.UserMessages.Add(record);
            await _dbContext.SaveChangesAsync();

            QueryCacheManager.ExpireTag(CacheTags.UserMessages);

            _eventPublisher.EntityInserted(record);

            //Send Notification to admin
            var urlHelper  = new UrlHelper(_httpContext.Request.RequestContext);
            var messageUrl = urlHelper.Action("ReplyToUserMessage", "ManageUserMessages", new { id = record.Id, area = "Admin" },
                                              _httpContext.Request.Url.Scheme);

            if (!_workContext.IsAdmin)
            {
                //Notification to admin
                await _notificationsService.SendNotificationAsync("Admin",
                                                                  "Notification_NewUserMessage",
                                                                  new
                {
                    Name  = record.Name,
                    Email = record.Email,
                    Url   = messageUrl
                });
            }
            //--------------

            return(record.Id);
        }
コード例 #2
0
        public virtual async Task UpdateAsync(TblUserMessages record)
        {
            var oldRecord = await FindByIdAsync(record.Id);

            _dbContext.UserMessages.AddOrUpdate(record);
            await _dbContext.SaveChangesAsync();

            QueryCacheManager.ExpireTag(CacheTags.UserMessages);

            _eventPublisher.EntityUpdated(record, oldRecord);
        }
コード例 #3
0
        public virtual ReplyToUserMessageModel PrepareReplyToUserMessageModel(TblUserMessages message)
        {
            var result = message == null ? new ReplyToUserMessageModel() : message.Adapt <ReplyToUserMessageModel>();

            var userMessage = HttpUtility.HtmlEncode(result.Message);

            userMessage    = userMessage.Replace("\r\n", "\r");
            userMessage    = userMessage.Replace("\n", "\r");
            userMessage    = userMessage.Replace("\r", "<br/>\r\n");
            userMessage    = userMessage.Replace("  ", " &nbsp;");
            result.Message = userMessage;

            if (string.IsNullOrWhiteSpace(result.ResponseText))
            {
                result.ResponseText =
                    $"<div style='direction: {(result.Message.IsRtlLanguage() ? "rtl" : "ltr")}'><p><br/></p><hr/><small><blockquote>{userMessage}</blockquote></small></div>";
            }

            return(result);
        }