public static AllowedAssignmentMeta MapAllowedAssignmentMeta(Logic.Objects.Client logicClient)
        {
            AllowedAssignmentMeta logicAllowedAssignmentMeta = new AllowedAssignmentMeta()
            {
                clientMeta       = Mapper.MapClientMeta(logicClient),
                tags             = logicClient.tags,
                totalSenders     = logicClient.senders.Count,
                totalAssignments = logicClient.assignments.Count
            };

            return(logicAllowedAssignmentMeta);
        }
        public static ClientChatMeta MapClientChatMeta(Logic.Objects.Client logicClient)
        {
            ClientChatMeta logicMeta = new ClientChatMeta()
            {
                clientId       = logicClient.clientID,
                clientNickname = logicClient.nickname,
                hasAccount     = logicClient.hasAccount,
                isAdmin        = logicClient.isAdmin
            };

            return(logicMeta);
        }
Esempio n. 3
0
        public async Task <Logic.Objects.Client> CreateClientAsync(string userName, string email)
        {
            try
            {
                Logic.Objects.Client client = new Logic.Objects.Client(userName, email);
                _context.Client.Add(Mapper.MapClient(client));
                await _context.SaveChangesAsync();

                return(client);
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong within CreateClientAsync: " + e.Message);
                return(null);
            }
        }
 /// <summary>
 /// maps a logic client to a context client
 /// </summary>
 /// <param name="logicClient"></param>
 /// <returns></returns>
 public static Data.Entities.Client MapClient(Logic.Objects.Client logicClient)
 {
     Entities.Client contextClient = new Entities.Client()
     {
         ClientId       = logicClient.clientID,
         ClientName     = logicClient.clientName,
         Email          = logicClient.email,
         Nickname       = logicClient.nickname,
         ClientStatusId = logicClient.clientStatus.statusID,
         AddressLine1   = logicClient.address.addressLineOne,
         AddressLine2   = logicClient.address.addressLineTwo,
         City           = logicClient.address.city,
         State          = logicClient.address.state,
         PostalCode     = logicClient.address.postalCode,
         Country        = logicClient.address.country,
         IsAdmin        = logicClient.isAdmin,
         HasAccount     = logicClient.hasAccount
     };
     return(contextClient);
 }
        public async Task UpdateClientByIDAsyncGetsCalledOnce()
        {
            var listOfClients = SetupClients();
            var targetID      = listOfClients.First().ClientID;
            var changedClient = new Logic.Objects.Client()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            Mock <Logic.Interfaces.IRepository> mockRepository = new Mock <Logic.Interfaces.IRepository>();

            mockRepository
            .Setup(x => x.UpdateClientByIDAsync(targetID, changedClient));

            await mockRepository.Object.UpdateClientByIDAsync(targetID, changedClient);

            mockRepository
            .Verify(x => x.UpdateClientByIDAsync(targetID, changedClient), Times.Once());
        }
 public static Logic.Objects.Client MapStaticClient(Entities.Client contextClient)
 {
     Logic.Objects.Client logicClient = new Logic.Objects.Client()
     {
         clientID   = contextClient.ClientId,
         email      = contextClient.Email,
         clientName = contextClient.ClientName,
         nickname   = contextClient.Nickname,
         hasAccount = contextClient.HasAccount,
         isAdmin    = contextClient.IsAdmin,
         address    = new Address
         {
             addressLineOne = contextClient.AddressLine1,
             addressLineTwo = contextClient.AddressLine2,
             city           = contextClient.City,
             country        = contextClient.Country,
             state          = contextClient.State,
             postalCode     = contextClient.PostalCode
         }
     };
     return(logicClient);
 }
Esempio n. 7
0
        public async Task UpdateClientByIDAsync(Logic.Objects.Client targetLogicClient)
        {
            Entities.Client contextOldClient = await santaContext.Clients.FirstOrDefaultAsync(c => c.ClientId == targetLogicClient.clientID);

            contextOldClient.ClientName = targetLogicClient.clientName;

            contextOldClient.AddressLine1 = targetLogicClient.address.addressLineOne;
            contextOldClient.AddressLine2 = targetLogicClient.address.addressLineTwo;
            contextOldClient.City         = targetLogicClient.address.city;
            contextOldClient.State        = targetLogicClient.address.state;
            contextOldClient.Country      = targetLogicClient.address.country;
            contextOldClient.PostalCode   = targetLogicClient.address.postalCode;

            contextOldClient.ClientStatusId = targetLogicClient.clientStatus.statusID;

            contextOldClient.Email      = targetLogicClient.email;
            contextOldClient.Nickname   = targetLogicClient.nickname;
            contextOldClient.IsAdmin    = targetLogicClient.isAdmin;
            contextOldClient.HasAccount = targetLogicClient.hasAccount;

            santaContext.Clients.Update(contextOldClient);
        }
Esempio n. 8
0
        public void MapClientObjectToEntity()
        {
            var clientID = Guid.NewGuid();

            var mappableObject = new Logic.Objects.Client()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            var expected = new Data.Entities.Client()
            {
                UserName = "******",
                Email    = "*****@*****.**"
            };

            var value = Data.Repository.Mapper.MapClient(mappableObject);

            Assert.IsType <Data.Entities.Client>(value);
            Assert.IsType <Guid>(value.ClientID);
            Assert.Equal(expected.UserName, value.UserName);
            Assert.Equal(expected.Email, value.Email);
        }
Esempio n. 9
0
        public async Task <bool> UpdateClientByIDAsync(Guid targetClientID, Logic.Objects.Client changedClient)
        {
            try
            {
                var targetClient = await _context.Client.FirstOrDefaultAsync(g => g.ClientID == targetClientID);

                if (targetClient == null)
                {
                    return(false);
                }

                targetClient.UserName = changedClient.UserName;
                targetClient.Email    = changedClient.Email;
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong within UpdateClientByIDAsync: " + e.Message);
                return(false);
            }
        }
        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());
        }
        /// <summary>
        /// Maps history information for general chats, which do not have a relationshipXrefID, EventType, or AssignmentClient using a list of contextChatMessages relating to the client's general conversation. Uses a logic client object
        /// rather than a context client object
        /// </summary>
        /// <param name="logicConversationClient"></param>
        /// <param name="contextChatMessages"></param>
        /// <param name="logicSubjectClient"></param>
        /// <returns></returns>
        public static Logic.Objects.MessageHistory MapHistoryInformation(Logic.Objects.Client logicConversationClient, List <Entities.ChatMessage> contextChatMessages, BaseClient logicSubjectClient)
        {
            List <Message> logicListRecieverMessages = new List <Message>();
            List <Message> logicListSubjectMessages  = new List <Message>();

            if (logicSubjectClient.isAdmin)
            {
                logicListSubjectMessages = contextChatMessages
                                           .Select(Mapper.MapMessage)
                                           .OrderBy(dt => dt.dateTimeSent)
                                           .Where(m => m.fromAdmin)
                                           .ToList();

                logicListRecieverMessages = contextChatMessages
                                            .Select(Mapper.MapMessage)
                                            .OrderBy(dt => dt.dateTimeSent)
                                            .Where(m => !m.fromAdmin)
                                            .ToList();
            }
            else
            {
                logicListSubjectMessages = contextChatMessages
                                           .Select(Mapper.MapMessage)
                                           .OrderBy(dt => dt.dateTimeSent)
                                           .Where(m => !m.fromAdmin && m.senderClient.clientId == logicSubjectClient.clientID)
                                           .ToList();

                logicListRecieverMessages = contextChatMessages
                                            .Select(Mapper.MapMessage)
                                            .OrderBy(dt => dt.dateTimeSent)
                                            .Where(m => m.fromAdmin)
                                            .ToList();
            }

            // General histories dont have a relationXrefID, EventType, or AssignmentClient because they are not tied to an assignment
            MessageHistory logicHistory = new MessageHistory()
            {
                relationXrefID   = null,
                eventType        = new Event(),
                assignmentStatus = new Logic.Objects.AssignmentStatus(),

                subjectClient            = MapClientChatMeta(logicSubjectClient),
                conversationClient       = MapClientChatMeta(logicConversationClient),
                assignmentRecieverClient = new ClientChatMeta(),
                assignmentSenderClient   = new ClientChatMeta(),

                subjectMessages = logicListSubjectMessages,

                recieverMessages = logicListRecieverMessages,

                unreadCount = logicListRecieverMessages.Where(m => m.isMessageRead == false).ToList().Count()
            };

            logicHistory.unreadCount = logicHistory.recieverMessages.Where(m => m.isMessageRead == false).ToList().Count();

            foreach (Message logicMessage in logicHistory.subjectMessages)
            {
                logicMessage.subjectMessage = true;
            }

            return(logicHistory);
        }
Esempio n. 12
0
        public async Task <Logic.Objects.Client> GetClientByIDAsync(Guid clientId)
        {
            Logic.Objects.Client logicClient = await santaContext.Clients
                                               .Select(client => new Logic.Objects.Client()
            {
                clientID     = client.ClientId,
                email        = client.Email,
                nickname     = client.Nickname,
                clientName   = client.ClientName,
                isAdmin      = client.IsAdmin,
                hasAccount   = client.HasAccount,
                clientStatus = Mapper.MapStatus(client.ClientStatus),
                address      = new Address
                {
                    addressLineOne = client.AddressLine1,
                    addressLineTwo = client.AddressLine2,
                    city           = client.City,
                    country        = client.Country,
                    state          = client.State,
                    postalCode     = client.PostalCode
                },
                responses = client.SurveyResponses.Select(surveyResponse => new Response()
                {
                    surveyResponseID = surveyResponse.SurveyResponseId,
                    clientID         = surveyResponse.ClientId,
                    surveyID         = surveyResponse.SurveyId,
                    surveyOptionID   = surveyResponse.SurveyOptionId,
                    responseText     = surveyResponse.ResponseText,
                    responseEvent    = Mapper.MapEvent(surveyResponse.Survey.EventType),
                    surveyQuestion   = Mapper.MapQuestion(surveyResponse.SurveyQuestion)
                }).ToList(),
                notes = client.Notes.Select(note => new Logic.Objects.Base_Objects.Note()
                {
                    noteID       = note.NoteId,
                    noteSubject  = note.NoteSubject,
                    noteContents = note.NoteContents
                }).ToList(),
                tags = client.ClientTagXrefs.Select(tagXref => new Logic.Objects.Tag()
                {
                    tagID   = tagXref.TagId,
                    tagName = tagXref.Tag.TagName,
                }).ToList(),
                assignments = client.ClientRelationXrefSenderClients.Select(xref => new RelationshipMeta()
                {
                    relationshipClient   = xref.SenderClientId == client.ClientId ? Mapper.MapClientMeta(xref.RecipientClient) : Mapper.MapClientMeta(xref.SenderClient),
                    eventType            = Mapper.MapEvent(xref.EventType),
                    clientRelationXrefID = xref.ClientRelationXrefId,
                    assignmentStatus     = Mapper.MapAssignmentStatus(xref.AssignmentStatus),
                    tags      = new List <Logic.Objects.Tag>(),
                    removable = xref.ChatMessages.Count > 0 ? false : true
                }).ToList(),
                senders = client.ClientRelationXrefRecipientClients.Select(xref => new RelationshipMeta()
                {
                    relationshipClient   = xref.SenderClientId == client.ClientId ? Mapper.MapClientMeta(xref.RecipientClient) : Mapper.MapClientMeta(xref.SenderClient),
                    eventType            = Mapper.MapEvent(xref.EventType),
                    clientRelationXrefID = xref.ClientRelationXrefId,
                    assignmentStatus     = Mapper.MapAssignmentStatus(xref.AssignmentStatus),
                    tags      = new List <Logic.Objects.Tag>(),
                    removable = xref.ChatMessages.Count > 0 ? false : true
                }).ToList()
            }).AsNoTracking().FirstOrDefaultAsync(c => c.clientID == clientId);

            return(logicClient);
        }
Esempio n. 13
0
 public async Task CreateClient(Logic.Objects.Client newClient)
 {
     Entities.Client contextClient = Mapper.MapClient(newClient);
     await santaContext.Clients.AddAsync(contextClient);
 }