public ActionResult AddReactor(ReactorPO form) { ActionResult response = null; int rowsAffected; try { _logger.LogMessage("Info", "Add Reactor Post request", MethodBase.GetCurrentMethod().ToString(), "Request to add Reactor information received."); if (ModelState.IsValid) { _logger.LogMessage("Info", "Model State check passed", MethodBase.GetCurrentMethod().ToString(), "ReactorPO form model state is valid."); //If thermal and electric power entered, calculate efficiency with BLO if (form.ThermalPower != 0 && form.ElectricPower != 0) { _logger.LogMessage("Attempting to calculate efficiency."); ReactorBO reactorBO = Mapping.Mapper.ReactorPOtoBO(form); form.Efficiency = _reactorBLO.CalculateEfficiency(reactorBO); } else { _logger.LogMessage("Thermal Power or Electric Power not provided. Did not calculate efficiency."); } _logger.LogMessage("Attempting to map Reactor PO to DO."); ReactorDO reactorDO = Mapping.Mapper.ReactorPOtoDO(form); rowsAffected = _reactorDAO.AddNewReactor(reactorDO); if (rowsAffected > 0) { _logger.LogMessage("Info", "New reactor information added", MethodBase.GetCurrentMethod().ToString(), form.Name + " reactor was added to database."); TempData["addNew"] = "Reactor added successfully."; } else { _logger.LogMessage("Warning", "Add Reactor attempt failed", MethodBase.GetCurrentMethod().ToString(), "Attempt to add new reactor showed no database rows affected."); TempData["addNew"] = "Failed to add new reactor to database."; } response = RedirectToAction("Index"); } else { _logger.LogMessage("Warning", "Model State check failed", MethodBase.GetCurrentMethod().ToString(), "ReactorPO form model state was not valid. Returning user to View."); FillGenerationDropDown(form); FillModeratorDropDown(form); response = View(form); } } catch (Exception ex) { _logger.LogMessage(ex, "Fatal"); } finally { } return(response); }
public ActionResult UpdateReactor(ReactorPO form) { ActionResult response = null; try { _logger.LogMessage("Info", "Update Reactor Post", MethodBase.GetCurrentMethod().ToString(), "Request to update information for reactor with ID #" + form.ReactorID + " received."); if (ModelState.IsValid) { _logger.LogMessage("Info", "Model State check passed", MethodBase.GetCurrentMethod().ToString(), "ReactorPO form model state is valid."); if (form.ThermalPower != 0 && form.ElectricPower != 0) { _logger.LogMessage("Attempting to calculate efficiency."); ReactorBO reactorBO = Mapping.Mapper.ReactorPOtoBO(form); form.Efficiency = _reactorBLO.CalculateEfficiency(reactorBO); } else { _logger.LogMessage("Thermal Power or Electric Power not provided. Did not calculate efficiency."); } _reactorDAO.UpdateReactor(Mapping.Mapper.ReactorPOtoDO(form)); TempData["updateReactor"] = "Reactor information updated."; response = RedirectToAction("ReactorDetails", "Reactor", new { id = form.ReactorID }); } else { _logger.LogMessage("Warning", "Model State check failed", MethodBase.GetCurrentMethod().ToString(), "ReactorPO form model state was not valid. Returning user to View."); FillGenerationDropDown(form); FillModeratorDropDown(form); response = View(form); } } catch (Exception ex) { _logger.LogMessage(ex, "Fatal"); } finally { } return(response); }
public static ReactorBO ReactorPOtoBO(ReactorPO from) { ReactorBO to = new ReactorBO(); to.ReactorID = from.ReactorID; to.Name = from.Name; to.FullName = from.FullName; to.IsThermal = from.IsThermal; to.ModeratorID = from.ModeratorID; to.PrimaryCoolant = from.PrimaryCoolant; to.Fuel = from.Fuel; to.ThermalPower = from.ThermalPower; to.ElectricPower = from.ElectricPower; to.Efficiency = from.Efficiency; to.Year = from.Year; to.Generation = from.Generation; to.CountryOfOrigin = from.CountryOfOrigin; to.NumberActive = from.NumberActive; to.Notes = from.Notes; return(to); }
public ActionResult ReactorStatistics() { StatisticsPO dbStats = new StatisticsPO(); StatisticsBO statisticsBO = new StatisticsBO(); List <ReactorBO> reactorBOList = new List <ReactorBO>(); try { List <ReactorDO> reactorDOList = _reactorDAO.ObtainAllReactors(); if (reactorDOList != null) { foreach (ReactorDO reactorDO in reactorDOList) { ReactorBO reactorBO = Mapping.Mapper.ReactorDOtoBO(reactorDO); reactorBOList.Add(reactorBO); } statisticsBO = _reactorBLO.SpectrumCount(reactorBOList, statisticsBO); statisticsBO = _reactorBLO.SpectrumPercentage(statisticsBO); statisticsBO = _reactorBLO.GenerationCounter(reactorBOList, statisticsBO); int[] genCount = new int[6]; genCount[0] = statisticsBO.NoGenCount; genCount[1] = statisticsBO.GenIcount; genCount[2] = statisticsBO.GenIIcount; genCount[3] = statisticsBO.GenIIIcount; genCount[4] = statisticsBO.GenIVcount; genCount[5] = statisticsBO.GenVcount; statisticsBO = _reactorBLO.GenerationPercentage(genCount, statisticsBO); dbStats = Mapping.Mapper.StatisticsBOtoPO(statisticsBO); } } catch (Exception ex) { _logger.LogMessage(ex, "Fatal"); } finally { } return(View(dbStats)); }
public float CalculateEfficiency(ReactorBO reactorBO) { float efficiency = 100 * reactorBO.ElectricPower / reactorBO.ThermalPower; return(efficiency); }