zhaolei
8 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
 
 
namespace Bootstrap.Admin.Controllers.Api
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/[controller]")]
    [Authorize]
    [ApiController]
    public class MessagesController : ControllerBase
    {
        /// <summary>
        /// 根据Id返回不同的消息列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public IEnumerable<Message> Get(string id)
        {
            var ret = new List<Message>();
            switch (id)
            {
                case "inbox":
                    ret = MessageHelper.Inbox(User.Identity.Name).ToList();
                    break;
                case "sendmail":
                    ret = MessageHelper.SendMail(User.Identity.Name).ToList();
                    break;
                case "mark":
                    ret = MessageHelper.Mark(User.Identity.Name).ToList();
                    break;
                case "trash":
                    ret = MessageHelper.Trash(User.Identity.Name).ToList();
                    break;
            }
            return ret;
        }
 
        /// <summary>
        /// 返回各个消息列表的文件个数
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public MessageCountModel Get()
        {
            var mcm = new MessageCountModel
            {
                InboxCount = MessageHelper.Inbox(User.Identity.Name).Count(),
                SendmailCount = MessageHelper.SendMail(User.Identity.Name).Count(),
                MarkCount = MessageHelper.Mark(User.Identity.Name).Count(),
                TrashCount = MessageHelper.Trash(User.Identity.Name).Count()
            };
            return mcm;
        }
    }
}