private bool HandleUpload(Stream fileStream, string name, int size, string type)
        {
            bool handled = false;

            try
            {
                byte[] documentBytes = new byte[fileStream.Length];
                fileStream.Read(documentBytes, 0, documentBytes.Length);

                Document databaseDocument = new Document
                {
                    CreatedOn   = DateTime.Now,
                    FileContent = documentBytes,
                    IsDeleted   = false,
                    Name        = name,
                    Size        = size,
                    Type        = type
                };

                using (Shopping_DBEntities4 databaseContext = new Shopping_DBEntities4())
                {
                    databaseContext.Documents.Add(databaseDocument);
                    handled = (databaseContext.SaveChanges() > 0);
                }
            }
            catch (Exception ex)
            {
                // Oops, something went wrong, handle the exception
            }

            return(handled);
        }
        public ActionResult zz(FormCollection fc, HttpPostedFileBase file)
        {
            var      context           = new Shopping_DBEntities4();
            Product1 tbl               = new Product1();
            var      allowedExtensions = new[] {
                ".Jpg", ".png", ".PNG", ".jpg", "jpeg"
            };

            tbl.Name        = fc["Id"].ToString();
            tbl.PictureName = file.ToString();                                        //getting complete url
            tbl.Name        = fc["Name"].ToString();
            var fileName = System.IO.Path.GetFileName(file.FileName);                 //getting only file name(ex-ganesh.jpg)
            var ext      = System.IO.Path.GetExtension(file.FileName);                //getting the extension(ex-.jpg)

            if (allowedExtensions.Contains(ext))                                      //check what type of extension
            {
                string name   = System.IO.Path.GetFileNameWithoutExtension(fileName); //getting file name without extension
                string myfile = name + ext;                                           //appending the name with id
                // store the file inside ~/project folder(Img)
                var path = System.IO.Path.Combine(Server.MapPath("~/UploadedFiles"), myfile);
                tbl.PictureName = "";
                tbl.isActive    = true;
                tbl.Name        = path;
                tbl.Price       = 12;
                context.Product1.Add(tbl);
                context.SaveChanges();
                file.SaveAs(path);
            }
            else
            {
                ViewBag.message = "Please choose only Image file";
            }
            return(View());
        }
        public JsonResult GetProductByUserId()
        {
            int pid = EAD_Project.Security.SessionManager.User.UserID; int total = 0;
            var prod = EAD_Project.BAL.ProductBO.GetProductByUserId(pid);

            foreach (var x in prod)
            {
                total = total + x.Price;
            }
            ViewBag.total      = total;
            ViewData["total"]  = total;
            Session["Product"] = prod;
            using (var context = new Shopping_DBEntities4())
            {
                var student = new DB.Bill_To
                {
                    UserID = EAD_Project.Security.SessionManager.User.UserID,
                    Total  = total
                };
                context.Bill_To.Add(student);
                context.SaveChanges();
            }
            var d = new
            {
                data = prod
            };

            return(Json(d, JsonRequestBehavior.AllowGet));
        }
 public ActionResult contact_us_save(Models.contact_us u)
 {
     //ViewBag.Message = "Your application description page.";
     ///// Models.contact_us u = new Models.contact_us();
     ///// Request.Form
     //u.name = Request.Form["name"];
     //u.email = Request.Form["email"];
     //u.subject = Request.Form["subject"];
     //u.message = Request.Form["message"];
     //var obj = BAL.contact_us.Save(u);
     DB.contact_us student = null;
     using (var context = new Shopping_DBEntities4())
     {
         student = new DB.contact_us
         {
             name    = Request.Form["name"],
             email   = Request.Form["email"],
             subject = Request.Form["subject"],
             message = Request.Form["message"]
         };
         context.contact_us.Add(student);
         context.SaveChanges();
     }
     if (student != null)
     {
         //FlashMessage.Warning("Your error message");
         //return RedirectToAction("AdminUsers", "Admin");
         return(Content("<script>alert('message sent successfully');document.location='contact_us'</script>"));
         // return Content("<script language='javascript' type='text/javascript'>alert('message sent successfully !!');</script>");
     }
     else
     {
         return(Content("<script>alert('message not sent successfully');document.location='contact_us'</script>"));
     }
 }
        public ActionResult Bill_To(Models.Bill_To u)
        {
            using (var context = new Shopping_DBEntities4())
            {
                var student = (from d in context.Bill_To
                               where d.UserID == SessionManager.User.UserID
                               select d).ToList();
                var total  = 0;
                var total1 = student.ToList();
                foreach (var x in total1)
                {
                    total = (Int32)x.Total;
                }
                ViewBag.total     = total;
                ViewData["total"] = total;
                foreach (var no in total1)
                {
                    if (no != null)
                    {
                        no.Display_Name     = u.Display_Name;
                        no.User_Name        = u.User_Name;
                        no.Password         = u.Password;
                        no.confirm_password = u.confirm_password;
                        no.Company_Name     = u.Company_Name;
                        no.Email            = u.Email;
                        no.Title            = u.Title;
                        no.First_Name       = u.First_Name;
                        no.Middle_Name      = u.Middle_Name;
                        no.Last_Name        = u.Last_Name;
                        no.Address_1        = u.Address_1;
                        no.Address_2        = u.Address_2;
                        no.Zip      = u.Zip;
                        no.Country  = u.Country;
                        no.State    = u.State;
                        no.Phone1   = u.Phone1;
                        no.Phone2   = u.Phone2;
                        no.Fax      = u.Mobile_Phone;
                        no.Email    = u.Fax;
                        no.message  = u.message;
                        no.Shipping = u.Shipping;
                        context.SaveChanges();
                        var data = new
                        {
                            success = true
                        };
                        return(Content("<script>alert('checkout successful!!!'); var data = new{success = true; document.location='NormalUser'</script>"));
                    }
                    else
                    {
                        return(View());
                    }
                }

                return(View());
            }
        }
 private static void DeleteStudent(User u)
 {
     using (var context = new Shopping_DBEntities4())
     {
         var bay = (from d in context.Users
                    where d.UserID == u.UserID
                    select d).Single();
         context.Users.Remove(bay);
         context.SaveChanges();
     }
 }
        private static void ChangeStudent(User u)
        {
            using (var context = new Shopping_DBEntities4())
            {
                var student = (from d in context.Users
                               where d.UserID == u.UserID && d.Login == u.Login
                               select d).Single();

                student.Password = "******";
                context.SaveChanges();
            }
        }
 public ActionResult feedBackServlet(Models.feedback u)
 {
     using (var context = new Shopping_DBEntities4())
     {
         var student = new DB.feedback
         {
             email   = u.email,
             message = u.message,
         };
         context.feedbacks.Add(student);
         context.SaveChanges();
         return(Content("<script>alert('Thanks for ur feedback!!');document.location='About'</script>"));
     }
 }
 private static void AddStudent(User u)
 {
     using (var context = new Shopping_DBEntities4())
     {
         var student = new User
         {
             Name        = u.Name,
             Login       = u.Name,
             Password    = u.Password,
             PictureName = u.PictureName,
             Designation = u.Designation,
             Email       = u.Email,
             isAdmin     = false,
             isActive    = true
         };
         context.Users.Add(student);
         context.SaveChanges();
     }
 }
        public /*JsonResult*/ ActionResult SaveUsers(User u)
        {
            string password  = Request["password1"];
            string password2 = Request["cn_password"];

            if (password != password2)
            {
                return(Content("<script>alert('Password mismatch!!!');var data = new{success = false};document.location='login'</script>"));
            }

            var uniqueName = "";

            if (Request.Files["Image"] != null)
            {
                var file = Request.Files["Image"];
                if (file.FileName != "")
                {
                    var ext = System.IO.Path.GetExtension(file.FileName);

                    //Generate a unique name using Guid
                    uniqueName = Guid.NewGuid().ToString() + ext;

                    //Get physical path of our folder where we want to save images
                    // var rootPath = Server.MapPath("~/UploadedFiles");
                    var rootPath = "C:/Users/Tayyibah/Documents/GitHub/E-Shopper/EAD_Project/UploadedFiles";

                    var fileSavePath = System.IO.Path.Combine(rootPath, uniqueName);

                    // Save the uploaded file to "UploadedFiles" folder
                    file.SaveAs(fileSavePath);

                    u.PictureName = uniqueName;
                }
            }
            using (var context = new Shopping_DBEntities4())
            {
                var student = new DB.User
                {
                    Name        = u.Name,
                    Login       = u.Name,
                    Password    = password,
                    isAdmin     = false,
                    isActive    = true,
                    PictureName = u.PictureName,
                    Designation = u.Designation,
                    Email       = u.Email
                };
                context.Users.Add(student);
                context.SaveChanges();
                var data = new
                {
                    success = true,
                    //ProductID = pid,
                    //PictureName = u.PictureName
                };
                if (student != null)
                {
                    // return Json(data, JsonRequestBehavior.AllowGet); return Json(data, JsonRequestBehavior.AllowGet);
                    return(Content("<script>alert('thanks for registering!!!'); var data = new{success = true}; document.location='NormalUser'</script>"));
                }
                // return View();
                else
                {
                    return(Content("<script>alert('registering unsuccessful!!!'); var data = new{success = false}; document.location='NormalUser'</script>"));
                }
            }
            //   return Content("<script>alert('registering unsuccessful!!!'); var data = new{success = false}; document.location='NormalUser'</script>");
        }