public ActionResult AccountOptions() { TempData["SelectedMenu"] = "Account"; TempData["SelectedSubMenu"] = "Options"; User userObj = (User)Session["user"]; Account accountObj = (Account)Session["account"]; if (userObj.PrimaryUser == false) return RedirectToAction("Index", "Admin"); AccountInfomationViewModel accountinfor = new AccountInfomationViewModel(); //get time zone System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> tz; tz = TimeZoneInfo.GetSystemTimeZones(); List<TimeZoneViewModel> tzList = new List<TimeZoneViewModel>(); foreach (var t in tz) { TimeZoneViewModel tzvmodel = new TimeZoneViewModel(); tzvmodel.DisplayName = t.DisplayName; tzvmodel.ID = t.Id; tzList.Add(tzvmodel); } accountinfor.TimeZoneList = tzList; if (userObj != null) { var account = accountRepo.Accounts.Where(aid => aid.ID == userObj.AccountID).FirstOrDefault(); accountinfor.AccountName = account.AccountName; accountinfor.ContactName = userObj.FullName; accountinfor.EmailAddress = userObj.Email; accountinfor.TimeZone = account.TimeZone; accountinfor.BillingAddress = account.BusinessAddress; //get numberof connection int planid = account.PlanID; int planLevel = planid * 10; //get billing plan var billingPlan = planRepository.Plans.Where(pid => pid.ID == planid).FirstOrDefault(); accountinfor.BillingPlan = billingPlan.Name; // get saved quantity var accDetails = accountRepo.Accounts.Where(aguid => aguid.AccountGUID == accountObj.AccountGUID).FirstOrDefault(); var planLeval = planRepository.Plans.Where(pid => pid.ID == accDetails.PlanID).FirstOrDefault().PlanLevel; var featureQuality = featureRepository.Features.Where(pid => pid.PlanLevel == planLeval & pid.Type == "Max Items per Folder").FirstOrDefault(); var savedQuality = purchRepository.Purchases.Where(fid => fid.FeatureID == featureQuality.ID && fid.AccountGUID == accountObj.AccountGUID).FirstOrDefault(); if (savedQuality != null) { var quantitySaved = (savedQuality.Quantity) / (featureQuality.Quantity); accountinfor.NoOfConnection = quantitySaved * 5; } else { accountinfor.NoOfConnection = 0; } accountinfor.ListofUsers = new List<Domain.Entities.User>(); accountinfor.ListofUsers = userRepository.Users.Where(u => u.AccountID == userObj.AccountID).ToList(); //var errorLogsObj = CCErrorLogRepository.CCErrorLogs.Where(guid => guid.AccountGUID == accountObj.AccountGUID & (guid.ErrorType == "Exchange Connection" | guid.ErrorType == "Sync")).Take(100).ToList(); accountinfor.ErrorLogList = new List<CCErrorLog>(); //accountinfor.ErrorLogList = errorLogsObj; var plans = planRepository.Plans.ToList(); // plans.RemoveAll(pname => pname.Name == "Free"); accountinfor.Plans = plans; // get selected plan var planID = accountRepo.Accounts.FirstOrDefault(aguid => aguid.AccountGUID == accountObj.AccountGUID).PlanID; accountinfor.PlanID = planID; // get selected plan details var selectedPlanDetails = plans.FirstOrDefault(pid => pid.ID == planID); selectedPlanDetails.Price = selectedPlanDetails.Price; //packageViewModel.SelectedPlanDetails = selectedPlanDetails; // get card details from stripe var stripeCustomerID = accountRepo.Accounts.FirstOrDefault(aguid => aguid.AccountGUID == accountObj.AccountGUID).StripeCustomerID; if (stripeCustomerID != null) { // default card details var customer = new StripeCustomerService(); customer.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var cusRes = customer.Get(stripeCustomerID); var defaultCardID = cusRes.StripeDefaultCardId; //packageViewModel.DefaultCardID = defaultCardID; // get saved quantity featureQuality = featureRepository.Features.FirstOrDefault(pid => pid.PlanLevel == selectedPlanDetails.PlanLevel & pid.Type == "Max Items per Folder"); savedQuality = purchRepository.Purchases.FirstOrDefault(fid => fid.FeatureID == featureQuality.ID && fid.AccountGUID == accountObj.AccountGUID); if (savedQuality != null) { var quantitySaved = (savedQuality.Quantity) / (featureQuality.Quantity); accountinfor.QuantitySaved = quantitySaved; } else { accountinfor.QuantitySaved = 1; } var cards = new StripeCardService(); cards.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var objCard = cards.List(stripeCustomerID, null); List<CardViewModel> allCardDetails = new List<CardViewModel>(); foreach (var card in objCard) { CardViewModel objcard = new CardViewModel(); objcard.CardID = card.Id; objcard.Name = card.Name; objcard.Number = "**** " + card.Last4; objcard.Type = card.Brand; objcard.ExpireDate = card.ExpirationYear + "/" + card.ExpirationMonth; allCardDetails.Add(objcard); } //packageViewModel.CardDetails = allCardDetails; } else { //packageViewModel.CardDetails = null; } } return View(accountinfor); }
public ActionResult BillingOptions(int id) { TempData["SelectedMenu"] = "Account"; TempData["SelectedSubMenu"] = "Billing"; User userObj = (User)Session["user"]; Account accountObj = (Account)Session["account"]; if (userObj.PrimaryUser == false) return RedirectToAction("Index", "Admin"); decimal additionalPrice = 0; //TempData["SelectedMenu"] = "Subscription"; List<List<string>> typeListObj = new List<List<string>>(); PackageViewModel packageViewModel = new PackageViewModel(); //trial Data if (Session["trialData"] != null) { TrialDataModel trialObj = (TrialDataModel)Session["trialData"]; packageViewModel.trialObj = trialObj; } //get all plans var plans = planRepository.Plans.ToList(); // plans.RemoveAll(pname => pname.Name == "Free"); packageViewModel.Plans = plans; // get all types //var types = featureRepository.Features.Where(p => p.Price == 0).Select(f => f.Type).Distinct().ToList(); List<string> types = new List<string>(); types.Add("Sync Contacts"); types.Add("Sync Calendar"); types.Add("Sync Period"); //types.Add("Contacts Sync"); //types.Add("Calendar Sync"); //types.Add("Connections"); types.Add("Max Items per Folder"); types.Add("Fields Available"); types.Add("History Tracking"); types.Add("Third Party Connections"); packageViewModel.Types = types; // get selected plan var planID = accountRepo.Accounts.FirstOrDefault(aguid => aguid.AccountGUID == accountObj.AccountGUID).PlanID; packageViewModel.PlanID = planID; // get selected plan details var selectedPlanDetails = plans.FirstOrDefault(pid => pid.ID == planID); selectedPlanDetails.Price = selectedPlanDetails.Price; packageViewModel.SelectedPlanDetails = selectedPlanDetails; // run all plans foreach (var pln in plans) { var allFeatures = featureRepository.Features.Where(pl => pl.PlanLevel == pln.PlanLevel).ToList(); List<string> typesList = new List<string>(); foreach (var typ in types) { var res = allFeatures.FirstOrDefault(t => t.Type == typ); if (res != null) { typesList.Add(res.Name); } else { typesList.Add("-"); } } typeListObj.Add(typesList); } packageViewModel.Names = typeListObj; // get card details from stripe var stripeCustomerID = accountRepo.Accounts.FirstOrDefault(aguid => aguid.AccountGUID == accountObj.AccountGUID).StripeCustomerID; if (stripeCustomerID != null) { // default card details var customer = new StripeCustomerService(); customer.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var cusRes = customer.Get(stripeCustomerID); var defaultCardID = cusRes.StripeDefaultCardId; packageViewModel.DefaultCardID = defaultCardID; // get saved quantity var featureQuality = featureRepository.Features.FirstOrDefault(pid => pid.PlanLevel == selectedPlanDetails.PlanLevel & pid.Type == "Max Items per Folder"); var savedQuality = purchRepository.Purchases.FirstOrDefault(fid => fid.FeatureID == featureQuality.ID && fid.AccountGUID == accountObj.AccountGUID); if (savedQuality != null) { var quantitySaved = (savedQuality.Quantity) / (featureQuality.Quantity); packageViewModel.QuantitySaved = quantitySaved; } else { packageViewModel.QuantitySaved = 1; } var cards = new StripeCardService(); cards.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp"; var objCard = cards.List(stripeCustomerID, null); List<CardViewModel> allCardDetails = new List<CardViewModel>(); foreach (var card in objCard) { CardViewModel objcard = new CardViewModel(); objcard.CardID = card.Id; objcard.Name = card.Name; objcard.Number = "**** " + card.Last4; objcard.Type = card.Brand; objcard.ExpireDate = card.ExpirationYear + "/" + card.ExpirationMonth; allCardDetails.Add(objcard); } packageViewModel.CardDetails = allCardDetails; } else { packageViewModel.CardDetails = null; } // End get card details if (id == 2) { ViewBag.MessagePass = "******"; } else { ViewBag.MessagePass = ""; } return View(packageViewModel); }