public void Save_Metric(MetricDTO metric_dto)
 {
     try
     {
         _dbcontext.tblMetrics.Add(MetricDTO.Convert_DTO_To_Table(metric_dto));
         _dbcontext.SaveChanges();
     }
     catch (Exception ex) { throw ex; }
 }
 public void Update_Metric(MetricDTO metric_dto)
 {
     try
     {
         tblMetric tbl_Metric = _dbcontext.tblMetrics.Single(metric => metric.Id == metric_dto.Id);
         MetricDTO.Convert_DTO_To_Table(metric_dto, ref tbl_Metric);
         _dbcontext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 /// <summary>
 /// This is use for auto metric geration when the element add in to the structure only for the history point not for the Live point.
 /// </summary>
 /// <param name="tbl_Element"></param>
 public void Save_Metric(IEnumerable <tblElement> tbl_Elements)
 {
     try
     {
         foreach (var tbl_Element in tbl_Elements)
         {
             try
             {
                 //create matric only for the history points
                 if (tbl_Element.Connector_Live_ID == null)
                 {
                     _dbcontext.tblMetrics.Add(MetricDTO.Convert_DTO_To_Table(tbl_Element.ID, tbl_Element.Element_Name, tbl_Element.Unit_ID, Rollup_Function_Option.SUM));
                     _dbcontext.tblMetrics.Add(MetricDTO.Convert_DTO_To_Table(tbl_Element.ID, tbl_Element.Element_Name, tbl_Element.Unit_ID, Rollup_Function_Option.MAX));
                     _dbcontext.tblMetrics.Add(MetricDTO.Convert_DTO_To_Table(tbl_Element.ID, tbl_Element.Element_Name, tbl_Element.Unit_ID, Rollup_Function_Option.MIN));
                     _dbcontext.tblMetrics.Add(MetricDTO.Convert_DTO_To_Table(tbl_Element.ID, tbl_Element.Element_Name, tbl_Element.Unit_ID, Rollup_Function_Option.AVG));
                 }
             }
             catch (Exception ex) { throw ex; }
         }
         _dbcontext.SaveChanges();
     }
     catch (Exception ex) {  }
 }