public ActionResult ImportSignInfo(HttpPostedFileBase file, string SignID, SignListViewModel signListViewModel) { DataTable dataTable = new DataTable(); var fileName = file.FileName; var filePath = Server.MapPath(string.Format("~/{0}", "Files")); string path = Path.Combine(filePath, fileName); file.SaveAs(path); dataTable = ImportExcel.GetExcelDataTable(path); if (dataTable.Rows.Count > 0) { GameClubEntities gameClubEntities = new GameClubEntities(); CovertListHelper toList = new CovertListHelper(); List <SignInfo> signInfos = toList.convertToList <SignInfo>(dataTable); IEnumerable <SignInfo> signInfosResult = gameClubEntities.SignInfo.Where(s => s.SignID == SignID); foreach (var item in signInfos) { SignInfo signInfo = signInfosResult.Where(s => s.GameID == item.GameID).FirstOrDefault(); if (signInfo != null) { if (!string.IsNullOrEmpty(item.VoiceCondition)) { signInfo.VoiceCondition = item.VoiceCondition; } else { signInfo.VoiceCondition = "未语音"; } } } gameClubEntities.SaveChanges(); } signListViewModel = UpdateSignListViewModel(signListViewModel); return(PartialView("_SignList", signListViewModel)); }
public ActionResult ImportGameMember(HttpPostedFileBase file, int pageID, int pagesize, string keyword, string sortBy, string currentSort, bool IsOrderBy) { DataTable dataTable = new DataTable(); var fileName = file.FileName; var filePath = Server.MapPath(string.Format("~/{0}", "Files")); string path = Path.Combine(filePath, fileName); file.SaveAs(path); dataTable = ImportExcel.GetExcelDataTable(path); if (dataTable.Rows.Count > 0) { GameClubEntities gameClubEntities = new GameClubEntities(); CovertListHelper toList = new CovertListHelper(); List <GameMember> gameMembers = toList.convertToList <GameMember>(dataTable); foreach (var item in gameMembers)//对比数据库中的信息,把存在于Excel表中且不存在于数据库表的成员添加上去,如果存在且处于被删除的状态,设为未删除状态 { GameMember game = gameClubEntities.GameMember.Where(g => g.GameID == item.GameID).FirstOrDefault(); if (game == null) { GameMember gameMember = new GameMember { GameID = item.GameID, GameName = item.GameName, JoinDate = DateTime.Now, }; if (item.Authority > 0) { gameMember.Authority = item.Authority; } else { gameMember.Authority = EFGameMember.gameAuthorities.Count; } gameClubEntities.GameMember.Add(gameMember); } else { game.IsDel = null; game.DelTime = null; } } foreach (var item in gameClubEntities.GameMember)//把存在于数据库表中且不存在于Excel表的成员设为删除状态 { if (gameMembers.Where(g => g.GameID == item.GameID).FirstOrDefault() == null) { item.IsDel = true; item.DelTime = DateTime.Now; } } gameClubEntities.SaveChanges(); } return(RedirectToAction("GameMemberManage", new { pageID, pagesize, keyword, sortBy, currentSort, IsOrderBy })); }
public ActionResult ImportContribution(HttpPostedFileBase file, string ContributionID, ContributionListViewModel contributionListViewModel) { DataTable dataTable = new DataTable(); var fileName = file.FileName; var filePath = Server.MapPath(string.Format("~/{0}", "Files")); string path = Path.Combine(filePath, fileName); file.SaveAs(path); dataTable = ImportExcel.GetExcelDataTable(path); if (dataTable.Rows.Count > 0) { GameClubEntities gameClubEntities = new GameClubEntities(); CovertListHelper toList = new CovertListHelper(); List <Contribution> contributions = toList.convertToList <Contribution>(dataTable); IEnumerable <Contribution> contributionsResult = gameClubEntities.Contribution.Where(c => c.ContributionID == ContributionID); ContributionList contributionList = gameClubEntities.ContributionList.Where(c => c.ContributionID == ContributionID).FirstOrDefault(); foreach (var item in contributions) { Contribution contribution = contributionsResult.Where(c => c.GameID == item.GameID).FirstOrDefault(); if (contribution != null) { if (item.AllContribution != null) { contribution.AllContribution = item.AllContribution; if (contributionList != null && contributionList.Time != null && contributionList.Time > 0) { contribution.MinSpeed = (contribution.AllContribution) / contributionList.Time * decimal.Parse("60"); } } } } gameClubEntities.SaveChanges(); } contributionListViewModel = UpdateContributionListViewModel(contributionListViewModel); return(PartialView("_ContributionList", contributionListViewModel)); }