示例#1
0
        /// <summary>
        /// Take all records from db
        /// </summary>
        /// <param name=""></param>
        public IEnumerable <NumberValueEntity> GetAllRecords()
        {
            List <NumberValueEntity> entitiesList = new List <NumberValueEntity>();

            using (NumberValueContext nvc = new NumberValueContext())
            {
                foreach (NumberValueEntity n in nvc.NumberValue)
                {
                    entitiesList.Add(n);
                }
            }

            return(entitiesList);
        }
示例#2
0
 ///<summary>
 ///Add rows to DataBase
 /// </summary>
 public void AddRecords(IEnumerable <NumberValueEntity> tableStringParam)
 {
     using (NumberValueContext nvc = new NumberValueContext())
     {
         try
         {
             nvc.NumberValue.AddRange(tableStringParam);
             nvc.SaveChanges();
         }catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
     }
 }
示例#3
0
 /// <summary>
 /// Delete rows from DataBase
 /// </summary>
 /// <param name="entitiesToRemove">Entities to remove from table</param>
 public void DeleteRecords(IEnumerable <NumberValueEntity> entitiesToRemove)
 {
     using (NumberValueContext nvc = new NumberValueContext())
     {
         try
         {
             nvc.NumberValue.RemoveRange(entitiesToRemove);
             nvc.SaveChanges();
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
     }
 }
示例#4
0
 /// <summary>
 /// Update records
 /// </summary>
 /// <param name="recordsToUpdate"> Records to update </param>
 public void UpdateRecords(IEnumerable <NumberValueEntity> recordsToUpdate)
 {
     using (NumberValueContext nvc = new NumberValueContext())
     {
         try
         {
             foreach (NumberValueEntity n in recordsToUpdate)
             {
                 nvc.NumberValue.Find(n.NumberId).Value = n.Value;
             }
             nvc.SaveChanges();
         }catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
     }
 }
示例#5
0
 /// <summary>
 /// Delete row from DataBase
 /// </summary>
 /// <param name="idToDelete">Id to remove from table</param>
 public void DeleteRecord(int idToDelete)
 {
     using (NumberValueContext nvc = new NumberValueContext())
     {
         try
         {
             NumberValueEntity nve = nvc.NumberValue.Find(idToDelete);
             if (nve != null)
             {
                 nvc.NumberValue.Remove(nve);
             }
             else
             {
                 throw new Exception($"The row with id {idToDelete} didn't found");
             }
         }catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
     }
 }