public static async Task SendMessageToMember(int id, string message) { try { TicketSysEntities db = new TicketSysEntities(); 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><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 { } }
public static async Task MerchantVerificationWithMessage(int id, bool fPass) { try { TicketSysEntities db = new TicketSysEntities(); Seller seller = db.Seller.FirstOrDefault(x => x.MemberId == id); seller.fPass = fPass; db.SaveChanges(); await SendMessageToMember(id, $"iTicket 管理員已{(fPass ? "通過" : "駁回")}您的商家審核"); } catch { } }
public static IEnumerable <Member> MemberQuery(int roleId, string keyword) { TicketSysEntities db = new TicketSysEntities(); return(db.Member.Where(x => roleId == 9 || x.MemberRoleId == roleId).AsEnumerable() .Where(x => string.IsNullOrEmpty(keyword) || x.Email.Split('@')[0].ToLower().Contains(keyword) || x.NickName.ToLower().Contains(keyword) || x.Name.ToLower().Contains(keyword) || (x.Phone != null && x.Phone.Contains(keyword)) )); }
public static IEnumerable <Seller> SellerQuery(string keyword, int nonverify) { TicketSysEntities db = new TicketSysEntities(); return(db.Seller.Where(x => nonverify == 0 || x.fPass == null).AsEnumerable() .Where(x => string.IsNullOrEmpty(keyword) || x.Member.Email.Split('@')[0].ToLower().Contains(keyword) || x.Member.NickName.ToLower().Contains(keyword) || x.Member.Name.ToLower().Contains(keyword) || (x.Member.Phone != null && x.Member.Phone.Contains(keyword)) )); }
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 { } }
public static IEnumerable <Member> BanMemberQuery(string keyword) { TicketSysEntities db = new TicketSysEntities(); List <int> banlist = db.BanLIst.Where(x => x.EndTime > DateTime.Now) .Select(x => x.BanMemberId).Distinct().OrderBy(x => x).ToList(); return(db.Member.AsEnumerable() .Where(x => string.IsNullOrEmpty(keyword) || x.Email.Split('@')[0].ToLower().Contains(keyword) || x.NickName.ToLower().Contains(keyword) || x.Name.ToLower().Contains(keyword) || (x.Phone != null && x.Phone.Contains(keyword)) ).Where(x => banlist.BinarySearch(x.MemberID) >= 0)); }
public static IEnumerable <Article> ArticleQuery(int author, int cate, int date, int report, string keyword) { TicketSysEntities db = new TicketSysEntities(); return(db.Article_Report.GroupBy(x => x.ArticleId).Where(g => g.Count() >= report).AsEnumerable() .OrderByDescending(g => g.Count()).ThenByDescending(g => g.First().ArticleId) .Select(x => x.First().Article) .Where(x => author == 0 || x.MemberID == author) .Where(x => cate == 0 || x.ArticleCategoryID == cate) .Where(x => date == 0 || (DateTime.Now - x.Date).TotalDays <= date) .Where(x => string.IsNullOrEmpty(keyword) || x.ArticleTitle.ToLower().Contains(keyword) || x.Member.Email.Split('@')[0].ToLower().Contains(keyword) )); }
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 { } } }
public static bool ArticleReplyConfirmIsReport(int ArticleId) { TicketSysEntities db = new TicketSysEntities(); return(db.Reply_Report.Where(x => x.Reply.ArticleID == ArticleId).Count() != 0); }