public List <string> GetCategories() { IRisk risk = null; List <string> tradeCategories = new List <string>(); List <IRisk> risks = new List <IRisk> { RiskFactory.Create(TypeRisk.LowRisk), RiskFactory.Create(TypeRisk.MediumRisk), RiskFactory.Create(TypeRisk.HighRisk) }; foreach (var trade in _portfolio) { foreach (IRisk r in risks) { risk = r; if (r.CalculateRisk(trade)) { break; } } if (risk != null) { tradeCategories.Add(risk.Type); } } return(tradeCategories); }
public Trade(double value, string clientSector) { this._value = value; this._clientSector = clientSector; this._iRisk = new Risk.Risk(this); }
public Risk(ITrade trade) { if (trade.Value < 1000000) { if (trade.ClientSector == "Public") { this._risk = new LowRisk(); } } else if (trade.Value > 1000000) { if (trade.ClientSector == "Public") { this._risk = new MediumRisk(); } else { this._risk = new HighRisk(); } } if (this._risk == null) { this._risk = new NoFoundRisk(); } }
/// <summary> /// Edits risks /// </summary> /// <param name="risk"></param> public void EditTask(IRisk risk) { Risk riskTobeEdited = _riskRoot.Risks.Where(r => r.RiskID == risk.RiskID).FirstOrDefault(); if (riskTobeEdited != null) { riskTobeEdited.RiskDescription = risk.RiskDescription; riskTobeEdited.RiskLevel = risk.RiskLevel; riskTobeEdited.MitigationPlan = risk.MitigationPlan; riskTobeEdited.Status = risk.Status; // taskTobeEdited.Project = (risk as Risk).Project; } }
public void AddRisk(IRisk risk) { try { connection.OpenConnection(); DbCommand command = new DbCommand("INSERT INTO Risks (Title, TypeId) VALUES (@title, @typeid);"); command.Parameters = new SqlParameter[2]; command.Parameters[0] = new SqlParameter("title", risk.Title); command.Parameters[1] = new SqlParameter("typeid", risk.Type.Id); command.Type = DbCommand.DbCommandType.INSERT; connection.ExecNonQuery(command); //collection doesn't contain user Id here; RiskCollection = null; } catch (Exception e) { Logger.Instance.WriteToLog(e.StackTrace); throw; } finally { connection.CloseConnection(); } }
public void EditRisk(IRisk risk) { try { connection.OpenConnection(); DbCommand command = new DbCommand("UPDATE Risks SET Title = @title, TypeId = @typeid where Id = @id;"); command.Parameters = new SqlParameter[3]; command.Parameters[0] = new SqlParameter("id", risk.Id); command.Parameters[1] = new SqlParameter("title", risk.Title); command.Parameters[2] = new SqlParameter("typeid", risk.Type.Id); command.Type = DbCommand.DbCommandType.UPDATE; connection.ExecNonQuery(command); if (RiskCollection != null) { //update value in Collection RiskCollection.Remove(RiskCollection.Find(x => x.Id == risk.Id)); RiskCollection.Add(risk); } } finally { connection.CloseConnection(); } }
/// <summary> /// Removes risk object from the root list /// </summary> /// <param name="risk">IRisk object</param> public void RemoveRisk(IRisk risk) { Risk riskTobeRemoved = _riskRoot.Risks.Where(r => r.RiskID == risk.RiskID).FirstOrDefault(); _riskRoot.Risks.Remove(riskTobeRemoved); }
/// <summary> /// Adds new Risk object to the root list /// </summary> /// <param name="risk">IRisk object</param> public void AddRisk(IRisk risk) { _riskRoot.Risks.Add(risk as Risk); }