public void TestMethod1() { return; Random gen = new Random(); for (int i = 1; i <= 200; i++) { DateTime start = new DateTime(2010, 1, 1); int range = (start.AddYears(5) - start).Days; start = start.AddDays(gen.Next(range)); var productIds = new List <int>(); using (RecoEntities recoEntities = new RecoEntities()) { var productsNumber = gen.Next(5) + 1; var userId = gen.Next(19) + 2005; productIds.Clear(); for (int j = 1; j <= productsNumber; j++) { productIds.Add(gen.Next(49) + 4009); } decimal sum = 0; foreach (var productId in productIds) { var product = recoEntities.Products.Find(productId); sum += product.PretCuDiscount; } var newSale = new Sale() { Address = "-", Phone = "0790649098", CreatedDate = start, Price = sum, UserId = userId }; recoEntities.Sales.Add(newSale); recoEntities.SaveChanges(); while (productIds.Count > 0) { var newItemSale = new SaleItem() { CreatedDate = start, SaleId = newSale.Id, UserId = newSale.UserId, ProductId = productIds[0], Quantity = productIds.Count(x => x == productIds[0]) }; recoEntities.SaleItems.Add(newItemSale); recoEntities.SaveChanges(); var id = productIds[0]; productIds.RemoveAll(x => x == id); } } } }
public ActionResult Success(string numarTelefon, string adresa) { if (numarTelefon == null || adresa == null || numarTelefon == "" || adresa == "") { ViewBag.Error = "Numarul de telefon si adresa sunt campuri obligatorii!"; var model = Session["shoppingCart"] as ShoppingCartModel; return(View("Checkout", model)); } if (numarTelefon.Length < 10) { ViewBag.Error = "Numarul de telefon nu este complet!"; var model = Session["shoppingCart"] as ShoppingCartModel; return(View("Checkout", model)); } if (Session["shoppingCart"] == null) { return(View("~/Shared/Error")); } var shoppingCart = Session["shoppingCart"] as ShoppingCartModel; var sale = new Sale() { Price = shoppingCart.TotalPrice, UserId = Int32.Parse(Session["userId"].ToString()), Address = adresa, Phone = numarTelefon, CreatedDate = DateTime.Now }; recoEntities.Sales.Add(sale); recoEntities.SaveChanges(); foreach (var item in shoppingCart.Items) { var saleItem = new SaleItem() { ProductId = item.ProductId, CreatedDate = DateTime.Now, SaleId = sale.Id, UserId = Int32.Parse(Session["userId"].ToString()), Quantity = item.Cantity }; recoEntities.SaleItems.Add(saleItem); recoEntities.SaveChanges(); var product = recoEntities.Products.Single(x => x.Id == item.ProductId); product.Cantitate -= item.Cantity; recoEntities.SaveChanges(); } Session["shoppingCart"] = new ShoppingCartModel();; ViewBag.TransactionId = sale.Id; return(View()); }
public void TestMethod1() { return; Random gen = new Random(); for (int i = 2; i <= 20; i++) { DateTime start = new DateTime(2000, 1, 1); int range = (start.AddYears(5) - start).Days; start = start.AddDays(gen.Next(range)); using (RecoEntities recoEntities = new RecoEntities()) { recoEntities.Database.Connection.Open(); var user = new User() { DataCreare = start, Email = "user" + i.ToString() + "@mailinator.com", Forename = "User", Surname = i.ToString(), ImageUrl = null, Password = "******", Role = "Vizitator" }; recoEntities.Users.Add(user); recoEntities.SaveChanges(); } } }
public void TestMethod1() { //return; Random gen = new Random(); for (int i = 1; i <= 50; i++) { DateTime start = new DateTime(2005, 1, 1); int range = (start.AddYears(5) - start).Days; start = start.AddDays(gen.Next(range)); var categoryId = i % 4 + 1; decimal price = gen.Next(range) + 1; using (RecoEntities recoEntities = new RecoEntities()) { recoEntities.Database.Connection.Open(); var product = new Product() { DataCreare = start, CategorieId = categoryId, Nume = (categoryId).ToString() + " " + ((i / 4) + 1), Pret = price, PretCuDiscount = price, Cantitate = gen.Next(range) }; recoEntities.Products.Add(product); recoEntities.SaveChanges(); } } }
public ActionResult AddProduct(ProductModel model, HttpPostedFileBase image) { try { if (!ModelState.IsValid) { model.ListaCategorii = recoEntities.Categories.Where(x => x.Arata == false).ToList(); return(View(model)); } if (recoEntities.Products.Any(x => x.Nume == model.Nume)) { ModelState.AddModelError("", "Deja exista un produs cu acest nume"); } Mapper.Initialize(cfg => cfg.CreateMap <ProductModel, Product>()); var product = Mapper.Map <ProductModel, Product>(model); product.DataCreare = DateTime.Now; if (product.PretCuDiscount == 0) { product.PretCuDiscount = product.Pret; } recoEntities.Products.Add(product); recoEntities.SaveChanges(); if (image != null) { System.IO.File.Delete(Path.Combine(Server.MapPath("/images/"), "prod" + product.Id.ToString() + ".jpg")); string path = Path.Combine(Server.MapPath("/images/"), "prod" + product.Id.ToString() + ".jpg"); image.SaveAs(path); product.ImageUrl = "prod" + product.Id.ToString() + ".jpg"; } recoEntities.SaveChanges(); return(RedirectToAction("Index", "Home", new { area = "" })); } catch (Exception ex) { return(RedirectToAction("Index", "Home", new { area = "" })); } }
public ActionResult AddCategory(CategoryModel model, HttpPostedFileBase image) { try { if (Session["role"] == null || Session["role"].ToString() != "Admin") { return(View("~/Shared/Error")); } if (recoEntities.Categories.Any(x => x.Nume == model.Nume)) { ModelState.AddModelError("", "Deja exista un produs cu acest nume"); } if (!ModelState.IsValid) { return(View(model)); } Mapper.Initialize(cfg => cfg.CreateMap <CategoryModel, Category>()); var category = Mapper.Map <CategoryModel, Category>(model); category.DataCreare = DateTime.Now; recoEntities.Categories.Add(category); recoEntities.SaveChanges(); if (image != null) { System.IO.File.Delete(Path.Combine(Server.MapPath("/images/"), "category" + category.Id.ToString() + ".jpg")); string path = Path.Combine(Server.MapPath("/images/"), "category" + category.Id.ToString() + ".jpg"); image.SaveAs(path); category.ImageUrl = "category" + category.Id.ToString() + ".jpg"; } recoEntities.SaveChanges(); return(RedirectToAction("Index", "Categories", new { area = "" })); } catch (Exception ex) { return(RedirectToAction("Index", "Categories", new { area = "" })); } }
public ActionResult Register(RegisterUserModel model) { if (!ModelState.IsValid) { return(View("", model)); } if (recoEntities.Users.ToList().Any(x => x.Email == model.Email)) { ModelState.AddModelError("", "Adresa de email deja introdusa in sistem!"); return(View(model)); } var newUser = new User() { Forename = model.Forename, Surname = model.Surname, Email = model.Email, Password = model.Password, Role = "Vizitator", DataCreare = DateTime.Now }; recoEntities.Users.Add(newUser); recoEntities.SaveChanges(); var user = newUser; Session["userId"] = user.Id; Session["user"] = user.Forename + " " + user.Surname; Session["role"] = user.Role; if (user.ImageUrl != null) { Session["imageUrl"] = user.ImageUrl; } Session["shoppingCart"] = new ShoppingCartModel(); return(RedirectToAction("Index", "Home", new { area = "" })); }