public async Task <ActionResult <Logic.Objects.Tag> > PostTag([FromBody, Bind("tagName")] ApiTag tag) { BaseClient requestingClient = await repository.GetBasicClientInformationByEmail(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value); try { Logic.Objects.Tag newLogicTag = new Logic.Objects.Tag() { tagID = Guid.NewGuid(), tagName = tag.tagName }; await repository.CreateTag(newLogicTag); await repository.SaveAsync(); Logic.Objects.Tag createdLogicTag = await repository.GetTagByIDAsync(newLogicTag.tagID); await yuleLogger.logCreatedNewTag(requestingClient, createdLogicTag); return(Ok(createdLogicTag)); } catch (Exception) { await yuleLogger.logError(requestingClient, LoggingConstants.CREATED_NEW_TAG_CATEGORY); return(StatusCode(StatusCodes.Status424FailedDependency)); } }
public async Task <ActionResult <Logic.Objects.Profile> > GetProfileByEmailAsync(string email) { // Gets the claims from the URI and check against the client gotten based on auth claims token BaseClient checkerClient = await repository.GetBasicClientInformationByEmail(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value); Profile logicProfile = await repository.GetProfileByEmailAsync(email); // Log the profile request try { await yuleLogger.logGetProfile(checkerClient, logicProfile); } // If it fails, log the error instead and stop the transaction catch (Exception) { await yuleLogger.logError(checkerClient, LoggingConstants.GET_PROFILE_CATEGORY); return(StatusCode(StatusCodes.Status424FailedDependency)); } if (logicProfile.clientID == checkerClient.clientID) { return(Ok(logicProfile)); } else { await yuleLogger.logError(checkerClient, LoggingConstants.GET_PROFILE_CATEGORY); return(StatusCode(StatusCodes.Status401Unauthorized)); } }
public async Task <ActionResult <List <MessageHistory> > > GetAllHistoriesAsync([Required] Guid subjectID) { BaseClient requestingClient = await repository.GetBasicClientInformationByEmail(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value); BaseClient subjectClient = await repository.GetBasicClientInformationByID(subjectID); if (requestingClient.clientID == subjectID) { try { await yuleLogger.logGetAllHistories(requestingClient); List <MessageHistory> listLogicHistory = await repository.GetAllChatHistories(subjectClient); return(Ok(listLogicHistory)); } catch (Exception) { await yuleLogger.logError(requestingClient, LoggingConstants.GET_ALL_HISTORY_CATEGORY); return(StatusCode(StatusCodes.Status424FailedDependency)); } } else { await yuleLogger.logError(requestingClient, LoggingConstants.GET_ALL_HISTORY_CATEGORY); return(StatusCode(StatusCodes.Status401Unauthorized)); } }
public async Task <ActionResult <Logic.Objects.Response> > PutSurveyResponse(Guid surveyResponseID, Models.Survey_Response_Models.ApiSurveyReponseText model) { Response logicResponse = await repository.GetSurveyResponseByIDAsync(surveyResponseID); BaseClient checkerClient = await repository.GetBasicClientInformationByEmail(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value); if (checkerClient.isAdmin || logicResponse.clientID == checkerClient.clientID) { Response logicSurveyResponse = await repository.GetSurveyResponseByIDAsync(surveyResponseID); string oldResponse = logicResponse.responseText; logicSurveyResponse.responseText = model.responseText; await repository.UpdateSurveyResponseByIDAsync(logicSurveyResponse); // Try to save the changes and log the outcome. try { await yuleLogger.logModifiedAnswer(checkerClient, logicSurveyResponse.surveyQuestion, oldResponse, model.responseText); await repository.SaveAsync(); return(Ok(await repository.GetSurveyResponseByIDAsync(surveyResponseID))); } // If that fails, revert the answer, post the log, and save it to the DB context catch (Exception) { await yuleLogger.logError(checkerClient, LoggingConstants.MODIFIED_ANSWER_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)); }