Exemplo n.º 1
0
 public ActionResult Create([Bind(Include = "CustomerName")] CustomerViewModel customer)
 {
     if (ModelState.IsValid)
     {
         // Instantiate class
         var csp = new Helpers.PartnerCenter();
         // Creat new customer
         string customerId  = csp.CreateCspCustomer(customer.CustomerName, CreateSubscription: true);
         var    newCustomer = new Models.Customer();
         newCustomer.OwnerId      = User.Identity.GetUserId();
         newCustomer.CustomerId   = customerId;
         newCustomer.CustomerName = customer.CustomerName;
         db.Customers.Add(newCustomer);
         // Create new subscription
         string subscriptionId  = csp.CreateCspSubscription(customerId);
         var    newSubscription = new Models.Subscription();
         newSubscription.CustomerId     = customerId;
         newSubscription.SubscriptionId = subscriptionId.ToLower();
         db.Subscriptions.Add(newSubscription);
         // Exit
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(Index());
 }
Exemplo n.º 2
0
        public ActionResult MyCustomer()
        {
            var userId       = User.Identity.GetUserId();
            var csp          = new Helpers.PartnerCenter();
            var allCustomers = csp.GetCspCustomers();

            return(View(allCustomers));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    // Create immediately a customer ID and a subscription for the new user
                    string customerName = user.Email;
                    string userId       = user.Id;
                    // Instantiate class
                    var csp = new Helpers.PartnerCenter();
                    // Create new customer
                    string customerId = await csp.CreateCspCustomerAsync(customerName, CreateSubscription : false);

                    var newCustomer = new Models.Customer();
                    newCustomer.OwnerId      = userId;
                    newCustomer.CustomerId   = customerId;
                    newCustomer.CustomerName = customerName;
                    db.Customers.Add(newCustomer);
                    // Create new subscription
                    string subscriptionId = await csp.CreateCspSubscriptionAsync(customerId);

                    var newSubscription = new Models.Subscription();
                    newSubscription.CustomerId     = customerId;
                    newSubscription.SubscriptionId = subscriptionId.ToLower();
                    db.Subscriptions.Add(newSubscription);

                    // Exit
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult Index()
        {
            var csp = new Helpers.PartnerCenter();

            if (User.IsInRole("Admin"))
            {
                // We can either get the customers from the CSP API
                //var allCustomers = csp.GetCspCustomers();
                // Or from the DB :-)
                var allCustomers = db.Customers.ToList();
                return(View(allCustomers));
            }
            else
            {
                var customerList = new List <Models.Customer>();
                //We can either get the customers from the CSP API
                //foreach (var customer in db.Customers)
                //{
                //    if (customer.OwnerId == User.Identity.GetUserId()) {
                //        var thisCustomer = csp.GetUserCspCustomers(customer.CustomerId);
                //        customerList.Add(thisCustomer);
                //    }
                //}

                // Or from the DB
                string userId = User.Identity.GetUserId();
                customerList = db.Customers.Where(c => c.OwnerId == userId).ToList();
                if (customerList.Count > 0)
                {
                    return(View(customerList));
                }
                else
                {
                    // If no customer was found for this User Id
                    return(RedirectToAction("Create"));
                }
            }
        }