/// <summary>
        /// Delete specified NodeVoltage from database
        /// </summary>
        /// <param name="user">dto NodeVoltage</param>
        public void DeleteNodeVoltage(NodeVoltageDto 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.Voltages);

                //Find NodeVoltage which have to be deleted.
                Voltage existingNodeVoltage = dbContext.Voltages.Single(nv => nv.Id == dto.Id);

                //If required NodeReactiveLoad doesn't exists, throw exception.
                if (existingNodeVoltage == null)
                {
                    throw new Exception("Node Voltage does not exist");
                }
                //else perform delete from database
                else
                {
                    //Delete node Voltage.
                    dbContext.DeleteObject(existingNodeVoltage);

                    //Saves chages.
                    dbContext.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
Example #2
0
 public void InitialNodeVoltageTest()
 {
     NodeVoltageDto target = new NodeVoltageDto(); // TODO: Initialize to an appropriate value
     double expected = 0F; // TODO: Initialize to an appropriate value
     double actual;
     target.InitialNodeVoltage = expected;
     actual = target.InitialNodeVoltage;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
        /// <summary>
        /// Returns list of all Node Voltages from database.
        /// </summary>
        /// <returns>List list of NodeVoltageDto's</returns>
        public List<NodeVoltageDto> GetAllNodeVoltages()
        {
            //Instantiate list of dto Node Voltages which has been returned.
            List<NodeVoltageDto> listDto = new List<NodeVoltageDto>();
            try
            {
                //Before any action, it must be updated because calls from contract uses
                //only one instance of Node Manager.
                dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Voltages);

                //list of Node Voltages from entities
                List<Voltage> list = dbContext.Voltages.OrderBy(nv => nv.Id).ToList();

                //filling the list
                foreach (Voltage nv in list)
                {
                    NodeVoltageDto nodeVoltageDto = new NodeVoltageDto(nv.Id, nv.InitialVoltage, nv.CurrentVoltage, nv.MaximalVoltage, nv.MaximalVoltage);
                    listDto.Add(nodeVoltageDto);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
            //returns list of all node Voltages as list of dtoes.
            return listDto;
        }
        /// <summary>
        /// Update NodeVoltage in database
        /// </summary>
        /// <param name="dto">dto of NodeVoltage</param>
        public void UpdateNodeVoltage(NodeVoltageDto dto)
        {
            try
            {
                //Before any action, it must be updated because calls from contract uses
                //only one instance of Node Voltage Manager.
                dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Voltages);

                //Find NodeVoltage which have to be updated.
                Voltage existingNodeVoltage = dbContext.Voltages.Single(nv => nv.Id == dto.Id);

                //If required NodeVoltage doesn't exists, throw exception.
                if (existingNodeVoltage == null)
                {
                    throw new Exception("Node Voltage does not exist");
                }
                //else prepare all data for storing to database
                else
                {
                    existingNodeVoltage.Id = dto.Id;
                    existingNodeVoltage.InitialVoltage = dto.InitialNodeVoltage;
                    existingNodeVoltage.CurrentVoltage = dto.CurrentNodeVoltage;
                    existingNodeVoltage.MinimalVoltage = dto.MinimalNodeVoltage;
                    existingNodeVoltage.MaximalVoltage = dto.MaximalNodeVoltage;
                }

                //Save changes
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
        /// <summary>
        /// Insert specified NodeVoltage in database
        /// </summary>
        /// <param name="dto">dto data for NodeVoltage</param>
        public void InsertNodeVoltage(NodeVoltageDto 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.Voltages);
                Voltage nv = new Voltage();

                nv.Id = dto.Id;
                nv.InitialVoltage = dto.InitialNodeVoltage;
                nv.CurrentVoltage = dto.CurrentNodeVoltage;
                nv.MinimalVoltage = dto.MinimalNodeVoltage;
                nv.MaximalVoltage = dto.MaximalNodeVoltage;

                //Adds new NodeVoltage details to context
                dbContext.Voltages.AddObject(nv);

                //saves changes.
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
Example #6
0
 public void NodeVoltageDtoConstructorTest1()
 {
     NodeVoltageDto target = new NodeVoltageDto();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Example #7
0
 public void NodeVoltageDtoConstructorTest()
 {
     int id = 0; // TODO: Initialize to an appropriate value
     double initialNodeVoltage = 0F; // TODO: Initialize to an appropriate value
     double currentNodeVoltage = 0F; // TODO: Initialize to an appropriate value
     double minimalNodeVoltage = 0F; // TODO: Initialize to an appropriate value
     double maximalNodeVoltage = 0F; // TODO: Initialize to an appropriate value
     NodeVoltageDto target = new NodeVoltageDto(id, initialNodeVoltage, currentNodeVoltage, minimalNodeVoltage, maximalNodeVoltage);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }