Example #1
0
 public static async Task UnBanMemberWithMessage(int id)
 {
     try
     {
         TicketSysEntities db       = new TicketSysEntities();
         List <BanLIst>    banlists = db.BanLIst.Where(x => x.BanMemberId == id && x.EndTime > DateTime.Now).ToList();
         foreach (BanLIst banlist in banlists)
         {
             db.Entry(banlist).State = EntityState.Deleted;
             db.SaveChanges();
         }
         await SendMessageToMember(id, "iTicket 管理員已解除您的停權處分");
     }
     catch { }
 }
Example #2
0
 public static async Task BanMemberWithMessage(int id, int adminId, string reason, DateTime endtime)
 {
     try
     {
         TicketSysEntities db      = new TicketSysEntities();
         BanLIst           banlist = new BanLIst
         {
             BanMemberId   = id,
             AdminMemberId = adminId,
             Reason        = reason,
             EndTime       = endtime
         };
         db.Entry(banlist).State = EntityState.Added;
         db.SaveChanges();
         await SendMessageToMember(id, $"iTicket 管理員以「{reason}」為由將您停權到 {endtime:yyyy-MM-dd}");
     }
     catch { }
 }
        public static async Task DeleteWithMessage(int id, string message, string type, int arid,
                                                   int adminId, string reason = "", DateTime?endtime = null)
        {
            TicketSysEntities db = new TicketSysEntities();

            if (type == "A")
            {
                try
                {
                    List <Article_Report> reportsA = db.Article_Report.Where(x => x.ArticleId == arid).ToList();
                    foreach (Article_Report reportA in reportsA)
                    {
                        db.Entry(reportA).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                    int[] repliesIDs = db.Reply.Where(x => x.ArticleID == arid).Select(x => x.ReplyID).ToArray();
                    foreach (int rid in repliesIDs)
                    {
                        List <Reply_Report> reportsR = db.Reply_Report.Where(x => x.ReplyId == rid).ToList();
                        foreach (Reply_Report reportR in reportsR)
                        {
                            db.Entry(reportR).State = EntityState.Deleted;
                            db.SaveChanges();
                        }
                        Reply reply = db.Reply.FirstOrDefault(x => x.ReplyID == rid);
                        db.Entry(reply).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                    Article article = db.Article.FirstOrDefault(x => x.ArticleID == arid);
                    db.Entry(article).State = EntityState.Deleted;
                    db.SaveChanges();
                    if (reason == "" || endtime == null)
                    {
                        ShortMessage shortmessage = new ShortMessage
                        {
                            MemberID       = id,
                            MessageContent = $"文章刪除通知: {message}"
                        };
                        db.Entry(shortmessage).State = EntityState.Added;
                        db.SaveChanges();
                        MailMessage mail = new MailMessage
                        {
                            From       = new MailAddress("*****@*****.**"),
                            Subject    = "iTicket 發送了一則系統通知給您",
                            Body       = $"<h3>iTicket 發送了一則系統通知給您</h3><h4>文章刪除通知</h4><p>{message}</p>",
                            IsBodyHtml = true
                        };
                        mail.To.Add(db.Member.FirstOrDefault(x => x.MemberID == id).Email);
                        using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com"))
                        {
                            smtpClient.Port        = 587;
                            smtpClient.Credentials = new NetworkCredential("*****@*****.**", "!@#qweasd");
                            smtpClient.EnableSsl   = true;
                            await smtpClient.SendMailAsync(mail);
                        }
                    }
                    else
                    {
                        BanLIst banlist = new BanLIst
                        {
                            BanMemberId   = id,
                            AdminMemberId = adminId,
                            Reason        = reason,
                            EndTime       = endtime.Value
                        };
                        db.Entry(banlist).State = EntityState.Added;
                        db.SaveChanges();
                        ShortMessage shortmessage = new ShortMessage
                        {
                            MemberID       = id,
                            MessageContent = $"文章刪除通知: {message}"
                        };
                        db.Entry(shortmessage).State = EntityState.Added;
                        db.SaveChanges();
                        ShortMessage shortmessage2 = new ShortMessage
                        {
                            MemberID       = id,
                            MessageContent = $"iTicket 管理員以「{reason}」為由將您停權到 {endtime:yyyy-MM-dd}"
                        };
                        db.Entry(shortmessage2).State = EntityState.Added;
                        db.SaveChanges();
                        MailMessage mail = new MailMessage
                        {
                            From       = new MailAddress("*****@*****.**"),
                            Subject    = "iTicket 發送了一則系統通知給您",
                            Body       = $@"<h3>iTicket 發送了一則系統通知給您</h3>
                                      <p>iTicket 管理員以「{reason}」為由將您停權到 {endtime:yyyy-MM-dd}</p>
                                      <h4>文章刪除通知</h4>
                                      <p>{message}</p>",
                            IsBodyHtml = true
                        };
                        mail.To.Add(db.Member.FirstOrDefault(x => x.MemberID == id).Email);
                        using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com"))
                        {
                            smtpClient.Port        = 587;
                            smtpClient.Credentials = new NetworkCredential("*****@*****.**", "!@#qweasd");
                            smtpClient.EnableSsl   = true;
                            await smtpClient.SendMailAsync(mail);
                        }
                    }
                }
                catch { }
            }
            else
            {
                try
                {
                    List <Reply_Report> reports = db.Reply_Report.Where(x => x.ReplyId == arid).ToList();
                    foreach (Reply_Report report in reports)
                    {
                        db.Entry(report).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                    Reply reply = db.Reply.FirstOrDefault(x => x.ReplyID == arid);
                    db.Entry(reply).State = EntityState.Deleted;
                    db.SaveChanges();
                    if (reason == "" || endtime == null)
                    {
                        ShortMessage shortmessage = new ShortMessage
                        {
                            MemberID       = id,
                            MessageContent = $"回覆刪除通知: {message}"
                        };
                        db.Entry(shortmessage).State = EntityState.Added;
                        db.SaveChanges();
                        MailMessage mail = new MailMessage
                        {
                            From       = new MailAddress("*****@*****.**"),
                            Subject    = "iTicket 發送了一則系統通知給您",
                            Body       = $"<h3>iTicket 發送了一則系統通知給您</h3><h4>回覆刪除通知</h4><p>{message}</p>",
                            IsBodyHtml = true
                        };
                        mail.To.Add(db.Member.FirstOrDefault(x => x.MemberID == id).Email);
                        using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com"))
                        {
                            smtpClient.Port        = 587;
                            smtpClient.Credentials = new NetworkCredential("*****@*****.**", "!@#qweasd");
                            smtpClient.EnableSsl   = true;
                            await smtpClient.SendMailAsync(mail);
                        }
                    }
                    else
                    {
                        BanLIst banlist = new BanLIst
                        {
                            BanMemberId   = id,
                            AdminMemberId = adminId,
                            Reason        = reason,
                            EndTime       = endtime.Value
                        };
                        db.Entry(banlist).State = EntityState.Added;
                        db.SaveChanges();
                        ShortMessage shortmessage = new ShortMessage
                        {
                            MemberID       = id,
                            MessageContent = $"回覆刪除通知: {message}"
                        };
                        db.Entry(shortmessage).State = EntityState.Added;
                        db.SaveChanges();
                        ShortMessage shortmessage2 = new ShortMessage
                        {
                            MemberID       = id,
                            MessageContent = $"iTicket 管理員以「{reason}」為由將您停權到 {endtime:yyyy-MM-dd}"
                        };
                        db.Entry(shortmessage2).State = EntityState.Added;
                        db.SaveChanges();
                        MailMessage mail = new MailMessage
                        {
                            From       = new MailAddress("*****@*****.**"),
                            Subject    = "iTicket 發送了一則系統通知給您",
                            Body       = $@"<h3>iTicket 發送了一則系統通知給您</h3>
                                      <p>iTicket 管理員以「{reason}」為由將您停權到 {endtime:yyyy-MM-dd}</p>
                                      <h4>回覆刪除通知</h4>
                                      <p>{message}</p>",
                            IsBodyHtml = true
                        };
                        mail.To.Add(db.Member.FirstOrDefault(x => x.MemberID == id).Email);
                        using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com"))
                        {
                            smtpClient.Port        = 587;
                            smtpClient.Credentials = new NetworkCredential("*****@*****.**", "!@#qweasd");
                            smtpClient.EnableSsl   = true;
                            await smtpClient.SendMailAsync(mail);
                        }
                    }
                }
                catch { }
            }
        }