/// <summary>
        /// Delete specified NodeActiveLoad from database
        /// </summary>
        /// <param name="user">dto NodeActiveLoad</param>
        public void DeleteNodeActiveLoad(NodeActiveLoadDto 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.ActiveLoads);

                //Find NodeActiveLoad which have to be deleted.
                ActiveLoad existingActiveLoad = dbContext.ActiveLoads.Single(al => al.Id == dto.Id);

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

                    //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;
            //Annullment list of dto node active loads which has been returned.
            List<NodeActiveLoadDto> listDto = new List<NodeActiveLoadDto>();
            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.ActiveLoads);

                //list of active loads from entities
                List<ActiveLoad> list = dbContext.ActiveLoads.OrderBy(al => al.Id).ToList();

                //filling the list
                foreach (ActiveLoad al in list)
                {
                    NodeActiveLoadDto nodeActiveLoadDto = new NodeActiveLoadDto(al.Id, al.InitialActiveLoad, al.CurrentActiveLoad, al.MinimalActiveLoad, al.MaximalActiveLoad);
                    nodeActiveLoadDto.CurrentActiveLoad = 0;
                    UpdateNodeActiveLoad(nodeActiveLoadDto);
                    annulmentInfo = annulmentInfo + "\t- Current node active load at id: " + nodeActiveLoadDto.Id + "\t-> Annulled.\r\n";
                }
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
            //returns String which shows initialization details
            return annulmentInfo;
        }
 public void InitialActiveLoadTest()
 {
     NodeActiveLoadDto target = new NodeActiveLoadDto(); // TODO: Initialize to an appropriate value
     double expected = 0F; // TODO: Initialize to an appropriate value
     double actual;
     target.InitialActiveLoad = expected;
     actual = target.InitialActiveLoad;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void NodeActiveLoadDtoConstructorTest1()
 {
     NodeActiveLoadDto target = new NodeActiveLoadDto();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
 public void NodeActiveLoadDtoConstructorTest()
 {
     int id = 0; // TODO: Initialize to an appropriate value
     double initialActiveLoad = 0F; // TODO: Initialize to an appropriate value
     double currentActiveLoad = 0F; // TODO: Initialize to an appropriate value
     double minimalActiveLoad = 0F; // TODO: Initialize to an appropriate value
     double maximalActiveLoad = 0F; // TODO: Initialize to an appropriate value
     NodeActiveLoadDto target = new NodeActiveLoadDto(id, initialActiveLoad, currentActiveLoad, minimalActiveLoad, maximalActiveLoad);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
        /// <summary>
        /// Update NodeActiveLoad in database
        /// </summary>
        /// <param name="dto">dto of NodeActiveLoad</param>
        public void UpdateNodeActiveLoad(NodeActiveLoadDto 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.ActiveLoads);

                //Find NodeActiveLoad which have to be updated.
                ActiveLoad existingActiveLoad = dbContext.ActiveLoads.Single(al => al.Id == dto.Id);

                //If required NodeActiveLoad doesn't exists, throw exception.
                if (existingActiveLoad == null)
                {
                    throw new Exception("Node Active load does not exist");
                }
                //else prepare all data for storing to database
                else
                {
                    existingActiveLoad.Id = dto.Id;
                    existingActiveLoad.InitialActiveLoad = dto.InitialActiveLoad;
                    existingActiveLoad.CurrentActiveLoad = dto.CurrentActiveLoad;
                    existingActiveLoad.MinimalActiveLoad = dto.MinimalActiveLoad;
                    existingActiveLoad.MaximalActiveLoad = dto.MaximalActiveLoad;
                }

                //Save changes
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
        /// <summary>
        /// Insert specified NodeActiveLoad in database
        /// </summary>
        /// <param name="dto">dto data for NodeActiveLoad</param>
        public void InsertNodeActiveLoad(NodeActiveLoadDto 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.ActiveLoads);
                ActiveLoad al = new ActiveLoad();

                al.Id = dto.Id;
                al.InitialActiveLoad = dto.InitialActiveLoad;
                al.CurrentActiveLoad = dto.CurrentActiveLoad;
                al.MinimalActiveLoad = dto.MinimalActiveLoad;
                al.MaximalActiveLoad = dto.MaximalActiveLoad;

                //Adds new NodeActiveLoad details to context
                dbContext.ActiveLoads.AddObject(al);

                //saves changes.
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
        /// <summary>
        /// Returns list of all node active loads from database.
        /// </summary>
        /// <returns>List list of NodeActiveLoadDto's</returns>
        public List<NodeActiveLoadDto> GetAllNodeActiveLoads()
        {
            //Instantiate list of dto node active loads which has been returned.
            List<NodeActiveLoadDto> listDto = new List<NodeActiveLoadDto>();
            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.ActiveLoads);

                //list of active loads from entities
                List<ActiveLoad> list = dbContext.ActiveLoads.OrderBy(al => al.Id).ToList();

                //filling the list
                foreach (ActiveLoad al in list)
                {
                    NodeActiveLoadDto nodeActiveLoadDto = new NodeActiveLoadDto(al.Id, al.InitialActiveLoad, al.CurrentActiveLoad, al.MinimalActiveLoad, al.MaximalActiveLoad);
                    listDto.Add(nodeActiveLoadDto);
                }
            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
            //returns list of all node active loads as list of dtoes.
            return listDto;
        }