public bool Update(PlayoffUserInfoEntity userInfoEntity, string code) { var updated = false; try { using (var scope = new TransactionScope()) { var userInfo = _unitOfWork.PlayoffUserInfoRepository.GetByID(code); if (userInfo == null) { return(updated); } // Necessary stats for from NHL API userInfo.I_Games = userInfoEntity.I_Games; userInfo.I_Goals = userInfoEntity.I_Goals; userInfo.I_Assists = userInfoEntity.I_Assists; userInfo.I_Points = userInfoEntity.I_Points; userInfo.I_PtLastD = userInfoEntity.I_PtLastD; userInfo.I_PtLastW = userInfoEntity.I_PtLastW; userInfo.I_PtLastM = userInfoEntity.I_PtLastM; _unitOfWork.PlayoffUserInfoRepository.Update(userInfo); _unitOfWork.Save(); scope.Complete(); updated = true; } } catch (TransactionAbortedException ex) { LogError.Write(ex, "TransactionAbortedException"); } catch (ApplicationException ex) { LogError.Write(ex, "ApplicationException"); } catch (Exception ex) { LogError.Write(ex, "Exception"); } return(updated); }
public bool UpdateAll() { var updated = false; try { var users = _unitOfWork.PlayoffUserInfoRepository.GetAll().ToList(); if (!users.Any()) { LogError.Write(new Exception("Error"), "PlayoffUserInfo Get all returned 0 values"); return(false); } foreach (var userInfo in users) { var userStats = _unitOfWork.PlayoffPlayerInfoRepository .GetMany(p => p.C_UserEmail == userInfo.C_UserEmail && p.I_Status != (int)Statuses.Out).ToList(); if (!userStats.Any()) { LogError.Write(new Exception("Error"), "Could not retrieve user stats for this user info in PlayerInfo Table"); continue; } var userInfoEntity = new PlayoffUserInfoEntity { I_Games = userStats.Sum(u => u.I_Game), I_Goals = userStats.Sum(u => u.I_Goal), I_Assists = userStats.Sum(u => u.I_Assist), I_Points = userStats.Sum(u => u.I_Point), I_PtLastD = userStats.Sum(u => u.I_PtLastD), I_PtLastM = userStats.Sum(u => u.I_PtLastM), I_PtLastW = userStats.Sum(u => u.I_PtLastW) }; Update(userInfoEntity, userInfo.C_Code); } updated = true; } catch (Exception ex) { LogError.Write(ex, "Issue Update All"); } return(updated); }