Пример #1
0
        public async Task<IHttpActionResult> CreateContactUsMessage(ContactUsDto contactUs)
        {
            contactUs.UserId = contactUs.CreatedBy = contactUs.ModifiedBy = User.Identity.GetUserId();
            string orgCRMId = this.youfferContactService.GetOrgCRMId(contactUs.UserId).CRMId;

            long threadId = 0;
            CRMContactUs crmContactUsOld = this.crmManagerService.ReadContactUsMessage(orgCRMId);
            if (crmContactUsOld == null)
            {
                MessageThreadDto msgThread = this.youfferMessageService.GetMessageThread("YoufferAdmin", contactUs.UserId);
                if (msgThread == null)
                {
                    msgThread = new MessageThreadDto { FromUser = contactUs.UserId, ToUser = "******", CreatedBy = contactUs.UserId, ModifiedBy = contactUs.UserId };
                    msgThread = this.youfferMessageService.CreateMessageThread(msgThread);
                    threadId = msgThread.Id;
                }
                else
                {
                    threadId = msgThread.Id;
                }
            }
            else
            {
                threadId = crmContactUsOld.ThreadId;
            }

            CRMContactUs crmContactUs = new CRMContactUs()
            {
                Subject = contactUs.Subject,
                Description = contactUs.Description,
                Department = contactUs.DeptId.ToString(),
                IsIncomingMessage = true,
                IsDeleted = false,
                UserId = orgCRMId,
                ThreadId = threadId
            };

            if (contactUs.DeptId == ContactUsDept.Refund)
            {
                OrganisationModel org = this.crmManagerService.GetOrganisation(contactUs.UserId);
                crmContactUs.Assigned_User_Id = org.Assigned_User_Id;
            }

            crmContactUs = this.crmManagerService.CreateContactUsMessage(crmContactUs);
            if (!string.IsNullOrWhiteSpace(crmContactUs.Id))
            {
                contactUs.Id = Convert.ToInt64(crmContactUs.Id.Split('x')[1]);
            }

            StatusMessage res = new StatusMessage();
            res.IsSuccess = contactUs.Id > 0;

            return this.Ok(res);
        }
Пример #2
0
        /// <summary>
        /// Creates the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>The MessagesDto object.</returns>
        public MessagesDto CreateMessage(MessagesDto message)
        {
            try
            {
                MessageThreadDto messageThread = this.GetMessageThread(message.FromUser, message.ToUser);
                if (messageThread == null || messageThread.Id < 1)
                {
                    messageThread = new MessageThreadDto { FromUser = message.FromUser, ToUser = message.ToUser, CreatedBy = message.FromUser, ModifiedBy = message.FromUser };
                    messageThread = this.CreateMessageThread(messageThread);
                }

                if (messageThread.IsDeleted || messageThread.IsDeletedByUser || messageThread.IsDeletedByCompany)
                {
                    messageThread.IsDeleted = messageThread.IsDeletedByUser = messageThread.IsDeletedByCompany = false;
                    messageThread.ModifiedOn = DateTime.UtcNow;
                    MessageThread thread = this.mapperFactory.GetMapper<MessageThreadDto, MessageThread>().Map(messageThread);
                    this.messageThreadRepository.Update(thread);
                    this.messageThreadRepository.Commit();
                }

                message.ThreadId = messageThread.Id;
                Messages msg = this.mapperFactory.GetMapper<MessagesDto, Messages>().Map(message);
                this.messageRepository.Insert(msg);
                this.messageRepository.Commit();

                message = this.mapperFactory.GetMapper<Messages, MessagesDto>().Map(msg);
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("CreateMessage - " + ex.Message);
            }

            return message;
        }
Пример #3
0
        /// <summary>
        /// Gets the message thread.
        /// </summary>
        /// <param name="fromUserId">From user identifier.</param>
        /// <param name="toUserId">To user identifier.</param>
        /// <returns>MessageThreadDto object.</returns>
        public MessageThreadDto GetMessageThread(string fromUserId, string toUserId)
        {
            MessageThreadDto messageThread = new MessageThreadDto();
            try
            {
                MessageThread msgThread = this.messageThreadRepository.Find(x => (x.FromUser == fromUserId && x.ToUser == toUserId) || (x.FromUser == toUserId && x.ToUser == fromUserId)).FirstOrDefault();
                messageThread = this.mapperFactory.GetMapper<MessageThread, MessageThreadDto>().Map(msgThread);
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("GetMessageThread - " + ex.Message);
            }

            return messageThread;
        }
Пример #4
0
        /// <summary>
        /// Creates the contact us message.
        /// </summary>
        /// <param name="contactUs">The contact us.</param>
        /// <param name="fromAdmin"> is Message from Admin</param>
        /// <returns>ContactUsDto object.</returns>
        public ContactUsDto CreateContactUsMessage(ContactUsDto contactUs, bool fromAdmin = false)
        {
            try
            {
                ContactUs contactUsMsg = this.contactUsRepository.Find(x => x.UserId == contactUs.UserId && !x.IsDeleted).FirstOrDefault() ?? new ContactUs();

                if (contactUsMsg.Id > 0)
                {
                    contactUs.ThreadId = contactUsMsg.ThreadId;
                }
                else
                {
                    MessageThreadDto msgThreadDto = new MessageThreadDto();
                    if (!fromAdmin)
                    {
                        msgThreadDto.FromUser = msgThreadDto.CreatedBy = msgThreadDto.ModifiedBy = contactUs.UserId;
                        msgThreadDto.ToUser = "******";
                    }
                    else
                    {
                        msgThreadDto.FromUser = msgThreadDto.CreatedBy = msgThreadDto.ModifiedBy = "YoufferAdmin";
                        msgThreadDto.ToUser = contactUs.UserId;
                    }

                    msgThreadDto.IsDeleted = msgThreadDto.IsDeletedByCompany = msgThreadDto.IsDeletedByUser = false;
                    msgThreadDto = this.CreateMessageThread(msgThreadDto);
                    contactUs.ThreadId = msgThreadDto.Id;
                }

                contactUsMsg = this.mapperFactory.GetMapper<ContactUsDto, ContactUs>().Map(contactUs);
                this.contactUsRepository.Insert(contactUsMsg);
                this.contactUsRepository.Commit();

                contactUs.Id = contactUsMsg.Id;
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("CreateContactUsMessage - " + ex.Message);
            }

            return contactUs;
        }
Пример #5
0
        /// <summary>
        /// Creates the message thread.
        /// </summary>
        /// <param name="messageThread">The message thread.</param>
        /// <returns>MessageThreadDto object.</returns>
        public MessageThreadDto CreateMessageThread(MessageThreadDto messageThread)
        {
            try
            {
                MessageThread msgThread = this.mapperFactory.GetMapper<MessageThreadDto, MessageThread>().Map(messageThread);
                this.messageThreadRepository.Insert(msgThread);
                this.messageThreadRepository.Commit();

                messageThread.Id = msgThread.Id;
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("CreateMessageThread - " + ex.Message);
            }

            return messageThread;
        }