private void LoadModelAddressData(AffiliateViewModel model) { var ui = DnnUserController.Instance.GetUser(DnnGlobal.Instance.GetPortalId(), model.UserId.Value); UpdateCountryAndRegion(model, ui.Profile.Country, ui.Profile.Region); model.Company = ui.Profile["Company"] as string; model.AddressLine = ui.Profile.Street; model.City = ui.Profile.City; model.PostalCode = ui.Profile.PostalCode; model.Phone = ui.Profile.Telephone; }
private void LoadModel(AffiliateViewModel model) { if (string.IsNullOrEmpty(model.CountryId)) { model.CountryId = Country.UnitedStatesCountryBvin; } var country = HccApp.GlobalizationServices.Countries.Find(model.CountryId); model.Countries = HccApp.GlobalizationServices.Countries.FindAll(); model.Regions = country.Regions; model.AgreementText = HccApp.CurrentStore.Settings.AffiliateAgreementText; }
public ActionResult Register(AffiliateViewModel model) { if (ModelState.IsValid) { JsonResult result = null; var aff = LoadAffiliateFromModel(model); var createStatus = CreateUserStatus.None; var status = HccApp.ContactServices.Affiliates.Create(aff, ref createStatus); switch (status) { case AffiliateRepository.UpdateStatus.Success: result = GetStatusMessage(Localization.GetString("msgAffiliateSuccessfullyRegistered"), true, Url.RouteHccUrl(HccRoute.AffiliateDashboard)); var ui = DnnUserController.Instance.GetUser(DnnGlobal.Instance.GetPortalId(), aff.UserId); var culture = ui.Profile["UsedCulture"] as string; if (string.IsNullOrEmpty(culture)) { culture = "en-US"; } HccApp.ContactServices.SendAffiliateConfirmationEmail(aff, culture); if (HccApp.CurrentStore.Settings.AffiliateReview) { HccApp.ContactServices.SendAffiliateReviewEmail(aff); } if (aff.Approved) { HccApp.ContactServices.AffiliateWasApproved(aff, culture); } AssignAffiliateRole(aff.UserId); LoginAffiliateUser(aff); break; case AffiliateRepository.UpdateStatus.DuplicateAffiliateID: result = GetStatusMessage(Localization.GetString("msgAffiliateIdAlreadyExists"), false); break; case AffiliateRepository.UpdateStatus.UserCreateFailed: result = GetUserCreateFailedMessage(createStatus); break; default: result = GetStatusMessage(Localization.GetString("msgUnknownError"), false); break; } return(result); } return(Json(new { Status = "Invalid", Message = GetValidationSummaryMessage() })); }
private void LoadModel(AffiliateViewModel model) { var countryId = Country.UnitedStatesCountryBvin; var country = HccApp.GlobalizationServices.Countries.Find(countryId); model.Countries = HccApp.GlobalizationServices.Countries.FindAll(); model.CountryId = countryId; model.Regions = country.Regions; model.ReferralAffiliateId = Request.QueryString[WebAppSettings.AffiliateQueryStringName]; model.AgreementText = HccApp.CurrentStore.Settings.AffiliateAgreementText; model.AllowReferral = HccApp.CurrentStore.Settings.AffiliateDisplayChildren; }
public ActionResult Update(AffiliateViewModel model) { if (ModelState.IsValid) { JsonResult result = null; var status = AffiliateRepository.UpdateStatus.UnknownError; var affiliates = HccApp.ContactServices.Affiliates; var aff = affiliates.Find(model.Id); if (aff != null) { aff.AffiliateId = model.MyAffiliateId; aff.Address.FirstName = model.FirstName; aff.Address.LastName = model.LastName; aff.Address.CountryBvin = model.CountryId; aff.Address.Company = model.Company; aff.Address.Line1 = model.AddressLine; aff.Address.City = model.City; aff.Address.RegionBvin = model.State; aff.Address.PostalCode = model.PostalCode; aff.Address.Phone = model.Phone; if (!aff.Approved && HccApp.CurrentStore.Settings.AffiliateDisplayChildren) { aff.ReferralAffiliateId = model.ReferralAffiliateId; } status = affiliates.Update(aff); } switch (status) { case AffiliateRepository.UpdateStatus.Success: result = GetStatusMessage(Localization.GetString("msgAffiliateSuccessfullyUpdated"), true); break; case AffiliateRepository.UpdateStatus.DuplicateAffiliateID: result = GetStatusMessage(Localization.GetString("msgAffiliateIdAlreadyExists"), false); break; default: result = GetStatusMessage(Localization.GetString("msgUnknownError"), false); break; } return(result); } return(Json(new { Status = "Invalid", Message = GetValidationSummaryMessage() })); }
private Affiliate LoadAffiliateFromModel(AffiliateViewModel model) { var sett = HccApp.CurrentStore.Settings; var aff = new Affiliate { UserId = model.UserId ?? Null.NullInteger, Username = model.Username, Password = model.Password, StoreId = HccApp.CurrentStore.Id, Enabled = true, AffiliateId = model.MyAffiliateId, Email = model.Email, CommissionAmount = sett.AffiliateCommissionAmount, CommissionType = sett.AffiliateCommissionType, ReferralDays = sett.AffiliateReferralDays, Approved = !sett.AffiliateRequireApproval }; if (sett.AffiliateDisplayChildren) { aff.ReferralAffiliateId = model.ReferralAffiliateId; } aff.Address.FirstName = model.FirstName; aff.Address.LastName = model.LastName; aff.Address.CountryBvin = model.CountryId; aff.Address.Company = model.Company; aff.Address.Line1 = model.AddressLine; aff.Address.City = model.City; aff.Address.RegionBvin = model.State; aff.Address.PostalCode = model.PostalCode; aff.Address.Phone = model.Phone; if (model.UserId.HasValue) { var acc = HccApp.CurrentCustomer; aff.Username = acc.Username; aff.Email = acc.Email; aff.Address.FirstName = acc.FirstName; aff.Address.LastName = acc.LastName; } return(aff); }
private void UpdateCountryAndRegion(AffiliateViewModel model, string country, string region) { var gCountry = HccApp.GlobalizationServices.Countries.FindByDisplayName(country); if (gCountry != null) { model.CountryId = gCountry.Bvin; model.Regions = gCountry.Regions; var gRegion = gCountry.Regions.FirstOrDefault(r => r.DisplayName == region); if (gRegion != null) { model.State = gRegion.Abbreviation; } } else { model.CountryId = Country.UnitedStatesCountryBvin; } }
private void LoadModelUserInfo(AffiliateViewModel model, CustomerAccount acc) { model.UserId = HccApp.CurrentCustomerId.ConvertTo <int>(); model.Username = acc.Username; model.FirstName = HccApp.CurrentCustomer.FirstName; model.LastName = HccApp.CurrentCustomer.LastName; model.Email = "*****@*****.**"; // Fake data. For skipping validation only. model.Password = "******"; model.ConfirmPassword = "******"; LoadModelAddressData(model); var aff = HccApp.ContactServices.Affiliates.FindByUserId(model.UserId.Value); if (aff != null) { model.MyAffiliateId = aff.AffiliateId; } }
public ActionResult Index() { var userRegisteredAsAffiliate = false; var model = new AffiliateViewModel(); LoadModel(model); if (HccApp.MembershipServices.IsUserLoggedIn()) { var acc = HccApp.CurrentCustomer; userRegisteredAsAffiliate = IsUserAlreadyRegisteredAsAffiliate(acc); if (!userRegisteredAsAffiliate) { LoadModelUserInfo(model, acc); } } if (userRegisteredAsAffiliate) { return(Redirect(Url.RouteHccUrl(HccRoute.AffiliateDashboard))); } return(View(model)); }
public ActionResult Index() { var model = new AffiliateDashboardViewModel(); var aff = HccApp.ContactServices.Affiliates.FindByUserId(HccApp.CurrentCustomerId.ConvertTo <int>()); if (aff == null) { return(View((AffiliateDashboardViewModel)null)); } var affModel = new AffiliateViewModel(aff); LoadModel(affModel); FillRequiredFields(affModel); model.Affiliate = affModel; var range = new DateRange { RangeType = DefaultDateRange }; range.CalculateDatesFromType(DateTime.Now); var totals = HccApp.ContactServices.Affiliates.GetAffiliateTotals(aff.Id, new AffiliateReportCriteria { StartDateUtc = range.StartDate, EndDateUtc = range.EndDate }); var totalRowCount = 0; model.Orders = new AffiliateOrdersViewModel { Orders = GetOrders(aff, range.StartDate, range.EndDate, 1, 5, ref totalRowCount), TotalCount = totals.OrdersCount, TotalAmount = totals.SalesAmount.ToString("C") }; int totalPayments; model.Payments = new AffiliatePaymentsViewModel { Payments = GetPayments(aff, range.StartDate, range.EndDate, 1, 5, out totalPayments), TotalCount = totals.PaymentsCount, TotalAmount = totals.CommissionPaid.ToString("C") }; if (HccApp.CurrentStore.Settings.AffiliateDisplayChildren) { model.Affiliate.AllowReferral = true; var totalsReferrals = HccApp.ContactServices.Affiliates.GetTotalsByFilter(new AffiliateReportCriteria { ReferralAffiliateID = aff.AffiliateId, SearchBy = AffiliateReportCriteria.SearchType.AffiliateId, SearchText = null }, AffiliateRepository.TotalsReturnType.ReturnPayments); int totalReferals; model.Referrals = new AffiliateReferralsViewModel { Referrals = GetReferrals(aff, AffiliateReportCriteria.SearchType.AffiliateId, null, 1, 5, out totalReferals), TotalCount = totalReferals, TotalAmount = totalsReferrals.Commission.ToString("C") }; } //model.DefaultDateRange = (int)DefaultDateRange; model.UrlBuilder = new AffiliateUrlBuilderViewModel { AffiliateId = model.Affiliate.MyAffiliateId, Categories = GetCategoriesList(), RegistrationUrl = Url.RouteHccUrl(HccRoute.AffiliateRegistration) }; return(View(model)); }
private void FillRequiredFields(AffiliateViewModel model) { model.Password = "******"; model.ConfirmPassword = "******"; }