/// <summary> /// Delete specified branch from database /// </summary> /// <param name="user">dto Branch</param> public void DeleteBranch(BranchDto 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.Branches); //Find branch which have to be deleted. Branch existingBranch = dbContext.Branches.Single(brch => brch.Id == dto.Id); //If required branch doesn't exists, throw exception. if (existingBranch == null) { throw new Exception("Branch does not exist"); } //else perform delete from database else { //Delete branch. dbContext.DeleteObject(existingBranch); //Saves chages. dbContext.SaveChanges(); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
public void BranchNameTest() { BranchDto target = new BranchDto(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; target.BranchName = expected; actual = target.BranchName; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void BranchDtoConstructorTest() { int id = 0; // TODO: Initialize to an appropriate value string branchName = string.Empty; // TODO: Initialize to an appropriate value int branchResistanceId = 0; // TODO: Initialize to an appropriate value int branchReactanceId = 0; // TODO: Initialize to an appropriate value int nodeId = 0; // TODO: Initialize to an appropriate value int nodeParent = 0; // TODO: Initialize to an appropriate value BranchDto target = new BranchDto(id, branchName, branchResistanceId, branchReactanceId, nodeId, nodeParent); Assert.Inconclusive("TODO: Implement code to verify target"); }
private void GetRootBranch() { if (rootBranch == null) { rootBranch = allBranches.Single(br => br.NodeParent == 0); } }
public void BranchReactanceIdTest() { BranchDto target = new BranchDto(); // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; target.BranchReactanceId = expected; actual = target.BranchReactanceId; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void BranchDtoConstructorTest1() { BranchDto target = new BranchDto(); Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <summary> /// Returns list of all branches from database. /// </summary> /// <returns>List list of BranchDto's</returns> public List<BranchDto> GetAllBranches() { //Instantiate list of dto branches which has been returned. List<BranchDto> listDto = new List<BranchDto>(); 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.Branches); //list of branches from entities List<Branch> list = dbContext.Branches.OrderBy(brch => brch.Id).ToList(); //filling the list foreach (Branch brch in list) { BranchDto branchDto = new BranchDto(brch.Id, brch.BranchName, brch.BranchResistanceId, brch.BranchReactanceId, brch.NodeId, brch.NodeParent); listDto.Add(branchDto); } } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } //returns list of all branch details as list of dtoes. return listDto; }
/// <summary> /// Update Branch in database /// </summary> /// <param name="dto">dto of Branch</param> public void UpdateBranch(BranchDto 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.Branches); //Find branch which have to be updated. Branch existingBranch = dbContext.Branches.Single(brch => brch.Id == dto.Id); //If required branch doesn't exists, throw exception. if (existingBranch == null) { throw new Exception("Branch does not exist"); } //else prepare all data for storing to database else { existingBranch.Id = dto.Id; existingBranch.BranchName = dto.BranchName; existingBranch.BranchResistanceId = dto.BranchResistanceId; existingBranch.BranchReactanceId = dto.BranchReactanceId; existingBranch.NodeId = dto.NodeId; } //Save changes dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }
/// <summary> /// Insert specified branch in database /// </summary> /// <param name="dto">dto data for branch</param> public void InsertBranch(BranchDto 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.Branches); Branch brch = new Branch(); brch.Id = dto.Id; brch.BranchName = dto.BranchName; brch.BranchResistanceId = dto.BranchResistanceId; brch.BranchReactanceId = dto.BranchReactanceId; brch.NodeId = dto.NodeId; //Adds new branch details to context dbContext.Branches.AddObject(brch); //saves changes. dbContext.SaveChanges(); } catch (Exception exception) { throw new Exception("SmartGridDataMenagers: " + exception.Message); } }