Esempio n. 1
0
 /// <summary>
 /// Constructor with edit report window opening
 /// </summary>
 /// <param name="addReportOpen">opens the add report window</param>
 /// <param name="reportEdit">gets the report info that is being edited</param>
 public AddReportViewModel(AddReport addReportOpen, vwUserReport reportEdit)
 {
     report           = reportEdit;
     addReport        = addReportOpen;
     ReportList       = service.GetAllReports().ToList();
     WorkerReportList = service.GetAllWorkerReports(Service.LoggedInUser[0].UserID).ToList();
 }
 /// <summary>
 /// Constructor with edit report window opening
 /// </summary>
 /// <param name="addReportOpen">opens the add report window</param>
 /// <param name="reportEdit">gets the report info that is being edited</param>
 public AddReportViewModel(AddReport addReportOpen, vwUserReport reportEdit)
 {
     report           = reportEdit;
     addReport        = addReportOpen;
     ReportList       = service.GetAllReports().ToList();
     WorkerReportList = service.GetAllWorkerReports(LoggedUser.CurrentUser.UserID).ToList();
 }
        /// <summary>
        /// Creates or edits a report
        /// </summary>
        /// <param name="report">the report that is being added</param>
        /// <returns>a new or edited report</returns>
        public vwUserReport AddReport(vwUserReport report)
        {
            InputCalculator iv = new InputCalculator();

            try
            {
                using (ReportDBEntities context = new ReportDBEntities())
                {
                    if (report.ReportID == 0)
                    {
                        tblReport newReport = new tblReport
                        {
                            Project     = report.Project,
                            ReportDate  = report.ReportDate,
                            ReportHours = report.ReportHours,
                            UserID      = Service.LoggedInUser[0].UserID
                        };

                        context.tblReports.Add(newReport);
                        context.SaveChanges();
                        report.ReportID = newReport.ReportID;
                        return(report);
                    }
                    else
                    {
                        tblReport reportToEdit = (from ss in context.tblReports where ss.ReportID == report.ReportID select ss).First();

                        reportToEdit.Project     = report.Project;
                        reportToEdit.ReportDate  = report.ReportDate;
                        reportToEdit.ReportHours = report.ReportHours;
                        reportToEdit.UserID      = report.UserID;

                        reportToEdit.ReportID = report.ReportID;

                        tblReport reportEdit = (from ss in context.tblReports
                                                where ss.ReportID == report.ReportID
                                                select ss).First();
                        context.SaveChanges();
                        return(report);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
 /// <summary>
 /// This method searches for the selected Report
 /// </summary>
 /// <returns>the found report</returns>
 private vwUserReport UserReport()
 {
     try
     {
         using (ReportDBEntities db = new ReportDBEntities())
         {
             vwUserReport user = new vwUserReport();
             user = db.vwUserReports.Where(x => x.ReportID == Report.ReportID).First();
             return(user);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
         return(null);
     }
 }
 /// <summary>
 /// Window constructor for editing report
 /// </summary>
 /// <param name="reportEdit">report that is bing edited</param>
 public AddReport(vwUserReport reportEdit)
 {
     InitializeComponent();
     this.DataContext = new AddReportViewModel(this, reportEdit);
 }