Exemplo n.º 1
0
        private TimesheetDto TimesheetToDto(Timesheet ts)
        {
            TimesheetDto tsdto = new TimesheetDto();

            tsdto.DateCreated  = ts.DateCreated;
            tsdto.Id           = ts.Id;
            tsdto.Owner        = ts.Owner;
            tsdto.Role         = ts.Role;
            tsdto.Username     = ts.Username;
            tsdto.WeekStarting = ts.WeekStarting;
            tsdto.Status       = ts.Status.ToString();

            tsdto.TimesheetEntries = new List <TimesheetEntryDto>();
            foreach (TimesheetEntry tse in ts.TimesheetEntries)
            {
                TimesheetEntryDto tsedto = new TimesheetEntryDto();
                tsedto.DateCreated = tse.DateCreated;
                tsedto.Day         = tse.Day;
                tsedto.Details     = tse.Details;
                tsedto.EndTime     = tse.EndTime;
                tsedto.Id          = tse.Id;
                tsedto.Code        = tse.Code;
                tsedto.StartTime   = tse.StartTime;
                tsedto.Username    = tse.Timesheet.Username;
                tsedto.Chargeable  = tse.Chargeable;

                tsdto.TimesheetEntries.Add(tsedto);
            }

            return(tsdto);
        }
Exemplo n.º 2
0
        public IActionResult Create([FromBody] TimesheetDto timesheetDto)
        {
            // map dto to entity
            var timesheet = _mapper.Map <Timesheet>(timesheetDto);

            try
            {
                // save
                _timesheetService.Create(timesheet);
                return(Ok(timesheet.IdTimesheet));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemplo n.º 3
0
        private TimesheetDto ConvertToDto(Timesheet ts)
        {
            TimesheetDto tsdto = new TimesheetDto();

            tsdto.DateCreated  = ts.DateCreated;
            tsdto.Id           = ts.Id;
            tsdto.Owner        = ts.Owner;
            tsdto.Role         = ts.Role;
            tsdto.Username     = ts.Username;
            tsdto.WeekStarting = ts.WeekStarting;
            tsdto.Status       = ts.Status.ToString();
            if (ts.DateSubmitted.HasValue)
            {
                tsdto.DateSubmitted = ts.DateSubmitted.Value;
            }


            tsdto.TimesheetEntries = new List <TimesheetEntryDto>();
            tsdto.TimesheetNotes   = new List <TimesheetNoteDto>();

            foreach (TimesheetEntry tse in ts.TimesheetEntries)
            {
                TimesheetEntryDto tsedto = new TimesheetEntryDto();
                tsedto.DateCreated = tse.DateCreated;
                tsedto.Day         = tse.Day;
                tsedto.Details     = tse.Details;
                tsedto.EndTime     = tse.EndTime;
                tsedto.Id          = tse.Id;
                tsedto.Code        = tse.Code;
                tsedto.StartTime   = tse.StartTime;
                tsedto.Username    = tse.Timesheet.Username;
                tsedto.Chargeable  = tse.Chargeable;

                tsdto.TimesheetEntries.Add(tsedto);
            }

            foreach (TimesheetNote note in ts.TimesheetNotes)
            {
                tsdto.TimesheetNotes.Add(_mapper.Map <TimesheetNoteDto>(note));
            }

            return(tsdto);
        }
        public async Task <Timesheet> AddTimesheet(TimesheetDto timesheet)
        {
            using (var context = ContextFactory.CreateDbContext(ConnectionString))
            {
                var ts = new Timesheet
                {
                    ActivityTypeId = timesheet.ActivityTypeId,
                    Date           = timesheet.Date,
                    WorkItemId     = timesheet.WorkItemId,
                    Duration       = timesheet.Duration,
                    UserUniqueName = timesheet.UserUniqueName,
                    Comment        = timesheet.Comment
                };

                context.Timesheet.Add(ts);
                context.SaveChanges();

                return(ts);
            }
        }
Exemplo n.º 5
0
        public IActionResult Put(int id, [FromBody] TimesheetDto ts)
        {
            Timesheet timesheet = _timeSheetRepository.GetTimsheetById(ts.Id);

            if (ts.Status.Equals(TimesheetStatus.Approved.ToString()))
            {
                _logger.LogWarning($"About to approve timesheet for id: {ts.Id}");
                timesheet.Approved(_mediator);
            }
            else if (ts.Status.Equals(TimesheetStatus.Rejected.ToString()))
            {
                _logger.LogWarning($"About to reject timesheet for id: {ts.Id}");
                timesheet.Rejected(_mediator);
            }
            else if (ts.Status.Equals(TimesheetStatus.Submitted.ToString()))
            {
                _logger.LogWarning($"Timesheet Submitted for id: {ts.Id}");
                timesheet.Submitted(_mediator);
            }

            _timeSheetRepository.UpdateTimesheet(timesheet);

            return(Ok());
        }
 public async Task <ActionResult <Timesheet> > PostTimesheet([FromBody] TimesheetDto timesheet)
 {
     return(await _timesheetRepository.AddTimesheet(timesheet));
 }