/// <summary> /// Delete specified branch reactance from database /// </summary> /// <param name="user">dto BranchReactance</param> public void DeleteBranchReactance(BranchReactanceDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of BranchManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchReactances); //Find branch reactance which have to be deleted. BranchReactance existingBranchReactance = dbContext.BranchReactances.Single(brRtc => brRtc.Id == dto.Id); //If required branch reactance doesn't exists, throw exception. if (existingBranchReactance == null) { throw new Exception("Branch reactance does not exist"); } //else perform delete from database else { //Delete branch. dbContext.DeleteObject(existingBranchReactance); //Saves chages. dbContext.SaveChanges(); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Annull all values after server stop. /// </summary> /// <returns>String annulment info</returns> public String AnnullValues() { String annulmentInfo = null; //Instantiate list of dto branch reactance which has been returned. List<BranchReactanceDto> listDto = new List<BranchReactanceDto>(); try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchReactances); //list of branch reactances from entities List<BranchReactance> list = dbContext.BranchReactances.OrderBy(br => br.Id).ToList(); //filling the list foreach (BranchReactance br in list) { BranchReactanceDto branchReactanceDto = new BranchReactanceDto(br.Id, br.InitialBranchReactance, br.CurrentBranchReactance, br.MinimalBranchReactance, br.MaximalBranchReactance); branchReactanceDto.CurrentBranchReactance = 0; UpdateBranchReactance(branchReactanceDto); annulmentInfo = annulmentInfo + "\t- Current branch reactance at id: " + branchReactanceDto.Id + "\t-> Annulled.\r\n"; } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } //returns String which shows initialization details return annulmentInfo; }
public void CurrentBranchReactanceTest() { BranchReactanceDto target = new BranchReactanceDto(); // TODO: Initialize to an appropriate value double expected = 0F; // TODO: Initialize to an appropriate value double actual; target.CurrentBranchReactance = expected; actual = target.CurrentBranchReactance; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void BranchReactanceDtoConstructorTest() { int id = 0; // TODO: Initialize to an appropriate value double initialBranchReactance = 0F; // TODO: Initialize to an appropriate value double currentBranchReactance = 0F; // TODO: Initialize to an appropriate value double minimalBranchReactance = 0F; // TODO: Initialize to an appropriate value double maximalBranchReactance = 0F; // TODO: Initialize to an appropriate value BranchReactanceDto target = new BranchReactanceDto(id, initialBranchReactance, currentBranchReactance, minimalBranchReactance, maximalBranchReactance); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void IdTest() { BranchReactanceDto target = new BranchReactanceDto(); // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; target.Id = expected; actual = target.Id; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void BranchReactanceDtoConstructorTest1() { BranchReactanceDto target = new BranchReactanceDto(); Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <summary> /// Update Branch Reactance in database /// </summary> /// <param name="dto">dto of Branch Reactance</param> public void UpdateBranchReactance(BranchReactanceDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchReactances); //Find branch which have to be updated. BranchReactance existingBranchReactance = dbContext.BranchReactances.Single(brRtc => brRtc.Id == dto.Id); //If required branch reactance doesn't exists, throw exception. if (existingBranchReactance == null) { throw new Exception("Branch reactance does not exist"); } //else prepare all data for storing to database else { existingBranchReactance.Id = dto.Id; existingBranchReactance.InitialBranchReactance = dto.InitialBranchReactance; existingBranchReactance.CurrentBranchReactance = dto.CurrentBranchReactance; existingBranchReactance.MinimalBranchReactance = dto.MinimalBranchReactance; existingBranchReactance.MaximalBranchReactance = dto.MaximalBranchReactance; } //Save changes dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Insert specified branch reactance in database /// </summary> /// <param name="dto">dto data for branch reactance</param> public void InsertBranchReactance(BranchReactanceDto dto) { try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchReactances); BranchReactance brRtc = new BranchReactance(); brRtc.Id = dto.Id; brRtc.InitialBranchReactance = dto.InitialBranchReactance; brRtc.CurrentBranchReactance = dto.CurrentBranchReactance; brRtc.MinimalBranchReactance = dto.MinimalBranchReactance; brRtc.MaximalBranchReactance = dto.MaximalBranchReactance; //Adds new branch reactance details to context dbContext.BranchReactances.AddObject(brRtc); //saves changes. dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Returns list of all branch reactances from database. /// </summary> /// <returns>List list of BranchReactanceDto's</returns> public List<BranchReactanceDto> GetAllBranchReactances() { //Instantiate list of dto branch reactances which has been returned. List<BranchReactanceDto> listDto = new List<BranchReactanceDto>(); try { //Before any action, it must be updated because calls from contract uses //only one instance of UserManager. dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.BranchReactances); //list of branch reactances from entities List<BranchReactance> list = dbContext.BranchReactances.OrderBy(brRtc => brRtc.Id).ToList(); //filling the list foreach (BranchReactance brRtc in list) { BranchReactanceDto branchReactanceDto = new BranchReactanceDto(brRtc.Id, brRtc.InitialBranchReactance, brRtc.CurrentBranchReactance, brRtc.MinimalBranchReactance, brRtc.MaximalBranchReactance); listDto.Add(branchReactanceDto); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } //returns list of all branch details as list of dtoes. return listDto; }