Ejemplo n.º 1
0
        public static string AddReport(vwReport report)
        {
            try
            {
                using (DataRecordsEntities1 context = new DataRecordsEntities1())
                {
                    if (report.reportId == 0)
                    {
                        int result = (from x in context.tblReports where x.employeeId == report.employeeId && x.reportDate == report.reportDate select x).Count();
                        if (result < 2)
                        {
                            int hours = 0;
                            if (result == 1)
                            {
                                hours = (from x in context.tblReports where x.employeeId == report.employeeId && x.reportDate == report.reportDate select x.workingHours).FirstOrDefault();
                            }

                            if (hours + report.workingHours <= 12)
                            {
                                tblReport newReport = new tblReport();
                                newReport.employeeId   = report.employeeId;
                                newReport.reportDate   = report.reportDate;
                                newReport.project      = report.project;
                                newReport.workingHours = report.workingHours;
                                context.tblReports.Add(newReport);
                                context.SaveChanges();
                                return(null);
                            }
                        }
                    }
                    else
                    {
                        tblReport reportToEdit = (from x in context.tblReports where x.reportId == report.reportId select x).FirstOrDefault();
                        reportToEdit.reportDate   = report.reportDate;
                        reportToEdit.project      = report.project;
                        reportToEdit.workingHours = report.workingHours;
                        int r = (from x in context.tblReports where x.employeeId == report.employeeId && x.reportDate == report.reportDate && x.reportId != report.reportId select x.workingHours).FirstOrDefault();
                        if (r == 0 && reportToEdit.workingHours <= 12)
                        {
                            context.SaveChanges();
                            return(null);
                        }
                        else if (r + reportToEdit.workingHours <= 12)
                        {
                            context.SaveChanges();
                        }
                        else
                        {
                            return("Too many working hours");
                        }
                    }
                }
                return("Too many working hours");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
                return("Invalid report");
            }
        }
Ejemplo n.º 2
0
 public static void DeleteReport(vwReport report)
 {
     try
     {
         using (DataRecordsEntities1 context = new DataRecordsEntities1())
         {
             tblReport reportToDelete = (from u in context.tblReports where u.reportId == report.reportId select u).First();
             context.tblReports.Remove(reportToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }