Exemplo n.º 1
0
        /// <summary>
        /// Send message.
        /// </summary>
        /// <param name="message">All fields of message should be correct to ensure ef updates the correct data.</param>
        /// <returns></returns>
        public virtual async Task <BaseResponse> Send(TMessage message)
        {
            var rsp = await Sender.Send(message);

            if (Db.Entry(message).State == EntityState.Detached)
            {
                Db.Attach(message);
            }
            message.TryTimes++;
            if (rsp.Code != 0)
            {
                message.Status = MessageStatus.Failed;
            }
            else
            {
                message.Status = MessageStatus.Succeed;
                message.SendDt = DateTime.Now;
            }
            await Db.SaveChangesAsync();

            return(rsp);
        }