public async Task <ActionResult <Logic.Objects.Message> > PutReadAll([FromBody] ApiReadAllMessageModel messages)
        {
            Logic.Objects.Client checkerClient = await repository.GetClientByEmailAsync(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value);

            foreach (Guid messageID in messages.messages)
            {
                Logic.Objects.Message targetMessage = await repository.GetMessageByIDAsync(messageID);

                if (checkerClient.isAdmin || targetMessage.recieverClient.clientId == checkerClient.clientID)
                {
                    targetMessage.isMessageRead = true;
                    await repository.UpdateMessageByIDAsync(targetMessage);
                }
                else
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized));
                }
            }

            await repository.SaveAsync();

            return(Ok());
        }
        public async Task <ActionResult <Logic.Objects.Message> > PutReadStatus(Guid chatMessageID, [FromBody] ApiMessageReadModel message)
        {
            Logic.Objects.Message logicMessage = await repository.GetMessageByIDAsync(chatMessageID);

            BaseClient checkerClient = await repository.GetBasicClientInformationByEmail(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value);

            if (checkerClient.isAdmin || logicMessage.recieverClient.clientId == checkerClient.clientID)
            {
                try
                {
                    Logic.Objects.Message targetMessage = await repository.GetMessageByIDAsync(chatMessageID);

                    targetMessage.isMessageRead = message.isMessageRead;

                    await repository.UpdateMessageByIDAsync(targetMessage);

                    await repository.SaveAsync();

                    Logic.Objects.Message modifiedLogicMessage = await repository.GetMessageByIDAsync(chatMessageID);

                    await yuleLogger.logModifiedMessageReadStatus(checkerClient, modifiedLogicMessage);

                    return(Ok(modifiedLogicMessage));
                }
                catch (Exception)
                {
                    await yuleLogger.logError(checkerClient, LoggingConstants.MODIFIED_MESSAGE_READ_STATUS_CATEGORY);

                    return(StatusCode(StatusCodes.Status424FailedDependency));
                }
            }
            else
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }
        }
        public async Task <ActionResult <Logic.Objects.Message> > PostMessage([FromBody] ApiMessageModel message)
        {
            BaseClient logicBaseClient = await repository.GetBasicClientInformationByID(message.messageSenderClientID.GetValueOrDefault() != Guid.Empty?message.messageSenderClientID.GetValueOrDefault() : message.messageRecieverClientID.GetValueOrDefault());

            BaseClient checkerClient = await repository.GetBasicClientInformationByEmail(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value);

            List <RelationshipMeta> checkerAssignmentInfo = new List <RelationshipMeta>();

            // If the checker is an admin, there is no need to get the checker's info container as that is
            // only used to authorize the caller
            if (!checkerClient.isAdmin)
            {
                checkerAssignmentInfo = await repository.getClientAssignmentsInfoByIDAsync(checkerClient.clientID);
            }


            // If the logic client and checker client have the same Id
            if (logicBaseClient.clientID == checkerClient.clientID)
            {
                // If the message xref is not null, check to make sure the checkerAssignmentInfo has an assignment that matches (Or pass true if null, which implies posting to a general chat
                // Or bypass if they are an admin
                if ((message.clientRelationXrefID != null ? checkerAssignmentInfo.Any(a => a.clientRelationXrefID == message.clientRelationXrefID) : true) || checkerClient.isAdmin)
                {
                    TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

                    Logic.Objects.Message logicMessage = new Logic.Objects.Message()
                    {
                        chatMessageID  = Guid.NewGuid(),
                        recieverClient = new ClientChatMeta()
                        {
                            clientId = message.messageRecieverClientID
                        },
                        senderClient = new ClientChatMeta()
                        {
                            clientId = message.messageSenderClientID
                        },
                        clientRelationXrefID = message.clientRelationXrefID,
                        messageContent       = message.messageContent,
                        dateTimeSent         = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, easternZone),
                        isMessageRead        = false,
                        fromAdmin            = message.fromAdmin
                    };
                    if (logicMessage.recieverClient.clientId == null && logicMessage.senderClient.clientId == null)
                    {
                        return(StatusCode(StatusCodes.Status400BadRequest));
                    }
                    else
                    {
                        try
                        {
                            await repository.CreateMessage(logicMessage);

                            await repository.SaveAsync();

                            Logic.Objects.Message postedLogicMessage = await repository.GetMessageByIDAsync(logicMessage.chatMessageID);

                            await yuleLogger.logCreatedNewMessage(checkerClient, postedLogicMessage.senderClient, postedLogicMessage.recieverClient);

                            // If this message has an eventTypeID
                            if (message.eventTypeID.HasValue)
                            {
                                // If the message is from an admin, get the event for the notification, and send the email
                                if (message.fromAdmin)
                                {
                                    Logic.Objects.Event logicEvent = await repository.GetEventByIDAsync(message.eventTypeID.Value);

                                    await mailbag.sendChatNotificationEmail(await repository.GetClientByIDAsync(logicMessage.recieverClient.clientId.Value), logicEvent);
                                }
                            }
                            // Else if it doesnt have an event (It is a general message)
                            else
                            {
                                // If it's from an admin, make a new event object, and send the client a notification
                                if (message.fromAdmin)
                                {
                                    Logic.Objects.Event logicEvent = new Logic.Objects.Event();
                                    await mailbag.sendChatNotificationEmail(await repository.GetClientByIDAsync(logicMessage.recieverClient.clientId.Value), new Logic.Objects.Event());
                                }
                            }
                            return(Ok());
                        }
                        catch (Exception)
                        {
                            await yuleLogger.logError(checkerClient, LoggingConstants.CREATED_NEW_MESSAGE_CATEGORY);

                            return(StatusCode(StatusCodes.Status424FailedDependency));
                        }
                    }
                }
            }
            return(StatusCode(StatusCodes.Status401Unauthorized));
        }