public GroupHistoryEntry CreateLogAddTime(Group group, NhbkDate date, NhbkDateOffset timeOffset) { return(new GroupHistoryEntry { Group = group, Action = AddTimeActionName, Date = DateTime.Now, Gm = false, Data = _jsonUtil.Serialize(new { timeOffset, date }) }); }
public NhbkDate AddTimeAndNotify(Group group, NhbkDateOffset timeOffset, INotificationSession notificationSession) { var groupData = _jsonUtil.Deserialize <GroupData>(group.Data) ?? new GroupData(); if (groupData.Date == null) { throw new GroupDateNotSetException(); } groupData.Date.Add(timeOffset); group.AddHistoryEntry(_groupHistoryUtil.CreateLogAddTime(group, groupData.Date, timeOffset)); notificationSession.NotifyGroupChangeGroupData(group.Id, groupData); group.Data = _jsonUtil.Serialize(groupData); return(groupData.Date); }
public async Task <ActionResult <NhbkDate> > PostAddTimeAsync( [FromServices] NaheulbookExecutionContext executionContext, [FromRoute] int groupId, NhbkDateOffset request ) { try { return(await _groupService.AddTimeAsync(executionContext, groupId, request)); } catch (GroupDateNotSetException ex) { throw new HttpErrorException(StatusCodes.Status400BadRequest, ex); } catch (ForbiddenAccessException ex) { throw new HttpErrorException(StatusCodes.Status403Forbidden, ex); } catch (GroupNotFoundException ex) { throw new HttpErrorException(StatusCodes.Status404NotFound, ex); } }
public async Task <NhbkDate> AddTimeAsync(NaheulbookExecutionContext executionContext, int groupId, NhbkDateOffset request) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var group = await uow.Groups.GetAsync(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); var notificationSession = _notificationSessionFactory.CreateSession(); var newDate = _groupUtil.AddTimeAndNotify(group, request, notificationSession); await uow.SaveChangesAsync(); await notificationSession.CommitAsync(); return(newDate); } }