Ejemplo n.º 1
0
        /// <summary>
        /// 获取客户详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <Resp> GetDetail()
        {
            using var db = new MyForContext();
            DB.Tables.Client client = await db.Clients.AsNoTracking()
                                      .Include(c => c.Avatar)
                                      .FirstOrDefaultAsync(c => c.Id == Id);

            if (client is null)
            {
                return(Resp.Fault(Resp.NONE, NOT_CLIENT));
            }

            Results.ClientDetail detail = new Results.ClientDetail
            {
                AccountName = client.AccountName,
                Description = client.Description,
                Email       = client.Email,
                Phone       = client.Phone,
                Gender      = new Share.KeyValue
                {
                    Key   = client.Gender,
                    Value = ((User.Gender)client.Gender).GetDescription()
                },
                Avatar     = client.Avatar.Path,
                Thumbnail  = client.Avatar.Thumbnail,
                CreateDate = client.CreateDate.ToStandardString()
            };
            return(Resp.Success(detail, ""));
        }
Ejemplo n.º 2
0
        public async Task <Resp> GetDetail()
        {
            using var db = new MyForContext();

            DB.Tables.Segment segment = await db.Segments.AsNoTracking()
                                        .FirstOrDefaultAsync(s => s.Id == Id);

            if (segment is null)
            {
                return(Resp.Fault(Resp.NONE, NONE_SEGMENT));
            }

            Results.SegmentDetail detail = new Results.SegmentDetail
            {
                Content    = segment.Content,
                Creator    = Clients.Client.GetName(segment.CreateById),
                CreateDate = segment.CreateDate.ToStandardString(),
                State      = new Share.KeyValue
                {
                    Key   = segment.State,
                    Value = ((SegmentState)segment.State).GetDescription()
                }
            };
            return(Resp.Success(detail, ""));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取管理员账号列表
        /// </summary>
        /// <param name="index">当前页码</param>
        /// <param name="rows">行数</param>
        /// <param name="search">搜索参数</param>
        /// <returns></returns>
        public async Task <Resp> GetAccounts(int index, int rows, string search)
        {
            search = string.IsNullOrWhiteSpace(search) ? "" : search;
            Paginator pager = new Paginator
            {
                Index = index,
                Rows  = rows
            };

            Expression <Func <DB.Tables.Account, bool> > whereSQL = a => a.AccountName.Contains(search);

            using var db = new MyForContext();

            pager.TotalRows = await db.Accounts.CountAsync(whereSQL);

            pager.List = await db.Accounts.AsNoTracking()
                         .Where(whereSQL)
                         .Skip(pager.GetSkip())
                         .Take(pager.Rows)
                         .Select(a => new Models.Account_Result
            {
                Id         = a.Id,
                Account    = a.AccountName,
                Gender     = ((User.Gender)a.Gender).GetDescription(),
                Email      = string.IsNullOrWhiteSpace(a.Email) ? "-" : a.Email,
                Phone      = string.IsNullOrWhiteSpace(a.Phone) ? "-" : a.Phone,
                CreateDate = a.CreateDate.ToStandardString()
            })
                         .ToListAsync();

            return(Resp.Success(pager));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取主题
        /// </summary>
        public async Task <Resp> GetSelfThemes(int index, int rows, string search)
        {
            Paginator pager = new Paginator
            {
                Index = index,
                Rows  = rows
            };

            Expression <Func <DB.Tables.Theme, bool> > whereSQL = t => t.Name.Contains(search) && t.MasterId == Id;

            using var db    = new MyForContext();
            pager.TotalRows = await db.Themes.CountAsync(whereSQL);

            pager.List = await db.Themes.AsNoTracking()
                         .Where(whereSQL)
                         .Skip(pager.GetSkip())
                         .Take(pager.Rows)
                         .Select(t => new Themes.Results.ThemeItem
            {
                Id     = t.Id,
                Name   = t.Name,
                Master = GetName()
            })
                         .ToListAsync();

            return(Resp.Success(pager, ""));
        }
Ejemplo n.º 5
0
        public async Task <Resp> ModifyAsync(Models.UpdateTheme updateTheme)
        {
            (bool isValid, string msg) = updateTheme.IsValid();

            if (!isValid)
            {
                return(Resp.Fault(Resp.NONE, msg));
            }

            using var db = new MyForContext();

            DB.Tables.Theme model = await db.Themes.FirstOrDefaultAsync(t => t.Id == Id);

            if (model is null)
            {
                return(Resp.Fault(Resp.NONE, NONE_THEME));
            }
            model.Description = updateTheme.Description;
            if (updateTheme.IsChangeCover)
            {
                Files.File file = new Files.File();
                model.CoverId = await file.SaveImageToDB(updateTheme.Cover);
            }
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, ""));
            }
            return(Resp.Fault(Resp.NONE, "失败"));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取默认主题
        /// </summary>
        public static Theme GetDefaultTheme()
        {
            const string KEY          = "22f7b7b7-d674-47d5-89a4-eba97eebf3bc";
            Theme        defaultTheme = Cache.Get <Theme>(KEY);

            if (defaultTheme is null)
            {
                using var db = new MyForContext();
                DB.Tables.Theme theme = db.Themes.AsNoTracking()
                                        .FirstOrDefault(t => t.Name == DEFAULT_THEME);
                //  没有默认主题就加一个
                if (theme is null)
                {
                    theme = new DB.Tables.Theme
                    {
                        Name     = DEFAULT_THEME,
                        MasterId = 1
                    };
                    db.Themes.Add(theme);
                    db.SaveChanges();
                }
                defaultTheme = new Theme(theme.Id);
                //  存缓存
                _ = Cache.Set(KEY, defaultTheme, 300);
            }

            return(defaultTheme);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 移除主题, 默认软删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="delete">是否彻底删除</param>
        /// <returns></returns>
        public async Task <Resp> Remove(int id, bool delete = false)
        {
            using var db = new MyForContext();
            DB.Tables.Theme theme = await db.Themes.FirstOrDefaultAsync(t => t.Id == id);

            if (theme is null)
            {
                return(Resp.Fault(Resp.NONE, Theme.NONE_THEME));
            }

            if (delete)
            {
                db.Themes.Remove(theme);
            }
            else
            {
                theme.State = (int)Theme.ThemeStates.Remove;
            }

            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, ""));
            }
            return(Resp.Fault(Resp.NONE, "失败"));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 发布新帖子
        /// </summary>
        public async Task <Resp> PublishNewPostAsync(Models.NewPostInfo info)
        {
            (bool isValid, string msg) = info.IsValid();
            if (!isValid)
            {
                return(Resp.Fault(Resp.NONE, msg));
            }

            Content content = new Content(info.Content, info.Files);

            using var db    = new MyForContext();
            using var trans = db.Database.BeginTransaction();

            await content.UploadImagesAndSetInContent();

            DB.Tables.Post newPost = new DB.Tables.Post
            {
                Title      = info.Title,
                ThemeId    = Themes.Theme.GetIdByThemeName(info.Theme),
                Keyword    = info.Theme,
                CreateById = info.CreateById,
                State      = (int)Post.PostState.ToAudit
            };
            newPost.Content = content.ToString();

            db.Posts.Add(newPost);
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                trans.Commit();
                return(Resp.Success(Resp.NONE));
            }
            return(Resp.Fault(Resp.NONE, "添加失败"));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 删除段子
        /// </summary>
        public async Task <Resp> Remove(int id, bool delete = false)
        {
            using var db = new MyForContext();

            DB.Tables.Segment segment = await db.Segments.FirstOrDefaultAsync(s => s.Id == id);

            if (segment is null)
            {
                return(Resp.Fault(Resp.NONE, Segment.NONE_SEGMENT));
            }

            if (delete)
            {
                db.Segments.Remove(segment);
            }
            else
            {
                segment.State = (int)Segment.SegmentState.Remove;
            }

            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, "删除成功"));
            }
            return(Resp.Fault(Resp.NONE, "删除失败"));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 注册一个客户
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public async Task <Resp> RegisterNewClient(Models.Register_Info info)
        {
            (bool isValid, string msg) = info.IsValid();
            if (!isValid)
            {
                return(Resp.Fault(Resp.NONE, msg));
            }

            using var db = new MyForContext();

            if (await db.Clients.AnyAsync(c => c.AccountName == info.Account))
            {
                return(Resp.Fault(Resp.NONE, "已被使用的账号"));
            }

            DB.Tables.Client newClient = new DB.Tables.Client
            {
                AccountName = info.Account,
                Password    = info.Password
            };
            db.Clients.Add(newClient);
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, ""));
            }
            return(Resp.Fault(Resp.NONE, ""));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据片段获取可能的主题名字
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public static async Task <List <string> > GetThemeNameBySegmentAsync(string segment, int rows)
        {
            if (string.IsNullOrWhiteSpace(segment))
            {
                return(new List <string>());
            }

            string key = $"0fe53e33-cdaf-4fbb-8e3e-874fcfde59e7-{segment}";

            List <string> list = Cache.Get <List <string> >(key);

            if (list is null)
            {
                using var db = new MyForContext();
                list         = await db.Themes.AsNoTracking()
                               .OrderByDescending(t => t.Name.Length)
                               .Where(t => t.Name.Contains(segment))
                               .Take(rows)
                               .Select(t => t.Name)
                               .ToListAsync();

                Cache.Set(key, list);
            }
            return(list);
        }
Ejemplo n.º 12
0
        public async Task <Resp> Login(Models.Login_Info info)
        {
            (bool isValid, string msg) = info.IsValid();
            if (!isValid)
            {
                return(Resp.Fault(Resp.NONE, msg));
            }

            using var db = new MyForContext();

            DB.Tables.Client client = await db.Clients
                                      .Where(c => c.AccountName == info.Account && c.Password == info.Password)
                                      .FirstOrDefaultAsync();

            if (client is null)
            {
                return(Resp.Fault(Resp.NONE, "账号不存在后密码错误"));
            }

            client.Token = Guid.NewGuid();
            int suc = await db.SaveChangesAsync();

            if (suc != 1)
            {
                return(Resp.Fault(Resp.NONE, "登录失败"));
            }

            Results.Login_Result result = new Results.Login_Result
            {
                Id      = client.Id,
                Token   = client.Token,
                Account = client.AccountName
            };
            return(Resp.Success(result));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 获取列表
        /// </summary>
        public async Task <Resp> GetListAsync(int index, int rows, string order, Segment.SegmentState state)
        {
            DateTimeOffset NOW = DateTimeOffset.Now;

            Expression <Func <DB.Tables.Segment, bool> > whereSQL;

            if (state != Segment.SegmentState.NotSelected)
            {
                whereSQL = s => s.State == (int)state;
            }
            else
            {
                whereSQL = s => true;
            }

            Paginator pager = new Paginator
            {
                Index = index,
                Rows  = rows
            };

            using var db = new MyForContext();

            var query = db.Segments.AsNoTracking();

            switch (order)
            {
            //  一周最热
            case "week":
            {
                whereSQL = whereSQL.And(s => s.CreateDate <= NOW && s.CreateDate > NOW.AddDays(-7));
                query    = query.OrderByDescending(s => s.Likes);
            }; break;

            default:
                query = query.OrderByDescending(s => s.CreateDate);
                break;
            }

            pager.TotalRows = await db.Segments.CountAsync(whereSQL);

            List <Results.SegmentItem> list = await query.Where(whereSQL)
                                              .Skip(pager.GetSkip())
                                              .Take(pager.Rows)
                                              .Select(s => new Results.SegmentItem
            {
                Id       = s.Id,
                Content  = s.Content.Length > 20 ? s.Content.Substring(0, 20) + "..." : s.Content,
                Likes    = s.Likes,
                NickName = Clients.Client.GetName(s.CreateById),
                Date     = s.CreateDate.ToStandardString()
            })
                                              .ToListAsync();

            pager.List = list;
            return(Resp.Success(pager, ""));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 获取当前帖子的详情
        /// </summary>
        /// <returns></returns>
        public async Task <Resp> GetDetail()
        {
            if (IsEmpty())
            {
                return(Resp.Fault(Resp.NONE, NONE_POST));
            }

            using var db = new MyForContext();
            DB.Tables.Post post = await db.Posts.AsNoTracking()
                                  .Include(p => p.Theme)
                                  //.Include(p => p.Comments)
                                  .FirstOrDefaultAsync(p => p.Id == Id);

            if (post is null)
            {
                return(Resp.Fault(Resp.NONE, NONE_POST));
            }

            Results.PostDetail detail = new Results.PostDetail
            {
                Title   = post.Title,
                Theme   = post.Theme.Name,
                Content = post.Content,
                Likes   = post.Likes,
                State   = new Share.KeyValue
                {
                    Key   = post.State,
                    Value = ((PostState)post.State).GetDescription()
                },
                Creator    = Clients.Client.GetName(post.CreateById),
                CreateDate = post.CreateDate.ToStandardString(),
                //Comments = post.Comments.Select(c => new Results.Comment
                //{
                //    Id = c.Id,
                //    NickName = Clients.Client.GetName(c.CreateById),
                //    Date = c.CreateDate.ToStandardString(),
                //    CommentContent = c.Comment
                //}).ToList()
            };

            List <Results.Comment> comments = await db.PostComments.AsNoTracking()
                                              .Where(c => c.PostId == Id)
                                              .Take(10)
                                              .Select(c => new Results.Comment
            {
                Id             = c.Id,
                NickName       = Clients.Client.GetName(c.CreateById),
                Date           = c.CreateDate.ToStandardString(),
                CommentContent = c.Comment
            }).ToListAsync();

            detail.Comments = comments;

            return(Resp.Success(detail, ""));
        }
Ejemplo n.º 15
0
        public static User GetUser(int id, string token)
        {
            using var db = new MyForContext();
            DB.Tables.Account user = db.Accounts.AsNoTracking().FirstOrDefault(p => p.Id == id && p.Token.ToString() == token);
            if (user is null)
            {
                return(new User(User.EMPTY));
            }

            return(new User(user.Id));
        }
Ejemplo n.º 16
0
        public static Client GetClient(int id, string token)
        {
            using var db = new MyForContext();
            DB.Tables.Client client = db.Clients.AsNoTracking()
                                      .FirstOrDefault(c => c.Id == id && (c.Token.ToString() == token || c.APPToken.ToString() == token));
            if (client is null)
            {
                return(Client.Empty);
            }

            return(new Client(client.Id));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 根据账号用户名获取客户
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public static Client GetClientByAccount(string account)
        {
            using var db = new MyForContext();
            DB.Tables.Client client = db.Clients.AsNoTracking()
                                      .FirstOrDefault(c => c.AccountName == account);
            if (client is null)
            {
                return(Client.Empty);
            }

            return(new Client(client.Id));
        }
Ejemplo n.º 18
0
        public static string GetName(int id)
        {
            string key  = $"45abce59-96b8-4785-879f-f04d2663c037_{id}";
            string name = Cache.Get <string>(key);

            if (name is null)
            {
                using var db = new MyForContext();
                DB.Tables.Post post = db.Posts.AsNoTracking()
                                      .FirstOrDefault(t => t.Id == id);
                name = post?.Title ?? "";
                _    = Cache.Set(key, name, 10);
            }

            return(name);
        }
Ejemplo n.º 19
0
        public static string GetName(int id)
        {
            string key  = $"4d60b003-eb58-477c-a62d-de0580d486fa_{id}";
            string name = Cache.Get <string>(key);

            if (name is null)
            {
                using var db = new MyForContext();
                DB.Tables.Theme theme = db.Themes.AsNoTracking()
                                        .FirstOrDefault(t => t.Id == id);
                name = theme?.Name ?? "";
                _    = Cache.Set(key, name, 10);
            }

            return(name);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 添加一个账号
        /// </summary>
        /// <param name="newAccount"></param>
        /// <returns></returns>
        public async Task <Resp> AddAccount(Models.NewAccount newAccount)
        {
            (bool isValid, string msg) = newAccount.IsValid();
            if (!isValid)
            {
                return(Resp.Fault(msg));
            }

            using var db = new MyForContext();

            if (await db.Accounts.AnyAsync(a => a.AccountName == newAccount.AccountName))
            {
                return(Resp.Fault("账号名已经存在"));
            }

            //if (await db.Accounts.AnyAsync(a => a.Email == newAccount.Email))
            int avatarId;

            if (newAccount.Avatar is null)
            {
                avatarId = User.GetDefaultAvatarId();
            }
            else
            {
                Files.File file = new Files.File();
                avatarId = await file.SaveFileToDBAsync(newAccount.Avatar);
            }

            DB.Tables.Account model = new DB.Tables.Account
            {
                AccountName = newAccount.AccountName,
                Password    = newAccount.Password,
                AvatarId    = avatarId,
                Email       = newAccount.Email,
                Phone       = newAccount.Phone,
                Gender      = newAccount.Gender,
                CreateById  = newAccount.CreatorId
            };
            db.Accounts.Add(model);
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, "添加成功"));
            }
            return(Resp.Fault(msg: "添加账号失败"));
        }
Ejemplo n.º 21
0
        public static string GetName(int id)
        {
            string key  = $"3c82d8b0-421a-4686-a003-b01e71cf9933_{id}";
            string name = Cache.Get <string>(key);

            if (name is null)
            {
                using var db = new MyForContext();
                DB.Tables.Account account = db.Accounts.AsNoTracking()
                                            .FirstOrDefault(a => a.Id == id);

                name = account?.AccountName ?? "";
                _    = Cache.Set(key, name, 10);
            }

            return(name);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 通过主题名获取主题 ID, 若没有, 则返回默认主题 ID
        /// </summary>
        /// <param name="themeName"></param>
        /// <returns></returns>
        public static int GetIdByThemeName(string themeName)
        {
            themeName = themeName.Trim();

            string key = $"6011a3cf-82a6-468a-b00b-ee76f886e926-{themeName}";
            int    id  = Cache.Get <int>(key);

            //
            if (id == default)
            {
                using var db = new MyForContext();
                DB.Tables.Theme theme = db.Themes.AsNoTracking().FirstOrDefault(t => t.Name == themeName);

                id = theme?.Id ?? GetDefaultTheme().Id;
                Cache.Set(key, id);
            }
            return(id);
        }
        /// <summary>
        /// 一周热门排序
        /// </summary>
        /// <param name="index"></param>
        /// <param name="rows"></param>
        /// <param name="search"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task <Resp> GetThemeListAsync(int index, int rows, string search, Theme.ThemeStates state)
        {
            DateTimeOffset NOW = DateTimeOffset.Now;

            using var db = new MyForContext();

            Paginator pager = new Paginator
            {
                Index = index,
                Rows  = rows
            };

            if (string.IsNullOrWhiteSpace(search))
            {
                search = "";
            }

            Expression <Func <DB.Tables.Theme, bool> > whereSQL = t => t.Name.Contains(search) && t.Description.Contains(search);

            if (state != Theme.ThemeStates.NotSelected)
            {
                whereSQL.And(t => t.State == (int)state);
            }

            pager.TotalRows = await db.Themes.CountAsync(whereSQL);

            pager.List = await db.Themes.AsNoTracking()
                         .Where(whereSQL)
                         .Include(t => t.Master)
                         .Include(t => t.Posts)
                         .OrderByDescending(t => t.Posts.Count(p => p.CreateDate <= NOW && p.CreateDate > NOW.AddDays(-7)))
                         .Skip(pager.GetSkip())
                         .Take(pager.Rows)
                         .Select(t => new Results.ThemeItem
            {
                Id         = t.Id,
                Name       = t.Name,
                Master     = t.Master.AccountName,
                CreateDate = t.CreateDate.ToStandardString()
            })
                         .ToListAsync();

            return(Resp.Success(pager, ""));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 获取主页的帖子列表
        /// </summary>
        public async Task <Resp> GetHomePageListAsync()
        {
            DateTimeOffset NOW = DateTimeOffset.Now;

            using var db = new MyForContext();
            List <Results.HomePageSegmentItem> list = await db.Segments.AsNoTracking()
                                                      .Where(t => t.State == (int)Segment.SegmentState.Enabled)
                                                      .OrderByDescending(t => t.CreateDate)
                                                      .Take(10)
                                                      .Select(t => new Results.HomePageSegmentItem
            {
                Id      = t.Id,
                Content = t.Content,
                Likes   = t.Likes,
            })
                                                      .ToListAsync();

            return(Resp.Success(list));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 启用管理员
        /// </summary>
        /// <param name="description">启用理由</param>
        /// <returns></returns>
        public async Task <Resp> EnabledAsync(string description)
        {
            using var db = new MyForContext();

            DB.Tables.Post account = await db.Posts.FirstOrDefaultAsync(c => c.Id == Id);

            if (account is null)
            {
                return(Resp.Fault(Resp.NONE, NONE_POST));
            }

            account.State = (int)PostState.Enabled;
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success());
            }
            return(Resp.Fault(Resp.NONE, "启用失败"));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 删除一个管理员
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <Resp> Delete(int id)
        {
            using var db = new MyForContext();

            var account = await db.Accounts.AsNoTracking().FirstOrDefaultAsync(a => a.Id == id);

            if (account is null)
            {
                return(Resp.Fault(null, "找不到该管理员"));
            }

            db.Accounts.Remove(account);
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success());
            }
            return(Resp.Fault(null, "删除失败, 请重试"));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 登出
        /// </summary>
        /// <returns></returns>
        public async Task <Resp> Logout()
        {
            using var db = new MyForContext();

            DB.Tables.Client client = await db.Clients.FirstOrDefaultAsync(c => c.Id == Id);

            if (client is null)
            {
                return(Resp.Fault(Resp.NONE, NOT_CLIENT));
            }

            client.Token = Guid.NewGuid();
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, "登出成功"));
            }
            return(Resp.Fault(Resp.NONE, "登出失败"));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 启用管理员
        /// </summary>
        /// <param name="description">启用理由</param>
        /// <returns></returns>
        public async Task <Resp> EnabledAsync(string description)
        {
            using var db = new MyForContext();

            DB.Tables.Account account = await db.Accounts.FirstOrDefaultAsync(c => c.Id == Id);

            if (account is null)
            {
                return(Resp.Fault(null, "找不到该用户"));
            }

            account.State = (int)StandardStates.Enabled;
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success());
            }
            return(Resp.Fault(null, "启用失败"));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 登出
        /// </summary>
        public async Task <Resp> Logout()
        {
            using var db = new MyForContext();

            DB.Tables.Account account = await db.Accounts.FirstOrDefaultAsync(a => a.Id == Id);

            if (account is null)
            {
                return(Resp.NeedLogin(Resp.NONE, "请重新登录"));
            }

            account.Token = Guid.NewGuid();
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success(Resp.NONE, "成功"));
            }
            return(Resp.Fault(Resp.NONE, "失败"));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 启用客户
        /// </summary>
        /// <param name="description">启用理由</param>
        /// <returns></returns>
        public async Task <Resp> EnabledAsync(string description)
        {
            using var db = new MyForContext();

            DB.Tables.Client client = await db.Clients.FirstOrDefaultAsync(c => c.Id == Id);

            if (client is null)
            {
                return(Resp.Fault(Resp.NONE, NOT_CLIENT));
            }

            client.State = (int)StandardStates.Enabled;
            int suc = await db.SaveChangesAsync();

            if (suc == 1)
            {
                return(Resp.Success());
            }
            return(Resp.Fault(Resp.NONE, "启用失败"));
        }