Beispiel #1
0
        public async Task <SingleTimesheetDto> UpdateTimesheet(int id, TimesheetCreateInputDto timesheetCreateInputDto)
        {
            var result = new SingleTimesheetDto();

            try
            {
                var timesheet = _context.Timesheet.Where(x => x.Id == id).FirstOrDefault();

                if (timesheet == null)
                {
                    throw new Exception();
                }

                timesheet.Date         = timesheetCreateInputDto.Date;
                timesheet.HoursWorked  = timesheetCreateInputDto.HoursWorked;
                timesheet.DateReported = timesheetCreateInputDto.DateReported;
                timesheet.ResourceId   = timesheetCreateInputDto.ResourceId;

                await _context.SaveChangesAsync();

                result = new SingleTimesheetDto()
                {
                    Id           = timesheet.Id,
                    Date         = timesheetCreateInputDto.Date,
                    HoursWorked  = timesheetCreateInputDto.HoursWorked,
                    DateReported = timesheetCreateInputDto.DateReported,
                    ResourceId   = timesheetCreateInputDto.ResourceId,
                };
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public async Task <SingleTimesheetDto> InsertTimesheet(TimesheetCreateInputDto timesheetCreateInputDto)
        {
            var result = new SingleTimesheetDto();

            try
            {
                var timesheet = new Timesheet()
                {
                    Date         = timesheetCreateInputDto.Date,
                    HoursWorked  = timesheetCreateInputDto.HoursWorked,
                    DateReported = timesheetCreateInputDto.DateReported,
                    ResourceId   = timesheetCreateInputDto.ResourceId,
                };
                _context.Timesheet.Add(timesheet);
                await _context.SaveChangesAsync();

                result = new SingleTimesheetDto()
                {
                    Id           = timesheet.Id,
                    Date         = timesheetCreateInputDto.Date,
                    HoursWorked  = timesheetCreateInputDto.HoursWorked,
                    DateReported = timesheetCreateInputDto.DateReported,
                    ResourceId   = timesheetCreateInputDto.ResourceId,
                };

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public async Task <ActionResult <SingleTimesheetDto> > UpdatetTimesheet(int id, TimesheetCreateInputDto timesheetInput)
        {
            var timesheetResult = await _timesheetRepository.UpdateTimesheet(id, timesheetInput);

            return(timesheetResult);
        }
Beispiel #4
0
        public async Task <ActionResult <SingleTimesheetDto> > InsertTimesheet(TimesheetCreateInputDto timesheetInput)
        {
            var timesheetResult = await _timesheetRepository.InsertTimesheet(timesheetInput);

            return(timesheetResult);
        }