public async Task<IHttpActionResult> MarkAsPurchased(MarkAsPurchasedDto markAsPurchased)
        {
            StatusMessage stat = new StatusMessage();

            string userId = markAsPurchased.UserId;
            string companyId = User.Identity.GetUserId();

            List<ApplicationUserDto> appUsers = this.userService.GetUsers(userId, companyId);
            string contactId = appUsers.Where(x => x.Id == userId).Select(x => x.CRMId).First().ToString();
            string organisationId = appUsers.Where(x => x.Id == companyId).Select(x => x.CRMId).First().ToString();
            string interestName = markAsPurchased.Interest;

            string leadId = this.youfferLeadService.GetMappingEntryByContactAndOrgCRMIdAndInterest(userId, organisationId, interestName).LeadId;

            ContactModel contact = this.crmManagerService.GetContact(userId);
            OrganisationModel org = this.crmManagerService.GetOrganisation(companyId);

            stat.IsSuccess = this.crmManagerService.MarkUserAsPurchased(userId, contactId, contact.FirstName, organisationId, interestName, leadId);

            if (!string.IsNullOrEmpty(contact.GCMId))
            {
                this.pushMessageService.SendMarkPurchasedNotificationToAndroid(contact.GCMId, org.AccountName, companyId, contact.FirstName, userId, interestName, "User Purchased", Notification.purchased.ToString());
            }

            if (!string.IsNullOrEmpty(contact.UDId))
            {
                this.pushMessageService.SendMarkPurchasedNotificationToiOS(contact.UDId, org.AccountName, companyId, string.Empty, userId, interestName, "User Purchased", Notification.purchased.ToString());
            }

            return this.Ok(stat);
        }
        public async Task<IHttpActionResult> ReportUser(FeedbackDto feedback)
        {
            string companyId = User.Identity.GetUserId();

            List<ApplicationUserDto> appUsers = this.userService.GetUsers(feedback.ToId, companyId);
            string contactId = appUsers.Where(x => x.Id == feedback.ToId).Select(x => x.CRMId).First().ToString();
            string organisationId = appUsers.Where(x => x.Id == companyId).Select(x => x.CRMId).First().ToString();

            feedback.FromId = feedback.CreatedBy = companyId;
            feedback.FeedbackId = Convert.ToInt32(Feedback.ReportUser);
            feedback = this.youfferFeedbackService.SaveFeedback(feedback);

            StatusMessage status = new StatusMessage();
            status.IsSuccess = this.crmManagerService.ReportUser(contactId, organisationId);

            ContactModel contact = this.crmManagerService.GetContact(feedback.ToId);
            OrganisationModel org = this.crmManagerService.GetOrganisation(companyId);
            if (!string.IsNullOrEmpty(contact.GCMId))
            {
                this.pushMessageService.SendReportUserNotificationToAndroid(contact.GCMId, companyId, org.AccountName, "Report User", Notification.reportuser.ToString());
            }

            if (!string.IsNullOrEmpty(contact.UDId))
            {
                this.pushMessageService.SendReportUserNotificationToiOS(contact.UDId, companyId, org.AccountName, "Report User", Notification.reportuser.ToString());
            }

            CRMNotifications notification = new CRMNotifications()
            {
                OrganisationsId = organisationId,
                ContactId = contactId,
                NotificationType = ConfigConstants.OrganisationComplainedContact
            };

            this.crmManagerService.CreateNotification(notification);

            return this.Ok(feedback);
        }
        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);
        }
Exemple #4
0
        public async Task<IHttpActionResult> SendVerificationCode(VerificationCode model)
        {
            StatusMessage stat = new StatusMessage();
            if (!string.IsNullOrWhiteSpace(model.PhoneNumber))
            {
                if (model.PhoneNumber.StartsWith("0"))
                {
                    model.PhoneNumber = model.PhoneNumber.TrimStart('0');
                }

                model.PhoneNumber = "+" + model.CountryCode + model.PhoneNumber;
                string userId = User.Identity.GetUserId();
                Random generator = new Random();
                string code = generator.Next(0, 1000000).ToString("D6");
                string message = "Your Confirmation Code:{0}\n\nThank you for downloading Youffer.\n\nSupport:\n{1}\n{2}";
                message = string.Format(message, code, AppSettings.Get<string>(ConfigConstants.YoufferSupportEmail), AppSettings.Get<string>(ConfigConstants.YoufferWebsiteURL));
                stat.IsSuccess = this.crmManagerService.SendVerificationCode(userId, model.PhoneNumber, code, message);
            }

            return this.Ok(stat);
        }
Exemple #5
0
 public async Task<IHttpActionResult> CheckVerificationCode(string code)
 {
     string userId = User.Identity.GetUserId();
     StatusMessage stat = new StatusMessage();
     string errorMessage;
     stat.IsSuccess = this.crmManagerService.UpdatePhoneNumberAfterVerification(userId, code, out errorMessage);
     stat.ErrorMessage = errorMessage;
     return this.Ok(stat);
 }
        public async Task<IHttpActionResult> ChangePassword(ChangePasswordModel model)
        {
            this.LoggerService.LogException("ChangePassword Request -json- " + JsonConvert.SerializeObject(model));
            StatusMessage msg = new StatusMessage();
            try
            {
                string userId = User.Identity.GetUserId();
                msg.ErrorMessage = await this.authRepository.ChangePassword(userId, model.OldPassword, model.NewPassword);
                if (string.IsNullOrWhiteSpace(msg.ErrorMessage))
                {
                    msg.IsSuccess = true;
                    return this.Ok(msg);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("ChangePassword: " + ex.Message);
                msg.ErrorMessage = ex.Message;
            }

            return this.Ok(msg);
        }
Exemple #7
0
        public async Task<IHttpActionResult> DeletemessageThread(int threadId)
        {
            StatusMessage status = new StatusMessage();
            string userId = User.Identity.GetUserId();
            string contactCRMId = this.youfferContactService.GetMappingEntryByContactId(userId).ContactCRMId;

            MessageThreadDto msgThread = this.youfferMessageService.GetMessageThread(userId, "YoufferAdmin");
            if (msgThread != null)
            {
                this.crmManagerService.MarkContactUsMessagesDeleted(contactCRMId);
            }

            status.IsSuccess = this.youfferMessageService.DeleteThread(threadId, userId);
            return this.Ok(status);
        }
Exemple #8
0
        public async Task<IHttpActionResult> NotCallAgain(string companyId)
        {
            StatusMessage status = new StatusMessage();
            string userId = User.Identity.GetUserId();
            string crmContactId = this.userService.GetContact(userId).CRMId;
            string crmOrgId = this.userService.GetContact(companyId).CRMId;

            status.IsSuccess = this.crmManagerService.MarkNotCall(crmContactId, crmOrgId);

            OrganisationModel organisation = this.crmManagerService.GetOrganisation(companyId);
            ContactModel contact = this.crmManagerService.GetContact(userId);
            if (!string.IsNullOrEmpty(organisation.GCMId))
            {
                this.pushMessageService.SendNotCallAgainNotificationToAndroid(organisation.GCMId, userId, contact.FirstName, "Not call again", Notification.notcall.ToString());
            }

            if (!string.IsNullOrEmpty(organisation.UDId))
            {
                this.pushMessageService.SendNotCallAgainNotificationToiOS(organisation.UDId, userId, contact.FirstName, "Not call again", Notification.notcall.ToString());
            }

            return this.Ok(status);
        }
Exemple #9
0
        public async Task<IHttpActionResult> RequestPayment(PaymentModelDto paymentModel)
        {
            StatusMessage status = new StatusMessage();

            string userId = User.Identity.GetUserId();
            string crmContactId = this.userService.GetContact(userId).CRMId;

            decimal totalAmount = this.youfferPaymentService.GetPurchasedUserTotalAmount(userId);
            if (totalAmount < 50)
            {
                status.IsSuccess = false;
                status.ErrorMessage = "You need to have at least $50 in your account to request payment.";
                return this.Ok(status);
            }

            string crmLeadId = string.Empty;

            if (!string.IsNullOrEmpty(crmContactId))
            {
                crmLeadId = this.youfferContactService.GetMappingEntryByContactId(userId).LeadId;
            }

            CRMRequestPayment crmRequestPayment = new CRMRequestPayment()
            {
                ContactId = crmContactId,
                Note = string.Empty,
                IsApproved = false,
                Amount = totalAmount
            };

            this.crmManagerService.CreatePaymentRequest(crmRequestPayment);
            status.IsSuccess = this.youfferPaymentService.RequestPayment(crmLeadId);
            return this.Ok(status);
        }
Exemple #10
0
        public async Task<IHttpActionResult> DeleteMessage(string msgId)
        {
            string userId = User.Identity.GetUserId();
            StatusMessage status = new StatusMessage();

            bool isContactUs = this.crmManagerService.CheckIfContactUsMsg(AppSettings.Get<string>(ConfigConstants.ContactUsId) + msgId);
            if (isContactUs)
            {
                status.IsSuccess = this.crmManagerService.DeleteContactusMessage(AppSettings.Get<string>(ConfigConstants.ContactUsId) + msgId);
            }
            else
            {
                status.IsSuccess = this.youfferMessageService.DeleteMessage(msgId, userId);
            }

            return this.Ok(status);
        }
Exemple #11
0
        public async Task<IHttpActionResult> ReportCompany(FeedbackDto feedback)
        {
            string userId = User.Identity.GetUserId();
            string crmContactId = this.userService.GetContact(userId).CRMId;
            string crmOrgId = this.userService.GetContact(feedback.ToId).CRMId;
            feedback.FromId = feedback.CreatedBy = userId;
            feedback.FeedbackId = Convert.ToInt32(Feedback.ReportCompany);

            feedback = this.youfferFeedbackService.SaveFeedback(feedback);

            StatusMessage status = new StatusMessage();
            status.IsSuccess = this.crmManagerService.ReportCompany(crmContactId, crmOrgId);

            OrganisationModel organisation = this.crmManagerService.GetOrganisation(feedback.ToId);
            ContactModel contact = this.crmManagerService.GetContact(userId);
            if (!string.IsNullOrEmpty(organisation.GCMId))
            {
                this.pushMessageService.SendReportCompanyNotificationToAndroid(organisation.GCMId, userId, contact.FirstName, "Fake Company", Notification.reportcompany.ToString());
            }

            if (!string.IsNullOrEmpty(organisation.UDId))
            {
                this.pushMessageService.SendReportCompanyNotificationToiOS(organisation.UDId, userId, contact.FirstName, "Fake Company", Notification.reportcompany.ToString());
            }

            CRMNotifications notification = new CRMNotifications()
            {
                OrganisationsId = crmOrgId,
                ContactId = crmContactId,
                NotificationType = ConfigConstants.ContactComplainedOrganisation
            };

            this.crmManagerService.CreateNotification(notification);

            return this.Ok(status);
        }
Exemple #12
0
        public async Task<IHttpActionResult> Register(UserModel userModel)
        {
            try
            {
                this.LoggerService.LogException("Register Request -json- " + JsonConvert.SerializeObject(userModel));
            }
            catch (Exception ex1)
            {
            }

            if (string.IsNullOrEmpty(userModel.Country) && !string.IsNullOrEmpty(userModel.CountryCode))
            {
                userModel.Country = this.commonService.GetCountryFromISO2Code(userModel.CountryCode);
            }

            if (string.IsNullOrEmpty(userModel.Country))
            {
                userModel.Country = "United States";
            }

            ////string ipAddress = string.IsNullOrEmpty(userModel.IPAddress) ? HttpContext.Current.Request.UserHostAddress : userModel.IPAddress;
            ////CityDto cityData = this.ip2LocationService.GetCityData(ipAddress);
            ////userModel.Country = cityData.CountryInfo.CountryName;
            ////userModel.State = cityData.MostSpecificSubDivisionName == null ? string.Empty : cityData.MostSpecificSubDivisionName;
            ////userModel.Latitude = cityData.Latitude;
            ////userModel.Longitude = cityData.Longitude;

            ////Only for handling old Android apps
            List<string> lstCallingCodes = this.commonService.GetCountryMetaData().Select(x => x.CallingCode).ToList();
            try
            {
                IEnumerable<string> code = lstCallingCodes.Where(x => x == userModel.CountryCode);
                if (!string.IsNullOrEmpty(code.FirstOrDefault()))
                {
                    userModel.CountryCode = this.commonService.GetISO2CodeFromCallingCode(code.FirstOrDefault());
                }
            }
            catch
            {
            }

            StatusMessage status = new StatusMessage();
            Roles userRole;

            bool isRoleParsed = Enum.TryParse(userModel.Role.ToString(), true, out userRole);

            if (!Roles.IsDefined(typeof(Roles), userModel.Role) || userRole == Roles.Admin)
            {
                return this.BadRequest();
            }

            userModel.UserRole = userRole.ToString();

            if (!this.ModelState.IsValid)
            {
                if (userModel.OSType != OSType.Web)
                {
                    string errorMsg = this.ModelState.Values.First().Errors[0].ErrorMessage;
                    return this.BadRequest(errorMsg);
                }

                return this.BadRequest(this.ModelState);
            }

            IdentityResult result;
            try
            {
                result = await this.authRepository.RegisterUser(userModel);
                if (!result.Succeeded)
                {
                    string errorMessage = result.Errors.Any() ? result.Errors.First() : string.Empty;
                    return this.BadRequest(errorMessage);
                }

                var user = await this.authRepository.FindUser(userModel.EmailId, userModel.Password);

                string defaultImageUrl = AppSettings.Get<string>(ConfigConstants.ApiBaseUrl) + AppSettings.Get<string>(ConfigConstants.DefaultProfileImage);
                string imageUrl = ImageHelper.SaveImageFromUrl(defaultImageUrl, user.Id);
                if (userModel.UserRole == Roles.Company.ToString())
                {
                    OrganisationModel orgModel = new OrganisationModel();
                    orgModel = this.mapperFactory.GetMapper<UserModel, OrganisationModel>().Map(userModel);

                    orgModel.ImageURL = imageUrl;
                    orgModel.IsImageUploaded = false;
                    orgModel.CashBalance = orgModel.CreditBalance = 0;

                    ////Only for handling old Android apps
                    if (!string.IsNullOrEmpty(userModel.SubBusinessType) && userModel.SubBusinessType.Length > 0)
                    {
                        orgModel.SubBusinessType = userModel.SubBusinessType.Split(new string[] { "," }, StringSplitOptions.None).Where(x => !string.IsNullOrEmpty(x)).ToArray();
                        orgModel.MainBusinessType = this.youfferInterestService.GetMainBusinessTypeFromSub(userModel.SubBusinessType).Select(x => x.ParentBusinessTypeName).Distinct().ToArray();
                    }

                    if (!string.IsNullOrEmpty(userModel.MainBusinessType) && userModel.MainBusinessType.Length > 0)
                    {
                        orgModel.MainBusinessType = userModel.MainBusinessType.Split(',').ToArray();
                        string[] subInterest = this.youfferInterestService.GetSubBusinessTypeFromMain(userModel.MainBusinessType).Select(x => x.BusinessTypeName).Distinct().ToArray();
                        orgModel.SubBusinessType = subInterest;
                    }

                    orgModel = this.crmManagerService.AddOrganisation(orgModel, user);

                    ////Send username and password email
                    await this.SendUserNamePasswordEmail(orgModel.Email1, orgModel.Password);
                }
                else
                {
                    ContactModel contactModel = new ContactModel();
                    contactModel = this.mapperFactory.GetMapper<UserModel, ContactModel>().Map(userModel);
                    contactModel.ImageURL = imageUrl;

                    contactModel = this.crmManagerService.AddContact(contactModel, user);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("Register: " + ex.Message);
                this.ModelState.AddModelError("Exception", ex.Message);

                if (userModel.OSType != OSType.Web)
                {
                    return this.BadRequest(ex.Message);
                }

                return this.BadRequest(this.ModelState);
            }

            IHttpActionResult errorResult = this.GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }

            status.IsSuccess = true;
            return this.Ok(status);
        }
Exemple #13
0
        public async Task<IHttpActionResult> SendResetPasswordLink(string email)
        {
            StatusMessage msg = new StatusMessage();
            try
            {
                msg.ErrorMessage = await this.authRepository.SendForgotPasswordLink(email);
                if (string.IsNullOrWhiteSpace(msg.ErrorMessage))
                {
                    msg.IsSuccess = true;
                    return this.Ok(msg);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("SendResetPasswordLink: " + ex.Message);
                msg.ErrorMessage = ex.Message;
            }

            return this.Ok(msg);
        }
Exemple #14
0
        public async Task<IHttpActionResult> UpdatePasswordAfterRest(ForgotPassword model)
        {
            this.LoggerService.LogException("UpdatePasswordAfterRest Request -json- " + JsonConvert.SerializeObject(model));
            StatusMessage msg = new StatusMessage();
            try
            {
                msg.ErrorMessage = await this.authRepository.UpdatePasswordAfterReset(model.ResetPwdGuid, model.NewPassword);
                if (string.IsNullOrWhiteSpace(msg.ErrorMessage))
                {
                    msg.IsSuccess = true;
                    return this.Ok(msg);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("ChangePassword: " + ex.Message);
                msg.ErrorMessage = ex.Message;
            }

            return this.Ok(msg);
        }
Exemple #15
0
        public async Task<IHttpActionResult> CreateOpportunity(PayPalDetailsDto payPalDetailsDto)
        {
            StatusMessage status = new StatusMessage();
            string companyId = User.Identity.GetUserId();
            string crmContactId = this.youfferContactService.GetMappingEntryByContactId(payPalDetailsDto.UserId).ContactCRMId;
            string crmLeadId = this.youfferContactService.GetMappingEntryByContactId(payPalDetailsDto.UserId).LeadId;
            ApplicationUserDto compantDet = this.youfferContactService.GetOrgCRMId(companyId);
            string crmOrgId = compantDet.CRMId;
            LeadModel leadModel = this.crmManagerService.GetLead(crmLeadId);
            OrganisationModel org = this.crmManagerService.GetOrganisation(companyId);

            double price = Convert.ToDouble(payPalDetailsDto.Amount);
            status.IsSuccess = this.crmManagerService.AddOpportunity(leadModel, crmOrgId, crmContactId, price, payPalDetailsDto, null);

            if (status.IsSuccess)
            {
                org.AnnualRevenue += price;
                this.crmManagerService.UpdateOrganisation(companyId, org);
            }

            if (!string.IsNullOrEmpty(leadModel.GCMId))
            {
                this.pushMessageService.SendPurchasedNotificationToAndroid(leadModel.GCMId, companyId, compantDet.Name, payPalDetailsDto.Interest, "Purchased", Notification.buyuser.ToString());
            }

            if (!string.IsNullOrEmpty(leadModel.UDId))
            {
                this.pushMessageService.SendPurchasedNotificationToiOS(leadModel.UDId, companyId, compantDet.Name, "Purchased", Notification.buyuser.ToString());
            }

            CRMNotifications notification = new CRMNotifications()
            {
                OrganisationsId = crmOrgId,
                ContactId = crmContactId,
                NotificationType = ConfigConstants.OrganisationPurchasedContact
            };

            this.crmManagerService.CreateNotification(notification);

            return this.Ok(status);
        }
Exemple #16
0
        public async Task<IHttpActionResult> Logout()
        {
            string userId = User.Identity.GetUserId();

            ContactModel contactModel = this.crmManagerService.GetContact(userId);

            contactModel.IsOnline = false;
            contactModel.UDId = string.Empty;
            contactModel.GCMId = string.Empty;
            this.crmManagerService.UpdateContact(userId, contactModel);
            StatusMessage msg = new StatusMessage()
            {
                IsSuccess = true
            };

            return this.Ok(msg);
        }
Exemple #17
0
        public async Task<IHttpActionResult> CanPurchaseUser(string userId, string interest)
        {
            StatusMessage stat = new StatusMessage();
            string companyId = User.Identity.GetUserId();
            string crmContactId = this.youfferContactService.GetMappingEntryByContactId(userId).ContactCRMId;
            string crmOrgId = this.youfferContactService.GetOrgCRMId(companyId).CRMId;

            stat.IsSuccess = this.crmManagerService.CanPurchaseUser(crmOrgId, crmContactId, interest);

            return this.Ok(stat);
        }
Exemple #18
0
        /// <summary>
        /// Sends the user name password email.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="password">The password.</param>
        /// <returns>IHttpActionResult object</returns>
        private async Task<IHttpActionResult> SendUserNamePasswordEmail(string email, string password)
        {
            StatusMessage msg = new StatusMessage();
            try
            {
                msg.ErrorMessage = await this.authRepository.SendUserNamePasswordEmail(email, password);
                if (string.IsNullOrWhiteSpace(msg.ErrorMessage))
                {
                    msg.IsSuccess = true;
                    return this.Ok(msg);
                }
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("SendUserNamePasswordEmail: " + ex.Message);
                msg.ErrorMessage = ex.Message;
            }

            return this.Ok(msg);
        }