Beispiel #1
0
        public async Task <ActionResult <List <TimeSheet> > > GetFullWeek(string id, string weekstart)
        {
            if (User.Identity.Name != id)
            {
                return(StatusCode(401));
            }
            var EmployeeId = await Repo.GetEmployeeIDByEmail(id);

            if (EmployeeId == 0)
            {
                return(NotFound());
            }
            try
            {
                DateTime         WeekStartDt     = DateTime.ParseExact(weekstart, "dd-MM-yyyy", null);
                var              actualWeekStart = TimeSheetApproval.GetPreviousSundayOfWeek(WeekStartDt);
                List <TimeSheet> TimeSheets      = Repo.GetEmployeeTimeSheetWeekFromDate(actualWeekStart, EmployeeId);
                //catch null and send 404
                //if (!TimeSheets.Any())
                //{
                //    return NotFound();
                //}
                return(TimeSheets);
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Beispiel #2
0
        public async Task <ActionResult <TimeSheetApproval> > GetTimeSheetApprovalByWeekStart(string id, string weekstart)
        {
            var EmployeeId = await Repo.GetEmployeeIDByEmail(id);

            if (EmployeeId == 0)
            {
                return(NotFound());
            }
            try
            {
                DateTime DateWeekStart = DateTime.ParseExact(weekstart, "dd-MM-yyyy", null);

                //YALL FORGOT THIS PART AS IN ABOVE - Phil
                var actualWeekStart = TimeSheetApproval.GetPreviousSundayOfWeek(DateWeekStart);

                var TSA = await Repo.GetTimeSheetApprovalByEmployeeIdAndWeekStart(EmployeeId, actualWeekStart.Date);

                //we need to send something back to front end to represent they dont have one for that week
                return(TSA);
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Beispiel #3
0
        public async Task <ActionResult> PostFullWeek(string id, List <TimeSheet> timeSheets)
        {
            try
            {
                var EmployeeId = await Repo.GetEmployeeIDByEmail(id);

                if (EmployeeId == 0)
                {
                    return(NotFound());
                }
                // var actualWeekStart = TimeSheetApproval.GetPreviousSundayOfWeek(weekstart);
                foreach (var timesheet in timeSheets)
                {
                    timesheet.EmployeeId = EmployeeId;
                    Repo.CreateTimeSheet(timesheet);
                }
                await Repo.Save();

                var weekStart = TimeSheetApproval.GetPreviousSundayOfWeek(timeSheets.ElementAt(0).Date).ToString("dd-MM-yyyy");
                return(CreatedAtRoute("EmployeeTimesheets", new { weekstart = weekStart }, timeSheets));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Beispiel #4
0
        public void GetPreviousSundayTest(string test, string actual)
        {
            // var TimeSheetApp = new TimeSheetApproval();
            var testDate = Convert.ToDateTime(test);
            var result   = TimeSheetApproval.GetPreviousSundayOfWeek(testDate);

            Assert.Equal(Convert.ToDateTime(actual), result);
        }
Beispiel #5
0
        public List <TimeSheet> GetEmployeeTimeSheetWeekFromDate(DateTime date, int employeeId)
        {
            //use date.date to get midnight
            var DateStart  = TimeSheetApproval.GetPreviousSundayOfWeek(date.Date);
            var DateEnd    = TimeSheetApproval.GetNextSaturdayOfWeek(date.Date);
            var TimeSheets = _db.TimeSheets.Where(x => ((x.EmployeeId == employeeId) && (x.Date.CompareTo(DateStart) >= 0) && (x.Date.CompareTo(DateEnd) <= 0))).AsNoTracking();

            return(Mapper.Map(TimeSheets));
        }