public int Update(match_goal entity) { try { // check time_at var info_rule = new general_rule_dao().GetRule(); if (entity.time_at > info_rule.max_time_goal) { return(-2); } // for updating var info = db.match_goal.Find(entity.id); info.time_at = entity.time_at; info.footballer_id = entity.footballer_id; info.goal_type_id = entity.goal_type_id; info.match_id = entity.match_id; db.SaveChanges(); return(1); } catch (Exception) { return(-1); } }
//common lib /// <summary> /// return -2 (time_at invalid) /// </summary> /// <param name="entity"></param> /// <returns></returns> public int Insert(match_goal entity) { try { var info_rule = new general_rule_dao().GetRule(); if (entity.time_at > info_rule.max_time_goal) { return(-2); } db.match_goal.Add(entity); db.SaveChanges(); return(1); } catch (Exception) { return(-1); } }
public IEnumerable <rank> ListClubRank_BySeason(ref string seasonID, string sortType1 = "totalScore", string sortType2 = "goalDifference", string sortType3 = "winScore", string sortType4 = "winScoreGuest") { string tmp_seasonID = seasonID; var rule = new general_rule_dao().GetRule(); var result = new season_dao().CheckSeason(seasonID); IEnumerable <rank> model = null; if (result) { model = db.ranks.Where(x => x.season_id == tmp_seasonID); } else { string current_season = db.seasons.OrderByDescending(x => x.display_order).Select(x => x.id).First().ToString(); model = db.ranks.Where(x => x.season_id == current_season); seasonID = current_season; } // Sắp xếp bảng xếp hạng theo 4 điều lệ truyền vào // Theo thứ tứ từ sortType1,2,3,4 switch (sortType1) { //Rơi vào thứ tự sắp đầu tiên theo điều kiện case "totalScore": { switch (sortType2) { //Rơi vào thứ tự sắp đầu tiên + thứ 2 theo điều kiện case "goalDifference": { //Rơi vào thứ tự sắp đầu tiên + thứ 2 + thứ 3 theo điều kiện switch (sortType3) { //Rơi vào thứ tự sắp đầu tiên + thứ 2 + thứ 3 + thứ 4(là loại cuối) theo điều kiện case "winScore": { model = model.OrderByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ToList(); break; } case "winScoreGuest": { model = model.OrderByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => x.win_score).ToList(); break; } } break; } //Kết thúc kiểm tra thứ tự ưu tiên thứ 2 case "winScore": { switch (sortType3) { case "goalDifference": { model = model.OrderByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_match_guest).ToList(); break; } case "winScoreGuest": { model = model.OrderByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_score - x.lose_score)).ToList(); break; } } break; } case "winScoreGuest": { switch (sortType3) { case "goalDifference": { model = model.OrderByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_score).ToList(); break; } case "winScore": { model = model.OrderByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_score - x.lose_score)).ToList(); break; } } break; } } break; } //Kết thúc kiểm tra thứ tự ưu tiên thứ 1 case "goalDifference": { switch (sortType2) { case "totalScore": { switch (sortType3) { case "winScore": { model = model.OrderByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ToList(); break; } case "winScoreGuest": { model = model.OrderByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => x.win_score).ToList(); break; } } break; } case "winScore": { switch (sortType3) { case "totalScore": { model = model.OrderByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ToList(); break; } case "winScoreGuest": { model = model.OrderByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ToList(); break; } } break; } case "winScoreGuest": { switch (sortType3) { case "totalScore": { model = model.OrderByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => x.win_score).ToList(); break; } case "winScore": { model = model.OrderByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ToList(); break; } } break; } } break; } case "winScore": { switch (sortType2) { case "totalScore": { switch (sortType3) { case "goalDifference": { model = model.OrderByDescending(x => x.win_score).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_match_guest).ToList(); break; } case "winScoreGuest": { model = model.OrderByDescending(x => x.win_score).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_score - x.lose_score)).ToList(); break; } } break; } case "goalDifference": { switch (sortType3) { case "totalScore": { model = model.OrderByDescending(x => x.win_score).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_match_guest).ToList(); break; } case "winScoreGuest": { model = model.OrderByDescending(x => x.win_score).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ToList(); break; } } break; } case "winScoreGuest": { switch (sortType3) { case "totalScore": { model = model.OrderByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => (x.win_score - x.lose_score)).ToList(); break; } case "goalDifference": { model = model.OrderByDescending(x => x.win_score).ThenByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ToList(); break; } } break; } } break; } case "winScoreGuest": { switch (sortType2) { case "totalScore": { switch (sortType3) { case "goalDifference": { model = model.OrderByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_score).ToList(); break; } case "winScore": { model = model.OrderByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_score - x.lose_score)).ToList(); break; } } break; } case "goalDifference": { switch (sortType3) { case "totalScore": { model = model.OrderByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => x.win_score).ToList(); break; } case "winScore": { model = model.OrderByDescending(x => x.win_match_guest).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ToList(); break; } } break; } case "winScore": { switch (sortType3) { case "totalScore": { model = model.OrderByDescending(x => x.win_match_guest).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ThenByDescending(x => (x.win_score - x.lose_score)).ToList(); break; } case "goalDifference": { model = model.OrderByDescending(x => x.win_match_guest).ThenByDescending(x => x.win_score).ThenByDescending(x => (x.win_score - x.lose_score)).ThenByDescending(x => (x.win_match * rule.win_score) + (x.draw_match * rule.draw_score) + (x.lose_match * rule.lose_score)).ToList(); break; } } break; } } break; } } return(model.ToList()); }