public User Add(User obj) { var user = Db.Users.Add(obj); Db.SaveChanges(); return(user); }
public ActionResult EditSubmit(int?id, string name, decimal price, string about, List <HttpPostedFileBase> imgFiles) { var findProduct = db.products.Find(id); findProduct.Name = name; findProduct.Price = price; findProduct.About = about; if (imgFiles[0] != null) { string SaveLocation = ""; foreach (var file in imgFiles) { string fileName = Path.GetFileName(file.FileName); SaveLocation = Server.MapPath("~/Template/img/newImg/") + "\\" + fileName; try { var newImgPath = new imageProduct(); newImgPath.ProductId = findProduct.Id; newImgPath.imgPath = fileName; newImgPath.CreatedDate = DateTime.Now; db.imageProducts.Add(newImgPath); file.SaveAs(SaveLocation); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } } db.Entry(findProduct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("newAddProduct", "Admin")); }
public IActionResult Pay(int id) { { if (User.Identity.IsAuthenticated) { var userName = User.Identity.Name; var model = _userManager.Users.FirstOrDefault(x => x.UserName == userName); var basket = _context.Baskets.Find(id); var pay = _context.Payments.FirstOrDefault(x => x.UserId == model.Id && x.BasketId == id); if (model != null) { var addBasket = new Payment { UserId = model.Id, BasketId = basket.Id, ProductId = basket.ProductId, Name = basket.Name, Quantity = basket.Quantity, TotalFee = basket.TotalFee, Date = DateTime.Now }; _context.Payments.Add(addBasket); TempData["message"] = "Seçtiğiniz " + addBasket.Name + " ismindeki ürün satın alınmıştır."; _context.SaveChanges(); } } return(RedirectToAction("Index")); } }
public IActionResult Create(int id) { if (User.Identity.IsAuthenticated) { var userName = User.Identity.Name; var model = _userManager.Users.FirstOrDefault(x => x.UserName == userName); var product = _context.Products.Find(id); var basket = _context.Baskets.FirstOrDefault(x => x.UserId == model.Id && x.ProductId == id); if (model != null) { if (basket != null) { basket.Quantity++; basket.TotalFee = product.Price * basket.Quantity; _context.SaveChanges(); return(RedirectToAction("Index")); } var addBasket = new Basket { UserId = model.Id, ProductId = product.Id, Quantity = 1, Name = product.Name, Price = product.Price, TotalFee = product.Price, Date = DateTime.Now }; _context.Baskets.Add(addBasket); _context.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Name,About,Adress,imgPath,CreatedDate,CreatedId,ModifiedDate,ModifiedId,DeletedDate,DeletedId")] shoppingAdresses shoppingAdresses, HttpPostedFileBase imgPath) { if (ModelState.IsValid) { string SaveLocation = ""; if (imgPath != null) { string fileName = Path.GetFileName(imgPath.FileName); SaveLocation = Server.MapPath("~/Template/img/Adresses/") + "\\" + fileName; try { shoppingAdresses.imgPath = fileName; imgPath.SaveAs(SaveLocation); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } shoppingAdresses.CreatedDate = DateTime.Now; db.shoppingAdresses.Add(shoppingAdresses); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shoppingAdresses)); }
public IActionResult Create(Product shopping) { try { if (ModelState.IsValid) { if (shopping.PictureFolder != null) { string folder = "pictures/"; folder += Guid.NewGuid().ToString() + "_" + shopping.PictureFolder.FileName; shopping.PictureWay = "/" + folder; string serverFolder = Path.Combine(_environment.WebRootPath, folder); shopping.PictureFolder.CopyTo(new FileStream(serverFolder, FileMode.Create)); } _context.Products.Add(shopping); TempData["Create"] = shopping.Name + " " + " ürün eklendi."; _context.SaveChanges(); return(RedirectToAction("Index", new { id = shopping.CategoryId })); } } catch (Exception) { } return(View(shopping)); }
// starlevel public ActionResult increseStarLevel(int id, int rate) { var find= db.rating.Where(w => w.DeletedDate == null && w.Product.Id == id).FirstOrDefault(); if (find!=null) { find.starCount += 1; find.totalStarLevel += rate; find.currentStar = rate; int starLevel = calculatorRating.calStar(find.starCount, find.totalStarLevel); find.Product.starLevel = starLevel; db.Entry(find).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction($"itemPage/{id}"); } else { Rating newRating = new Rating(); newRating.ProductId = id; newRating.starCount += 1; newRating.currentStar = rate; newRating.totalStarLevel += rate; newRating.CreatedDate = DateTime.Now; db.rating.Add(newRating); db.SaveChanges(); } return RedirectToAction($"itemPage/{id}"); }
public ActionResult Create([Bind(Include = "ID,Password,FullName,Email,Address,Tel")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categorys.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult deleteCategory(int?id) { var checkSession = Session[SessionKey.Admin]; var admin = db.Manager.Where(w => w.Email.ToString() == checkSession.ToString()).FirstOrDefault(); var findcategory = db.categories.Where(w => w.DeletedDate == null && w.Id == id).FirstOrDefault(); findcategory.DeletedDate = DateTime.Now; findcategory.DeletedId = admin.Id; db.Entry(findcategory).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(PartialView("~/Areas/Admin/Views/CategoryColorCompany/refleshPage.cshtml")); }
public ActionResult Create(SubCategory subcategory) { if (ModelState.IsValid) { db.SubCategories.Add(subcategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", subcategory.CategoryId); return(View(subcategory)); }
public ActionResult Create([Bind(Include = "Id,CustomerId,OrderDate,RequireDate,Receiver,Address,Description,Amount")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "ID", "Password", order.CustomerId); return(View(order)); }
public ActionResult lookAtMessage(int?id) { var currentMessage = db.ContactUs.Where(w => w.DeletedDate == null && w.Id == id).FirstOrDefault(); if (currentMessage.isRead == false) { currentMessage.isRead = true; db.Entry(currentMessage).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } var allMessages = db.ContactUs.OrderByDescending(w => w.Id).Where(w => w.DeletedDate == null).ToList(); return(Json(currentMessage, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", product.CategoryId); ViewBag.SubCategoryId = new SelectList(db.SubCategories, "SubCategoryId", "SubCategoryName", product.SubCategoryId); ViewBag.ModelId = new SelectList(db.Models, "ModelId", "ModelName", product.ModelId); return(View(product)); }
private void SeedGenres() { SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreLatin); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreSchlager); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreJazz); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreRenB); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreRock); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenrePop); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreElectricShopping); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreFolk); SeedGenreIfNotExists(_dbContext, ShoppingDataObjectsValues.GenreDutch); _dbContext.SaveChanges(); }
public ActionResult Create(Image image) { if (ModelState.IsValid) { db.Images.Add(image); db.SaveChanges(); return(RedirectToAction("List")); } ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", image.CategoryId); ViewBag.SubCategoryId = new SelectList(db.SubCategories, "SubCategoryId", "SubCategoryName", image.SubCategoryId); ViewBag.ModelId = new SelectList(db.Models, "ModelId", "ModelName", image.ModelId); ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", image.ProductId); return(View(image)); }
public ActionResult clickLike(int productId) { if (Session[SessionKey.User] != null) { int currentUserId = 0; var users = db.user.Where(w => w.DeletedDate == null && w.isBlock == false).ToList(); foreach (var item in users) { if (item.Email.ToString() == Session[SessionKey.User].ToString()) { currentUserId = item.Id; } } var product = db.products.Where(w => w.DeletedDate == null && w.isConfirm == true && w.Id == productId).FirstOrDefault(); var checkUser = db.Likes.Where(w => w.DeletedDate == null && w.ProductId == productId && w.UserId == currentUserId).FirstOrDefault(); if (checkUser != null) { if (product.LikeCount > 0) { product.LikeCount = product.LikeCount - 1; checkUser.DeletedDate = DateTime.Now; db.Entry(checkUser).State = System.Data.Entity.EntityState.Modified; } else { product.LikeCount = 0; } } else { var newLike = new Like(); newLike.ProductId = productId; newLike.UserId = currentUserId; newLike.CreatedDate = DateTime.Now; db.Likes.Add(newLike); product.LikeCount = product.LikeCount + 1; } db.Entry(product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var count = product.LikeCount; return(Json(count, JsonRequestBehavior.AllowGet)); } else { return(Json("notSession", JsonRequestBehavior.AllowGet)); } }
public IActionResult Create(UserComment userComment, int id) { //if (User.Identity.IsAuthenticated) //{ // var user = User.Identity.Name; // var model = _userManager.Users.FirstOrDefault(x => x.UserName == user); //var payment = _context.Payments.Find(id); ////var product = _context.Products.Find(id); var comment = _context.UserComments.FirstOrDefault(x => x.Id == id); ////var add = new UserComment ////{ //// UserId = model.Id, //// //PaymentId = payment.Id, //// ProductId = product.Id, //// UserName = model.UserName, //// Email = model.Email, //// Comment = comment.Comment, //// Date = DateTime.Now ////}; _context.UserComments.Add(userComment); ////TempData["create"] = "Yorum" + " " + comment.Comment + "" + " eklendi."; _context.SaveChanges(); return(View(userComment)); }
public ActionResult Create(Model model) { Category category = db.Categorys.Find(model.CategoryId); SubCategory subCategory = db.SubCategories.Find(model.SubCategoryId); if (ModelState.IsValid) { db.Models.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Categorys, "CategoryId", "Name", model.CategoryId); ViewBag.SubCategoryId = new SelectList(db.SubCategories, "SubCategoryId", "SubCategoryName", model.SubCategoryId); return(View(model)); }
public async void GetsAllLocations() { //Arrange var options = BuildInMemoryDb("GetsAllLocations"); //Act using (var context = new ShoppingDbContext(options)) { var store = new Store { Location = "Location1" }; context.Add(store); store = new Store { Location = "Location2" }; context.Add(store); store = new Store { Location = "Location3" }; context.Add(store); context.SaveChanges(); } //Assert using (var context = new ShoppingDbContext(options)) { var storeRepo = new StoreRepository(context); var stores = await storeRepo.All(); Assert.Equal(3, stores.Count()); } }
public ActionResult Cart(int id = 0) { ApplicationDbContext context = new ApplicationDbContext(); var um = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var user = um.FindByName(User.Identity.Name); var customer = db.Customers.FirstOrDefault(c => c.UserId == user.Id); if (db.CartItems.Where(c => c.CustomerId == customer.CustomerId && c.CustomerId == id).Count() > 0) { db.CartItems.First(c => c.CustomerId == customer.CustomerId && c.ProductId == id).Quantity++; } else { db.CartItems.Add(new CartItem { CustomerId = customer.CustomerId, ProductId = id, Quantity = 1 }); } db.SaveChanges(); return(View(db.CartItems.Where(c => c.CustomerId == customer.CustomerId && c.ProductId == id).ToList())); }
public ActionResult ForgotPassword(FormCollection form) { string username = form["Username"]; string email = form["Email"]; string message = ""; using (ShoppingDbContext db = new ShoppingDbContext()) { Customer account = db.Customer.Where(a => a.Email == email && a.Username == username).FirstOrDefault(); if (account != null) { string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword"); account.ResetCode = resetCode; db.SaveChanges(); message = "Reset password link has been sent to your email address!"; } else { message = "Invalid username and/or email! Please try again."; } } MessageBox.Show(message); return(View()); }
public ActionResult Detail(int id) { var model = db.Products.Find(id); //ถ้ามีคนเข้ามาดูจะนำไปนับและบันทึกไว้ model.Views++; db.SaveChanges(); var views = Request.Cookies["views"]; if (views == null) { views = new HttpCookie("views"); } views.Values[id.ToString()] = id.ToString(); views.Expires = DateTime.Now.AddMonths(1); Response.Cookies.Add(views); var keys = views.Values.AllKeys.Select(k => int.Parse(k)).ToList(); ViewBag.Views = db.Products .Where(p => keys.Contains(p.Id)); //Top 10 ViewBag.Top = db.Products.Where(p => p.Id > 0).OrderByDescending(o => o.Views).Take(10).ToList(); return(View(model)); }
public async void GetCustomerByEmail() { //Arrange var options = BuildInMemoryDb("GetsCustomerByEmail"); string fName = "Bob", lName = "Dole", email = "*****@*****.**"; int id = 1; //Act using (var context = new ShoppingDbContext(options)) { var customer = new Customer { CustomerId = id, FirstName = fName, LastName = lName, Email = email }; context.Add(customer); context.SaveChanges(); } //Assert using (var context = new ShoppingDbContext(options)) { var customerRepo = new CustomerRepository(context); var list = await customerRepo.Find(c => c.Email == email); var customerInfo = list.FirstOrDefault(); Assert.Equal(id, customerInfo.CustomerId); Assert.Equal(fName, customerInfo.FirstName); Assert.Equal(lName, customerInfo.LastName); Assert.Equal(email, customerInfo.Email); } }
public ActionResult Register(Customer newCustomer) { if (newCustomer.Password != newCustomer.ConfirmPassword) { MessageBox.Show("Password and confirm password do not match!"); return(View()); } if (newCustomer.Dateofbirth.Value > DateTime.Now) { MessageBox.Show("Invalid Date of Birth!"); return(View()); } using (ShoppingDbContext db = new ShoppingDbContext()) { Customer customer = db.Customer.Where(x => x.Username == newCustomer.Username).FirstOrDefault(); if (customer != null) { MessageBox.Show("Username already exists! Please choose another one."); return(View()); } string password = newCustomer.Password; newCustomer.Password = Functions.ComputeSHA256(password); newCustomer.ConfirmPassword = null; newCustomer.JoinDate = DateTime.Now; db.Customer.Add(newCustomer); db.SaveChanges(); } MessageBox.Show("Account successfully registered! You may now login."); return(RedirectToAction("Login", "Home")); }
public IActionResult Create(Category model) { try { _context.Categories.Add(model); TempData["create"] = "Kategori" + " " + model.Name + "" + " eklendi."; _context.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { } return(View(model)); }
public static ShoppingDbContext CreateInMemoryDataContext(Action <ShoppingDbContext> setupCallback = null) { // In-memory database only exists while the connection is open var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <ShoppingDbContext>() .UseSqlite(connection) .Options; // Create the schema in the database var context = new ShoppingDbContext( options); // HACK: ef core wont put data into a rowversion column, but it is not null, so create a fake default var sqlScript = context.Database.GenerateCreateScript(); sqlScript = sqlScript.Replace("\"Version\" BLOB NOT NULL", "\"Version\" BLOB NOT NULL DEFAULT (randomblob(8))"); context.Database.ExecuteSqlRaw(sqlScript); // Invoke callback to enable Test to provide master data if (setupCallback != null) { setupCallback.Invoke(context); context.SaveChanges(); } return(context); }
public ActionResult Create([Bind(Include = "Id,NameVN,Name,Image,Icon")] Category category, HttpPostedFileBase fileIcon) { if (ModelState.IsValid) { string path = Server.MapPath("~/Content/img/icons/"); string extensionName = Path.GetExtension(fileIcon.FileName); string finalFileName = DateTime.Now.Ticks.ToString() + extensionName; fileIcon.SaveAs(path + finalFileName); category.Icon = finalFileName; db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "Id,Name,Logo,Email,Phone")] Supplier supplier, HttpPostedFileBase fileLogo) { if (ModelState.IsValid) { string path = Server.MapPath("~/Content/img/suppliers/"); string extensionName = Path.GetExtension(fileLogo.FileName); string finalFileName = DateTime.Now.Ticks.ToString() + extensionName; fileLogo.SaveAs(path + finalFileName); supplier.Logo = finalFileName; db.Suppliers.Add(supplier); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(supplier)); }
public async void GetsAllOrdersForCustomer() { //Arrange var options = BuildInMemoryDb("GetsCustomersOrders"); //Act using (var context = new ShoppingDbContext(options)) { CreateOneCustomer(context); CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1" }; context.Add(store); context.SaveChanges(); var order = new Order { CusomerId = 1, OrderDateTime = DateTime.Now, OrderId = 1, StoreId = 1, }; context.Add(order); order = new Order { CusomerId = 1, OrderDateTime = DateTime.Now, OrderId = 2, StoreId = 1, }; context.Add(order); context.SaveChanges(); } //Assert using (var context = new ShoppingDbContext(options)) { var orderRepo = new OrderRepository(context); var orders = await orderRepo.Find(o => o.CusomerId == 1); Assert.Equal(2, orders.Count()); } }