Exemplo n.º 1
0
        public async Task <IHttpActionResult> PostUnlock([FromBody] UserDateDto userDate)
        {
            try
            {
                var result = await _timesheetService.Unlock(userDate);

                return(this.JsonDataResult(result));
            }
            catch (Exception e)
            {
                //Logger.Log(LogLevel.Error, e);
                return(new InternalServerErrorResult(this));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ChangeBirthDate(int id, [FromBody] UserDateDto dateObject)
        {
            var userId = int.Parse(this.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (userId != id)
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            userFromRepo.DateOfBirth = dateObject.DateOfBirth;

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemplo n.º 3
0
        public async Task <UserDateDto> Unlock(UserDateDto userDate)
        {
            DateTime fromDate = userDate.Date.AddDays(-1);
            DateTime toDate   = userDate.Date.AddDays(6);

            using (var context = new DatabaseContext())
            {
                var tsheet = await(from t in context.TimeSheet
                                   where t.EmployeeId == userDate.EmployeeId &&
                                   t.Date >= fromDate && t.Date <= toDate
                                   select t).ToListAsync();

                foreach (Timesheet sheet in tsheet)
                {
                    sheet.Approved     = false;
                    sheet.ApprovedBy   = userDate.UserId;
                    sheet.ApprovedDate = userDate.Date;
                }
                int z = await(context.SaveChangesAsync());
            }
            return(userDate);
        }
Exemplo n.º 4
0
        public async Task <EmployeeTimesheet> GetTimesheetByUserID(UserDateDto userDate)
        {
            EmployeeTimesheet empSheet = null;
            TimesheetRow      sheetRow = null;
            var      teamId            = 0;
            DateTime fromDate          = userDate.Date.AddDays(-1);
            DateTime toDate            = userDate.Date.AddDays(6);

            using (var context = new DatabaseContext())
            {
                teamId = context.Employee.Where(x => x.BSIPLid == userDate.UserId).Select(x => x.TeamId).FirstOrDefault <int>();
                var taskTeams = await context.TaskTeam.Where(x => x.TeamId == teamId).Include(x => x.Task).ToListAsync <TaskTeam>();

                var taskGroup = (from t in taskTeams
                                 select new EmployeeTask {
                    Id = t.TaskId, Name = t.Task.Name
                }).ToList();

                var tsheet1 = await(context.TimeSheet.Include(x => x.Task).Where(t => t.EmployeeId == userDate.UserId && t.Date >= fromDate && t.Date <= toDate)
                                    .ToListAsync());
                decimal workHours = 0;
                empSheet = new EmployeeTimesheet()
                {
                    EmployeeId    = userDate.UserId,
                    TeamId        = teamId,
                    TimesheetRows = new List <TimesheetRow>()
                };

                //select max data rom tsheets
                DateTime maxdate = new DateTime();
                if (tsheet1.Count > 0)
                {
                    maxdate = tsheet1[0].Date;
                }

                foreach (Timesheet t in tsheet1)
                {
                    if (t.Date > maxdate)
                    {
                        maxdate = t.Date;
                    }
                }

                //Prepare Colmns and Rows
                //Group by TaskIds
                //Loop through Tasks
                int    ctr      = 1;
                string taskName = string.Empty;
                foreach (var task in taskGroup)
                {
                    List <TimesheetColumn> cols = null;
                    //Loop through days
                    //get the actual days with dates
                    cols = new List <TimesheetColumn>();
                    var newDate = new DateTime(userDate.Date.Year, userDate.Date.Month, userDate.Date.Day, 0, 0, 0, DateTimeKind.Utc);
                    while (newDate.Date <= toDate.Date && newDate.Date <= maxdate.Date)
                    {
                        if (newDate.Date >= fromDate.Date)
                        {
                            workHours = (tsheet1 == null || tsheet1.Count == 0) ? 0 : tsheet1.Where(x => DateTime.Compare(x.Date.Date, newDate.Date) == 0 && x.TaskId == task.Id).FirstOrDefault().Hour;
                            var timesheetCol = new TimesheetColumn()
                            {
                                id         = 1,
                                taskId     = task.Id,
                                employeeId = userDate.UserId, //get task name
                                date       = newDate,
                                hours      = workHours
                                             //approved =
                            };
                            cols.Add(timesheetCol);
                            newDate = newDate.AddDays(1);
                        }
                    }

                    taskName = (tsheet1 == null || tsheet1.Count == 0) ? task.Name : tsheet1.Where(x => x.TaskId == task.Id).FirstOrDefault().Task.Name;
                    sheetRow = new TimesheetRow()
                    {
                        id               = ctr,
                        taskId           = task.Id,
                        taskName         = taskName,
                        timesheetColumns = cols,
                        totalHours       = 0
                    };

                    empSheet.TimesheetRows.Add(sheetRow);
                    ctr++;
                }
            }

            return(empSheet);
        }