Пример #1
0
        public async Task <TimeLogModel> CreateTimeLog(TimeLogModel timeLog)
        {
            try
            {
                var timeLogEntity = _timeLogMapper.Map(timeLog);

                await _context.TimeLogs.AddAsync(timeLogEntity);

                await _context.SaveChangesAsync();

                return(timeLog);
            }
            catch (Exception exception)
            {
                throw new CouldNotSaveException("Can't create new TimeLog.'", exception.Message);
            }
        }
Пример #2
0
        public async Task <TimeLogModel> UpdateTimeLog(TimeLogModel timeLog)
        {
            var entityToUpdate = await _context.TimeLogs
                                 .FirstOrDefaultAsync(x => x.Id == timeLog.Id);

            if (entityToUpdate == null)
            {
                throw new NoSuchEntityException("The entity does not exist");
            }

            entityToUpdate.ProjectId   = timeLog.ProjectId;
            entityToUpdate.Description = timeLog.Description;
            entityToUpdate.Logs        = timeLog.Logs;
            entityToUpdate.Date        = timeLog.Date;
            entityToUpdate.Duration    = timeLog.Duration;

            _context.TimeLogs.Update(entityToUpdate);
            await _context.SaveChangesAsync();

            return(timeLog);
        }
Пример #3
0
        public List <ITimeLogModel> GetUserSpentTime(Guid dayAssignId, IEnumerable <Guid> assignedMemberIds)
        {
            List <ITimeLogModel>       result               = new List <ITimeLogModel>();
            IEnumerable <JobStatusLog> jobStatusLogList     = jobStatusLogRepository.Query.Where(js => js.DayAssignId == dayAssignId);
            IEnumerable <TimeLog>      allSpentTimeForUsers = jobStatusLogList.SelectMany(js => js.TimeLogList).ToList();

            foreach (var assignedMemberId in assignedMemberIds)
            {
                TimeLogModel resultTimeModel = new TimeLogModel();
                resultTimeModel.MemberId = assignedMemberId;


                var allSpentUserTimeList = allSpentTimeForUsers.Where(userTime => userTime.MemberId == assignedMemberId);

                foreach (var userTime in allSpentUserTimeList)
                {
                    resultTimeModel.SpentTime += userTime.SpentTime;
                }

                result.Add(resultTimeModel);
            }

            return(result);
        }
Пример #4
0
        public async Task <ActionResult> UpdateTimeLog([FromBody] TimeLogModel timeLog)
        {
            var result = await _timeLogService.UpdateTimeLog(timeLog);

            return(Ok(result));
        }