Пример #1
0
        /// <summary>
        /// Delete specified Node from database
        /// </summary>
        /// <param name="user">dto node</param>
        public void DeleteNode(NodeDto 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.Nodes);

                //Find node which have to be deleted.
                Node existingNode = dbContext.Nodes.Single(nd => nd.Id == dto.Id);

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

                    //Saves chages.
                    dbContext.SaveChanges();
                }
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
Пример #2
0
 public void IdTest()
 {
     NodeDto target = new NodeDto(); // 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.");
 }
Пример #3
0
 public void NodeDtoConstructorTest()
 {
     int id = 0; // TODO: Initialize to an appropriate value
     string nodeName = string.Empty; // TODO: Initialize to an appropriate value
     int nodeTypeId = 0; // TODO: Initialize to an appropriate value
     int activeLoadId = 0; // TODO: Initialize to an appropriate value
     int reactiveLoadId = 0; // TODO: Initialize to an appropriate value
     int voltageId = 0; // TODO: Initialize to an appropriate value
     NodeDto target = new NodeDto(id, nodeName, nodeTypeId, activeLoadId, reactiveLoadId, voltageId);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Пример #4
0
 /// <summary>
 /// Implementation of insert node contract.
 /// Inserts NodeDto into database.
 /// </summary>
 /// <param name="dto">NodeDto</param>
 public void InsertNode(NodeDto dto)
 {
     try
     {
         nodeManager.InsertNode(dto);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Пример #5
0
 /// <summary>
 /// Implementation of delete node contract.
 /// Delete NodeDto from database.
 /// </summary>
 /// <param name="dto">NodeDto</param>
 public void DeleteNode(NodeDto dto)
 {
     try
     {
         nodeManager.DeleteNode(dto);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Пример #6
0
        /// <summary>
        /// Returns list of all Nodes from database.
        /// </summary>
        /// <returns>List list of NodeDto's</returns>
        public List<NodeDto> GetAllNodes()
        {
            //Instantiate list of dto nodes which has been returned.
            List<NodeDto> listDto = new List<NodeDto>();
            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.Nodes);

                //list of nodes from entities
                List<Node> list = dbContext.Nodes.OrderBy(nd => nd.Id).ToList();

                //filling the list
                foreach (Node nd in list)
                {
                    NodeDto nodeDto = new NodeDto(nd.Id, nd.NodeName, nd.NodeTypeId, nd.ActiveLoadId, nd.ReactiveLoadId, nd.VoltageId);
                    listDto.Add(nodeDto);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
            //returns list of all node details as list of dtoes.
            return listDto;
        }
Пример #7
0
        /// <summary>
        /// Update node in database
        /// </summary>
        /// <param name="dto">dto of node</param>
        public void UpdateNode(NodeDto 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.Nodes);

                //Find node which have to be updated.
                Node existingNode = dbContext.Nodes.Single(nd => nd.Id == dto.Id);

                //If required node doesn't exists, throw exception.
                if (existingNode == null)
                {
                    throw new Exception("Node does not exist");
                }
                //else prepare all data for storing to database
                else
                {
                    existingNode.Id = dto.Id;
                    existingNode.NodeName = dto.NodeName;
                    existingNode.NodeTypeId = dto.NodeTypeId;
                    existingNode.ActiveLoadId = dto.ActiveLoadId;
                    existingNode.ReactiveLoadId = dto.ReactiveLoadId;
                    existingNode.VoltageId = dto.VoltageId;
                }

                //Save changes
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
Пример #8
0
        /// <summary>
        /// Insert specified node in database
        /// </summary>
        /// <param name="dto">dto data for node</param>
        public void InsertNode(NodeDto 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.Nodes);
                Node nd = new Node();

                nd.Id = dto.Id;
                nd.NodeName = dto.NodeName;
                nd.NodeTypeId = dto.NodeTypeId;
                nd.ActiveLoadId = dto.ActiveLoadId;
                nd.ReactiveLoadId = dto.ReactiveLoadId;
                nd.VoltageId = dto.VoltageId;

                //Adds new node details to context
                dbContext.Nodes.AddObject(nd);

                //saves changes.
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
Пример #9
0
 public void NodeDtoConstructorTest1()
 {
     NodeDto target = new NodeDto();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Пример #10
0
 public void NodeNameTest()
 {
     NodeDto target = new NodeDto(); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.NodeName = expected;
     actual = target.NodeName;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }