Example #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);
        }
        /// <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;
        }