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)); }
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()); }
// DB.contact_us. student = (DB.contact_us)u; //// student.StudentName = "Student1"; // using (var ctx = new Shopping_DBEntities5()) // { // ctx.contact_us.Add(u); // ctx.SaveChanges(); // } public ActionResult checkout() { // 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; //} 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; } return(View()); }
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 ValidateUser(User userr /*String login, String password*/) { using (Shopping_DBEntities4 db = new Shopping_DBEntities4()) { var get_user = db.Users.Single(p => p.Name == userr.Name && p.Password == userr.Password); if (get_user != null) { Session["UserID"] = get_user.UserID.ToString(); // Session["UserName"] = get_user.UserName.ToString(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "UserName or Password does not match."); } } return(View()); //Object data = null; //try //{ // var url = ""; // var flag = false; // var obj = BAL.UserBO.ValidateUser(login, password); // if (obj != null) // { // flag = true; // //SessionManager.User = obj; // //if (obj.UsersType == 1) // // url = Url.Content("~/Home/Admin"); // //else // // url = Url.Content("~/Home/NormalUser"); // SessionManager.User = obj; // if (obj.IsAdmin/*.UsersType == 1*/) // url = Url.Content("~/Home/Admin"); // else // url = Url.Content("~/Home/NormalUser"); // } // data = new // { // valid = flag, // urlToRedirect = url // }; //} //catch (Exception) //{ // data = new // { // valid = false, // urlToRedirect = "" // }; //} //return Json(data, JsonRequestBehavior.AllowGet); }
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 byte[] LoadImage(int id, out string type) { byte[] fileBytes = null; string fileType = null; using (Shopping_DBEntities4 databaseContext = new Shopping_DBEntities4()) { var databaseDocument = databaseContext.Documents.FirstOrDefault(doc => doc.DocumentId == id); if (databaseDocument != null) { fileBytes = databaseDocument.FileContent; fileType = databaseDocument.Type; } } type = fileType; return(fileBytes); }
private static Boolean ValidateUser(User u) { using (var context = new Shopping_DBEntities4()) { var student = (from d in context.Users where d.Password == u.Password && d.Name == u.Name select d).Single(); if (student != null) { return(true); } else { return(false); } } }
public ActionResult Login(EAD_Project.PMS.Entities.UserDTO u) { Shopping_DBEntities4 db = new Shopping_DBEntities4(); var query = from d in db.Users where (d.Password == u.Password && d.Name == u.Name) select d; if (query != null) { var q = query.ToList(); foreach (var x in q) { u.IsAdmin = (bool)x.isAdmin; } Models.UserDTO result = new Models.UserDTO(); result.IsAdmin = u.IsAdmin; EAD_Project.PMS.Entities.UserDTO obj = UserBO.ValidateUser(u.Name, u.Password); foreach (var x in q) { if (query != null) { Session["User"] = obj; if (result.IsAdmin) { //return Redirect("~/Home/Admin"); return(RedirectToAction("Admin")); } else { return(RedirectToAction("NormalUser")); } } } //else //{ ViewBag.MSG = "Invalid Login/Password"; ViewBag.Login = u.Login; ModelState.AddModelError("", "UserName or Password does not match."); // return RedirectToAction("Login"); return(Content("<script>alert('invalid user name or password');document.location='Login'</script>")); //} } return(Content("<script>alert('invalid user name or password');document.location='Login'</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 ActionResult Bill_To() { using (var context = new Shopping_DBEntities4()) { var student = (from d in context.Bill_To where d.UserID == SessionManager.User.UserID select d).Single(); var total = 0; total = (Int32)student.Total; } Models.Bill_To u = new Models.Bill_To(); u.Company_Name = Request["Company_Name"]; u.Email = Request["Email"]; u.Title = Request["Title"]; u.First_Name = Request["First_Name"]; u.Middle_Name = Request["Middle_Name"]; u.Last_Name = Request["Last_Name"]; u.Address_1 = Request["Address_1"]; u.Address_2 = Request["Address_2"]; u.Zip = Request["Zip"]; u.Country = Request["Country"]; u.State = Request["State"]; u.Phone1 = Request["Confirm_password"]; u.Phone2 = Request["Phone"]; u.Fax = Request["Mobile_Phone"]; u.Email = Request["Fax"]; u.message = Request["message"]; u.Shipping = Request["Shipping"]; var obj = BAL.Bill_To.Save(u); if (obj > 0) { return(Content("<script>alert('checkout successful!!!');document.location='NormalUser'</script>")); } else { return(View()); } }
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>"); }