public CustomerSummaryViewModel(Customer cust)
        {
            Customer = cust;
            TotalRequests = cust.Requests.Count();
            CompletedReviews = cust.Reviews.Where(x => x.Reviewed.Equals(true)).Count();
            OpenReviews = cust.Reviews.Where(x => x.Reviewed.Equals(false)).Count();
            VideoReviews = cust.Reviews.Where(x => x.Reviewed.Equals(true) && x.VideoReview.Equals(true)).Count();
            PhotoReviews = cust.Reviews.Where(x => x.Reviewed.Equals(true) && x.PhotoReview.Equals(true)).Count();

            int stars = 0;
            int words = 0;
            int count = 0;
            foreach(var r in cust.Reviews.Where(x => x.Reviewed.Equals(true)))
            {
                count = count += 1;
                stars = stars + r.ProductRating.GetValueOrDefault();
                words = words + r.ReviewLength;
            }
            if (count > 0)
            {
                AvgWordCount = words / count;
                AvgProductRating = stars / count;
            }

        }
Beispiel #2
0
        public ActionResult Edit(Customer customer)
        {
            //public ActionResult Edit(Customer customer, bool idchanged, string newid)
            //DOES NOT ACTUALLY RESULT IN CHANGES CURRENTLY.
            //Sooooooooooooooo, this needs to go to account controller and update ApplicationUser primary key.
            //    But I'm reading that this needs to be done with SQL stored procedures. The code below results 
            //in concurrency error because you can't update record that doesn't exist.
            //also, we would need to update Reviews and Item Requests and UserRole on an ID change. Ugh.

            //if (idchanged){
            //    try
            //    {
            //        ParsedFeed profilecheck = new ParsedFeed(newid);
            //    }
            //    catch
            //    {
            //        ViewBag.Error = "There is a problem with that Amazon Profile ID. Please check and try again.";
            //        return View(customer);
            //    }
            //    bool check = new AccountController().EditAmazonID(customer.CustomerID, newid);
            //    customer.CustomerID = newid;
            //}

            if (ModelState.IsValid)
            {
                db.Entry(customer).State = EntityState.Modified;
                db.SaveChanges();
                ApplicationUser user = (from a in appdb.Users
                                        where a.CustomerID == customer.CustomerID
                                        select a).First();

                if (customer.Email != user.Email)
                {
                    bool check = new AccountController().EditEmail(customer.Email, customer.CustomerID);
                }
                return RedirectToAction("Index");
            }
            return View(customer);
        }
Beispiel #3
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)

            { 
                 return RedirectToAction("Index", "Dashboard");
            }
            //Check to see if we can read their profile RSS feed. If not, then id is invalid. Return to page and ask again.
            try
            {
                ParsedFeed profilecheck = new ParsedFeed(model.CustomerID);
            }
            catch
            {
                ViewBag.Error = "There is a problem with that Amazon Profile ID. Please check and try again.";
                ViewBag.ReturnUrl = returnUrl;
                return View(model);
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.CustomerID, Email = model.Email, CustomerID = model.CustomerID };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "customer");

                        //We're not logging in customer until they verify email
                        //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                        Customer customer = new Customer();
                        customer.Email = model.Email;
                        customer.FirstName = model.FirstName;
                        customer.LastName = model.LastName;
                        customer.CustomerID = model.CustomerID;
                        customer.LastReviewCheck = DateTime.Now;
                        customer.JoinDate = DateTime.Now;
                        customer.Qualified = true;
                        db.Customers.Add(customer);
                        db.SaveChanges();

                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                        var response = SendEmailConfirmation(user.Email, callbackUrl, false);

                        // Uncomment to debug locally 
                        // TempData["ViewBagLink"] = callbackUrl;



                        return RedirectToAction("Welcome", "Dashboard", new { message = "confirmmail" });

                        //return RedirectToAction("Welcome", "Dashboard");

                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
 //This constructor is for one individual customer. Called on Customer/Dashboard controller
 public CheckForCompletedReviews(Customer customer)
 {
     CustomersToCheck = new List<string> { };
     CustomersToCheck.Add(customer.CustomerID);
 }
Beispiel #5
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            //Check to see if we can read their profile RSS feed. If not, then id is invalid. Return to page and ask again.
            try
            {
                ParsedFeed profilecheck = new ParsedFeed(model.CustomerID);
            }
            catch
            {
                ViewBag.Error = "There is a problem with that Amazon Profile ID. Please check and try again.";
                return View("Register", model);
            }

            if (db.Customers.Where(u => u.CustomerID == model.CustomerID).Any())
            {
                ViewBag.Error = "That Amazon Profile ID is already in use.";
                return View("Register", model);
            }


            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.CustomerID, Email = model.Email, CustomerID = model.CustomerID };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    //We will not sign in customer immediately. They have to confirm email.
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    Customer customer = new Customer();
                    customer.Email = model.Email;
                    customer.FirstName = model.FirstName;
                    customer.LastName = model.LastName;
                    customer.CustomerID = model.CustomerID;
                    customer.LastReviewCheck = DateTime.Now;
                    customer.JoinDate = DateTime.Now;
                    customer.Qualified = true;
                    db.Customers.Add(customer);
                    db.SaveChanges();

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Email Confirmation
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                    var response = SendEmailConfirmation(user.Email, callbackUrl, false);

                    // Uncomment to debug locally 
                    // TempData["ViewBagLink"] = callbackUrl;

                    if (model.BeSeller)
                    {
                        await UserManager.AddToRoleAsync(user.Id, "seller");
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToAction("CreateSeller", "Seller");
                    }
                    else
                    {
                        //use this for TESTING ONLY
                        //await UserManager.AddToRoleAsync(user.Id, "campaignManager");

                        ////USE THIS FOR LIVE SITE
                        await UserManager.AddToRoleAsync(user.Id, "customer");
                    }

                    return RedirectToAction("Welcome", "Dashboard", new { message = "confirmmail" });

                    //return RedirectToAction("Welcome", "Dashboard");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }