Ejemplo n.º 1
0
        public async Task <ActionResult <Logic.Objects.Event> > PutDescription(Guid eventID, [FromBody] ApiEventActive active)
        {
            try
            {
                Logic.Objects.Event targetEvent = await repository.GetEventByIDAsync(eventID);

                targetEvent.active = active.eventIsActive;
                try
                {
                    await repository.UpdateEventByIDAsync(targetEvent);

                    await repository.SaveAsync();

                    return(Ok(await repository.GetEventByIDAsync(eventID)));
                }
                catch (Exception e)
                {
                    throw e.InnerException;
                }
            }

            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Logic.Objects.Event> > Post([FromBody] ApiEvent newEvent)
        {
            try
            {
                Logic.Objects.Event logicEvent = new Logic.Objects.Event()
                {
                    eventTypeID      = Guid.NewGuid(),
                    eventDescription = newEvent.eventDescription,
                    active           = newEvent.isActive
                };
                try
                {
                    await repository.CreateEventAsync(logicEvent);

                    await repository.SaveAsync();

                    return(Ok(await repository.GetEventByIDAsync(logicEvent.eventTypeID)));
                }
                catch (Exception e)
                {
                    throw e.InnerException;
                }
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
 public async Task <Logic.Objects.Event> GetEventByNameAsync(string eventName)
 {
     Logic.Objects.Event logicEvent = Mapper.MapEvent(await santaContext.EventTypes
                                                      .Include(e => e.Surveys)
                                                      .Include(e => e.ClientRelationXrefs)
                                                      .FirstOrDefaultAsync(e => e.EventDescription == eventName));
     return(logicEvent);
 }
 public async Task <Logic.Objects.Event> GetEventByIDAsync(Guid eventID)
 {
     Logic.Objects.Event logicEvent = Mapper.MapEvent(await santaContext.EventTypes
                                                      .Include(e => e.ClientRelationXrefs)
                                                      .Include(e => e.Surveys)
                                                      .FirstOrDefaultAsync(e => e.EventTypeId == eventID));
     return(logicEvent);
 }
        public async Task UpdateEventByIDAsync(Logic.Objects.Event targetEvent)
        {
            Data.Entities.EventType oldContextEvent = await santaContext.EventTypes.FirstOrDefaultAsync(e => e.EventTypeId == targetEvent.eventTypeID);

            oldContextEvent.EventDescription = targetEvent.eventDescription;
            oldContextEvent.IsActive         = targetEvent.active;

            santaContext.Update(oldContextEvent);
        }
Ejemplo n.º 6
0
 public static Entities.EventType MapEvent(Logic.Objects.Event logicEvent)
 {
     Entities.EventType contextEvent = new EventType()
     {
         EventTypeId      = logicEvent.eventTypeID,
         EventDescription = logicEvent.eventDescription,
         IsActive         = logicEvent.active
     };
     return(contextEvent);
 }
Ejemplo n.º 7
0
 public static Logic.Objects.Event MapEvent(Entities.EventType contextEventType)
 {
     Logic.Objects.Event logicEvent = new Logic.Objects.Event()
     {
         eventTypeID      = contextEventType.EventTypeId,
         eventDescription = contextEventType.EventDescription,
         active           = contextEventType.IsActive,
         removable        = contextEventType.ClientRelationXref.Count == 0 && contextEventType.Survey.Count == 0,
         immutable        = contextEventType.EventDescription == Constants.CARD_EXCHANGE_EVENT || contextEventType.EventDescription == Constants.GIFT_EXCHANGE_EVENT
     };
     return(logicEvent);
 }
 public async Task CreateEventAsync(Logic.Objects.Event newEvent)
 {
     Data.Entities.EventType contextEvent = Mapper.MapEvent(newEvent);
     await santaContext.EventTypes.AddAsync(contextEvent);
 }
        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));
        }