public IHttpActionResult Approval(TimeSheetApproval TimeSheetApproval)
        {
            var timesheetStatus = (int)TimeSheetStatus.Approve;

            if (TimeSheetApproval.Comment == null)
            {
                return(Json(false));
            }

            if (string.IsNullOrEmpty(Convert.ToString(TimeSheetApproval.TimeSheetMasterID)))
            {
                return(Json(false));
            }

            _ITimeSheetRepository.UpdateTimeSheetStatus(TimeSheetApproval, 2); //Approve

            if (_ITimeSheetRepository.IsTimesheetALreadyProcessed(TimeSheetApproval.TimeSheetMasterID))
            {
                _ITimeSheetRepository.UpdateTimeSheetAuditStatus(TimeSheetApproval.TimeSheetMasterID, TimeSheetApproval.Comment, timesheetStatus);
            }
            else
            {
                _ITimeSheetRepository.InsertTimeSheetAuditLog(InsertTimeSheetAudit(TimeSheetApproval, timesheetStatus));
            }
            return(Ok());
        }
Example #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());
            }
        }
        public bool UpdateTimeSheetStatus(TimeSheetApproval timesheetapprovalmodel, int Status)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TimesheetDBEntities"].ToString()))
            {
                con.Open();
                SqlTransaction sql = con.BeginTransaction();

                try
                {
                    var param = new DynamicParameters();
                    param.Add("@TimeSheetMasterID", timesheetapprovalmodel.TimeSheetMasterID);
                    param.Add("@Comment", timesheetapprovalmodel.Comment);
                    param.Add("@TimeSheetStatus", Status);
                    var result = con.Execute("Usp_UpdateTimeSheetStatus", param, sql, 0, System.Data.CommandType.StoredProcedure);
                    if (result > 0)
                    {
                        sql.Commit();
                        return(true);
                    }
                    else
                    {
                        sql.Rollback();
                        return(false);
                    }
                }
                catch (Exception)
                {
                    sql.Rollback();
                    throw;
                }
            }
        }
Example #4
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());
            }
        }
Example #5
0
        public bool ApproveTimeSheet(int idApprover, bool result, string comment)
        {
            if (!CantApproveTimeSheet(idApprover))
            {
                return(false);
            }
            var tsApproval = new TimeSheetApproval
            {
                idTimeSheet  = _timeSheet.id,
                idApprover   = idApprover,
                Result       = result,
                Comment      = comment,
                ApprovalDate = DateTime.Now
            };

            try
            {
                _db.TimeSheetApproval.InsertOnSubmit(tsApproval);
                _db.SubmitChanges();
            }
            catch (System.Exception e)
            {
                return(false);
            }
            _timeSheet = _db.TimeSheetView.SingleOrDefault(f => f.id == _timeSheet.id);
            return(true);
        }
Example #6
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());
            }
        }
Example #7
0
        public async Task <ActionResult> PostTSA(string id, TimeSheetApproval TSA)
        {
            try
            {
                var EmployeeId = await Repo.GetEmployeeIDByEmail(id);

                if (EmployeeId == 0)
                {
                    return(NotFound());
                }
                var TSATest = await Repo.GetTimeSheetApprovalByEmployeeIdAndWeekStart(EmployeeId, TSA.WeekStart);

                if (TSATest != null)
                {
                    return(Conflict());
                }
                TSA.EmployeeId = EmployeeId;
                Repo.CreateTimeSheetApproval(TSA);
                await Repo.Save();

                return(CreatedAtRoute("EmployeeTimeSheetApproval", new { weekstart = TSA.WeekStart }, TSA));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
        public ActionResult Approval(TimeSheetApproval TimeSheetApproval)
        {
            try
            {
                if (TimeSheetApproval.Comment == null)
                {
                    return(Json(false));
                }

                if (string.IsNullOrEmpty(Convert.ToString(TimeSheetApproval.TimeSheetMasterID)))
                {
                    return(Json(false));
                }

                _ITimeSheet.UpdateTimeSheetStatus(TimeSheetApproval, 2); //Approve

                if (_ITimeSheet.IsTimesheetALreadyProcessed(TimeSheetApproval.TimeSheetMasterID))
                {
                    _ITimeSheet.UpdateTimeSheetAuditStatus(TimeSheetApproval.TimeSheetMasterID, TimeSheetApproval.Comment, 2);
                }
                else
                {
                    _ITimeSheet.InsertTimeSheetAuditLog(InsertTimeSheetAudit(TimeSheetApproval, 2));
                }


                return(Json(true));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #9
0
        public void GetNextSaturdayTest(string test, string actual)
        {
            //      var TimeSheetApp = new TimeSheetApproval();
            var testDate = Convert.ToDateTime(test);
            var result   = TimeSheetApproval.GetNextSaturdayOfWeek(testDate);

            Assert.Equal(Convert.ToDateTime(actual), result);
        }
Example #10
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));
        }
Example #11
0
        public void UpdateTimeSheetApproval(TimeSheetApproval TSA)
        {
            var dbTSA = Mapper.Map(TSA);

            dbTSA.Id = TSA.Id;
            _db.TimeSheetApprovals.Attach(dbTSA);
            _db.Entry(dbTSA).Property(x => x.ApprovingManagerId).IsModified = true;
            _db.Entry(dbTSA).Property(x => x.Status).IsModified             = true;
        }
        public async Task <IActionResult> Post(TimeSheetApproval TSA)
        {
            //add check to see if TSA exists and throw 409 (fix)
            Repo.CreateTimeSheetApproval(TSA);
            await Repo.Save();


            TSA.Id = await Repo.GetTimeSheetApprovalIdByDateSubmitted(TSA.TimeSubmitted);

            //describes the route TSA is created at.

            return(CreatedAtRoute("GetTimeSheetApproval", new { id = TSA.Id }, TSA));
        }
 private TimeSheetAuditTB InsertTimeSheetAudit(TimeSheetApproval TimeSheetApproval, int Status)
 {
     try
     {
         TimeSheetAuditTB objAuditTB = new TimeSheetAuditTB();
         objAuditTB.ApprovalTimeSheetLogID = 0;
         objAuditTB.TimeSheetID            = TimeSheetApproval.TimeSheetMasterID;
         objAuditTB.Status        = Status;
         objAuditTB.CreatedOn     = DateTime.Now;
         objAuditTB.Comment       = TimeSheetApproval.Comment;
         objAuditTB.ApprovalUser  = Convert.ToInt32(Session["AdminUser"]);
         objAuditTB.ProcessedDate = DateTime.Now;
         objAuditTB.UserID        = _IUsers.GetUserIDbyTimesheetID(TimeSheetApproval.TimeSheetMasterID);
         return(objAuditTB);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #14
0
 public bool TimeSheetApproval(int idTimeSheet, DtoApprover employeeLogin, bool result, string comments, string appDominUrl)
 {
     using (var db = new KadrDataContext())
     {
         if (!CanApprove(idTimeSheet, employeeLogin))
         {
             return(false);
         }
         var approvalStep   = GetTimeSheetApproveStep(idTimeSheet);
         var timeSheet      = GetTimeSheet(idTimeSheet, true);
         var idDepartment   = timeSheet.Department.IdDepartment;
         var departmentName = db.Department.First(f => f.id == idDepartment).DepartmentSmallName;
         //var approver = GetCurrentApproverByLogin(employeeLogin)
         //    .GetDepartmentApproverNumbers(idDepartment)
         //    .First(w => w.ApproveNumber == approvalStep + 1);
         var approver = employeeLogin.GetDepartmentApproverNumbers(idDepartment)
                        .First(w => w.ApproveNumber == approvalStep + 1);
         try
         {
             var timeSheetApproval = new TimeSheetApproval
             {
                 ApprovalDate = DateTime.Now,
                 idTimeSheet  = idTimeSheet,
                 idApprover   = approver.IdApprover,
                 Result       = result,
                 Comment      = comments
             };
             db.TimeSheetApproval.InsertOnSubmit(timeSheetApproval);
             db.SubmitChanges();
             Task.Run(
                 () => EmailSending(employeeLogin.EmployeeLogin, idTimeSheet, result, comments, approvalStep, departmentName, appDominUrl));
             return(true);
         }
         catch (System.Exception e)
         {
             var s = e.Message;
             return(false);
         }
     }
 }
Example #15
0
        public async Task Save(TimeApprovalDTO timeApprovalDTO)
        {
            using (var db = _contextFactory.CreateDb())
            {
                var match = await db.TimeSheetApprovals.SingleOrDefaultAsync(x => x.WeekId == timeApprovalDTO.WeekId && x.EmployeeId == timeApprovalDTO.EmployeeId);

                if (match == null)
                {
                    match = new TimeSheetApproval()
                    {
                        EmployeeId = timeApprovalDTO.EmployeeId,
                        WeekId     = timeApprovalDTO.WeekId,
                    };
                    db.TimeSheetApprovals.Add(match);
                }
                var approver = db.Employees.FirstOrDefault(x => x.UserName == timeApprovalDTO.ApproverName)?.EmployeeId ?? 0;
                if (timeApprovalDTO.TimeApprovalStatus == TimeApprovalStatus.Approved)
                {
                    match.ApprovalDate = DateTime.Now;
                    if (match.SubmittedDate == null)
                    {
                        match.SubmittedDate = DateTime.Now;
                    }
                }
                else
                {
                    match.ApprovalDate = null;
                }
                if (timeApprovalDTO.TimeApprovalStatus == TimeApprovalStatus.Submitted)
                {
                    match.SubmittedDate = DateTime.Now;
                }
                match.ApproverEmployeeId = approver;
                match.ResponseReason     = match.ResponseReason ?? "" + timeApprovalDTO.ResponseReason;
                match.TimeApprovalStatus = timeApprovalDTO.TimeApprovalStatus.ToString();
                match.IsHidden           = timeApprovalDTO.IsHidden;
                await db.SaveChangesAsync();
            }
        }
Example #16
0
        public async Task TestingTimesheetRepoMethods()
        {
            var options = new DbContextOptionsBuilder <PhilanskiManagementSolutionsContext>()
                          .UseInMemoryDatabase(databaseName: "TestDB3")
                          .Options;


            TimeSheet timesheet1 = new TimeSheet();

            timesheet1.Date         = DateTime.Now;
            timesheet1.EmployeeId   = 1;
            timesheet1.Id           = 1;
            timesheet1.RegularHours = 40.00m;


            TimeSheet timesheet2 = new TimeSheet();

            timesheet2.Date         = DateTime.Now;
            timesheet2.EmployeeId   = 2;
            timesheet2.Id           = 2;
            timesheet2.RegularHours = 30.00m;



            TimeSheet updatedtimesheet2 = new TimeSheet();

            updatedtimesheet2.Date         = timesheet2.Date;
            updatedtimesheet2.EmployeeId   = 2;
            updatedtimesheet2.Id           = 2;
            updatedtimesheet2.RegularHours = 35.00m;

            TimeSheetApproval TSA = new TimeSheetApproval();

            TSA.WeekEnd          = DateTime.Parse("07/29/2018 14:50:50.42");
            TSA.WeekStart        = DateTime.Parse("07/22/2018 14:50:50.42");
            TSA.WeekTotalRegular = 56.00m;
            TSA.Status           = "0";
            TSA.TimeSubmitted    = DateTime.Now;
            TSA.EmployeeId       = 1;



            // Run the test against one instance of the context
            using (var context = new PhilanskiManagementSolutionsContext(options))
            {
                var repo = new Repository(context);
                repo.CreateTimeSheet(timesheet1);
                await repo.Save();

                repo.CreateTimeSheet(timesheet2);
                await repo.Save();

                repo.CreateTimeSheetApproval(TSA);
                await repo.Save();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new PhilanskiManagementSolutionsContext(options))
            {
                var repo = new Repository(context);

                List <TimeSheet> testtimesheetlist = new List <TimeSheet>();

                //testing get all timesheets
                testtimesheetlist = repo.GetAllTimeSheets();
                Assert.Equal(2, testtimesheetlist.Count());


                //TESTinG Task<int> GetTimeSheetIdByDateAndEmpId(DateTime date, int employeeId);
                int testtimesheetid = await repo.GetTimeSheetIdByDateAndEmpId(timesheet1.Date, 1);

                Assert.Equal(1, testtimesheetid);


                //testing  Task<TimeSheet> GetTimeSheetByID(int id);

                TimeSheet timesheetfromgetbyid = await repo.GetTimeSheetByID(1);

                Assert.Equal(timesheetfromgetbyid.Date, timesheet1.Date);


                // testing  List<TimeSheet> GetTimeSheetsByEmployeeId(int employeeId);

                List <TimeSheet> emp2timesheets = repo.GetTimeSheetsByEmployeeId(2);
                Assert.Single(emp2timesheets);

                //testing List<TimeSheet> GetEmployeeTimeSheetWeekFromDate(DateTime date, int employeeId);

                List <TimeSheet> timesheetsbydate = repo.GetEmployeeTimeSheetWeekFromDate(timesheet2.Date, 2);
                Assert.Single(timesheetsbydate);

                //testing void UpdateTimeSheet(TimeSheet timesheet);

                repo.UpdateTimeSheet(updatedtimesheet2);

                TimeSheet testingifitupdated = await repo.GetTimeSheetByID(2);

                Assert.Equal(35.00m, testingifitupdated.RegularHours);

                var TSAs = repo.GetAllTimeSheetApprovals();
                Assert.Single(TSAs);

                TSAs = repo.GetAllTimeSheetsFromEmployee(TSA.EmployeeId);
                Assert.Single(TSAs);

                var TSAtest = await repo.GetTimeSheetApprovalById(1);

                Assert.Equal(1, TSAtest.EmployeeId);


                context.Database.EnsureDeleted();
            }
        }
Example #17
0
        public async Task <IEnumerable <TimeApprovalDTO> > GetByStatus(DateTime?beginDateInclusive = null, DateTime?endDateInclusive = null, params TimeApprovalStatus[] withTimeApprovalStatus)
        {
            using (var db = _contextFactory.CreateDb())
            {
                var allEmps = await db.Employees.Where(x => x.EmployeeId != admin_employee_id).ToListAsync();

                var startWeek = beginDateInclusive.HasValue ? WeekDTO.CreateWithWeekContaining(beginDateInclusive.Value).WeekId.Value : WeekDTO.CreateWithWeekContaining(DateTime.Now.AddDays(-7)).WeekId.Value;
                var endWeek   = endDateInclusive.HasValue ? WeekDTO.CreateWithWeekContaining(endDateInclusive.Value).WeekId.Value : WeekDTO.CreateWithWeekContaining(DateTime.Now.AddDays(31)).WeekId.Value;

                if (startWeek > endWeek)
                {
                    endWeek = startWeek;
                }

                var approvals = await SearchForSavedApprovals(db, startWeek, endWeek, withTimeApprovalStatus);

                var approverNames = approvals.Values.Select(x => x.ApproverEmployeeId).Where(x => x.HasValue).Distinct().ToDictionary(x => x.Value, x => allEmps.FirstOrDefault(a => a.EmployeeId == x.Value)?.UserName);



                var weeklyHourTotals = await db.WeeklyData.Where(x => x.WeekId >= startWeek && x.WeekId <= endWeek).ToListAsync();

                var hourTotalsByEmpAndWeek = weeklyHourTotals.ToDictionary(x => (x.EmployeeId, x.WeekId), x => (x.TotalOverTimeHours, x.TotalRegularHours));


                var matches = new List <TimeApprovalDTO>();
                for (int weekid = startWeek; weekid <= endWeek; weekid++)
                {
                    foreach (var emp in allEmps)
                    {
                        if (!approvals.TryGetValue((emp.EmployeeId, weekid), out var x))
                        {
                            x = new TimeSheetApproval()
                            {
                                Employee   = emp,
                                EmployeeId = emp.EmployeeId,
                                IsHidden   = false,
                                WeekId     = weekid
                            };
                        }

                        var temp = new TimeApprovalDTO()
                        {
                            ApprovalDate       = x.ApprovalDate,
                            ApproverName       = approverNames.TryGetValue(x.ApproverEmployeeId ?? 0, out var approverName) ? approverName : null,
                            EmployeeName       = $"{x.Employee.Last}, {x.Employee.First}",
                            EmployeeId         = x.EmployeeId,
                            ResponseReason     = x.ResponseReason,
                            TimeApprovalStatus = string.IsNullOrWhiteSpace(x.TimeApprovalStatus) ? TimeApprovalStatus.Unkown : Enum.Parse <TimeApprovalStatus>(x.TimeApprovalStatus),
                            WeekId             = x.WeekId,
                            WeekStartDate      = WeekDTO.CreateForWeekId(x.WeekId).WeekStart,
                            SubmittedDate      = x.SubmittedDate,
                            TotalOverTimeHours = 0.00m,
                            TotalRegularHours  = 0.00m,
                            IsHidden           = x.IsHidden
                        };

                        if (hourTotalsByEmpAndWeek.TryGetValue((emp.EmployeeId, weekid), out var fromDb))
                        {
                            temp.TotalOverTimeHours = fromDb.TotalOverTimeHours;
                            temp.TotalRegularHours  = fromDb.TotalRegularHours;
                        }
                        matches.Add(temp);
                    }
                }

                return(matches);
            }
        }
Example #18
0
 public void CreateTimeSheetApproval(TimeSheetApproval TSA)
 {
     _db.Add(Mapper.Map(TSA));
 }
Example #19
0
        public async Task <ActionResult> PutEmployeeTSAByWeekStart(string id, string weekstart, int EmployeeId, TimeSheetApproval TSA)
        {
            var EmployeeNumberId = await Repo.GetEmployeeIDByEmail(id);

            if (EmployeeNumberId == 0)
            {
                return(NotFound());
            }
            var ManagerId = await Repo.GetManagerIdByEmployeeId(EmployeeNumberId);

            TSA.ApprovingManagerId = ManagerId;
            Repo.UpdateTimeSheetApproval(TSA);
            await Repo.Save();

            return(NoContent());
        }