//計算評價平均 state = 0 回傳平均 1 回傳筆數 public static double Evaluation(string companyseq, string state = "0") { pet.Models.Model1 db = new pet.Models.Model1(); List <Order> orders = db.Order.Where(x => x.companyseq == companyseq).ToList(); double all = 0; int count = 0; foreach (Order o in orders) { if (o.Evalution.Select(x => x.star).FirstOrDefault() != null) { all += (double)o.Evalution.Select(x => x.star).FirstOrDefault(); count++; } } if (state == "0") { if (count == 0) { return(0); } return(Math.Round((all / count), 2)); } else { return(count); } }
//signalR_notice 發信者,收信者,內容,類型noticetype public static void signalR_notice(string fromseq, string toseq, string seq, string text, Noticetype type) { pet.Models.Model1 db = new pet.Models.Model1(); Notice notice = new Notice(); notice.fromseq = fromseq; notice.toseq = toseq; notice.seq = seq; notice.state = Convert.ToBoolean(Noticestate.未讀); notice.text = text; notice.postday = DateTime.Now; notice.type = (int)type; db.Notice.Add(notice); db.SaveChanges(); }