コード例 #1
0
 /// <summary>
 /// This method edits reports in DbSet and then saves changes to database.
 /// </summary>
 /// <param name="report">Report to edit.</param>
 /// <returns>Edited report.</returns>
 public vwReport EditReport(vwReport report)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             tblReport reportToEdit = context.tblReports.Where(x => x.ReportID == report.ReportID).FirstOrDefault();
             reportToEdit.Date    = report.Date;
             reportToEdit.Project = report.Project;
             reportToEdit.Hours   = report.Hours;
             context.SaveChanges();
             return(report);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #2
0
 /// <summary>
 /// This method adds report to database.
 /// </summary>
 /// <param name="report">Report to add.</param>
 public void AddReport(vwReport report)
 {
     try
     {
         using (Data_RecordsEntities context = new Data_RecordsEntities())
         {
             tblReport reportToAdd = new tblReport
             {
                 EmployeeID = report.EmployeeID,
                 Date       = report.Date,
                 Project    = report.Project,
                 Hours      = report.Hours
             };
             context.tblReports.Add(reportToAdd);
             context.SaveChanges();
             report.ReportID = reportToAdd.ReportID;
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }