//add the selected item to cart table
        public ActionResult AddtoCart(int id)
        {
            SellProductDetail prod = db.SellProductDetails.SingleOrDefault(p => p.ItemID == id);
            var cartItem           = db.CartDetails.SingleOrDefault(c => c.ItemID == id);

            if (cartItem == null)
            {
                cartItem = new CartDetail     //saves the selected item to cart table based on item id
                {
                    ItemID   = prod.ItemID,
                    Count    = 1,
                    SellerID = Session["id"].ToString()
                               //SellerID = "1234"
                };
                db.CartDetails.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Count++;
                db.Entry(cartItem).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
            return(RedirectToAction("Viewcart", "Home", new { id = cartItem.ItemID })); //redirects to viewcart and display details of selected products
        }
 public ActionResult SellProduct(SellProductDetail sdet, HttpPostedFileBase image)
 {
     try
     {
         var db = new ShoppingAppFBEntities2();
         sdet.ItemImage = new byte[image.ContentLength];
         image.InputStream.Read(sdet.ItemImage, 0, image.ContentLength); //convert image to varbinary format in database
         sdet.SellerID = Session["id"].ToString();
         db.SellProductDetails.Add(sdet);                                //saves data to the database
         db.SaveChanges();
     }
     catch (DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 Trace.TraceInformation("Property: {0} Error: {1}",
                                        validationError.PropertyName,
                                        validationError.ErrorMessage);
             }
         }
     }
     return(View(sdet));
 }
        public async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                return(RedirectToAction("Login"));
            }
            if (loginInfo.Login.LoginProvider == "Facebook")
            {
                var identity     = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
                var access_token = identity.FindFirstValue("FacebookAccessToken");
                //  var dob = identity.Equals("user_birthday");
                var     fb     = new FacebookClient(access_token);
                dynamic myInfo = fb.Get("/me?fields=email,first_name,id");
                string  email  = myInfo.email;
                string  name   = myInfo.first_name;
                string  id     = myInfo.id;

                //var id = myInfo.id;
                Session["email"]    = email;
                Session["name"]     = name;
                Session["id"]       = id;
                Session["SellerID"] = id;
                UserDetail det = new UserDetail(); //save user details to database

                using (var db = new ShoppingAppFBEntities2())
                {
                    var results = (from c in db.UserDetails where c.UserID == id select c).SingleOrDefault();
                    if (results == null)
                    {
                        det.UserEmail = email;
                        det.UserName  = name;
                        det.UserID    = id;
                        db.UserDetails.Add(det);
                        db.SaveChanges();
                    }
                }
            }


            // Sign in the user with this external login provider if the user already has a login
            var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }));

            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl     = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                return(View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel {
                    Email = loginInfo.Email
                }));
            }
        }