public async Task <GroupCreation> AttachFile(int groupId, int userId, GroupCreation groupCreation) { GroupUserEntity userGroup = await DbContext.GroupsUsersRepo.GetByUserIdAndGroupId(userId, groupId); if (userGroup == null) { ThrowHttpResponseException(System.Net.HttpStatusCode.Unauthorized, "Access is denied."); } ValidateUserAsAuthenticated(userGroup.UserId); CreationEntity creation = await DbContext.CreationsRepo.GetSingleOrDefaultAsync(groupCreation.CreationId); if (creation == null) { ThrowHttpResponseException(System.Net.HttpStatusCode.NotFound, string.Format("Creation with id {0} not found.", groupCreation.CreationId)); } GroupCreationEntity groupCreationEntity = await DbContext.GroupCreationsRepo.CreateAsync( new GroupCreationEntity() { CreationId = creation.Id, GroupId = groupCreation.GroupId, }).ConfigureAwait(false); return(groupCreationEntity.ToContract()); }
public static GroupCreation ToContract(this GroupCreationEntity groupCreationEntity) { return(new GroupCreation { Id = groupCreationEntity.Id, CreationId = groupCreationEntity.CreationId, GroupId = groupCreationEntity.GroupId }); }