private void CreateUser(ShopOnlineDbContext context) { var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ShopOnlineDbContext())); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ShopOnlineDbContext())); var user = new ApplicationUser() { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, BirthDay = DateTime.Now, FullName = "Shop" }; if (manager.Users.Count(x => x.UserName == "shop2") == 0) { manager.Create(user, "zxc123"); if (!roleManager.Roles.Any()) { roleManager.Create(new IdentityRole { Name = "Admin" }); roleManager.Create(new IdentityRole { Name = "User" }); } var adminUser = manager.FindByEmail("*****@*****.**"); manager.AddToRoles(adminUser.Id, new string[] { "Admin", "User" }); } }
private void CreateContactDetail(ShopOnlineDbContext context) { if (context.ContactDetails.Count() == 0) { try { var contactDetail = new ShopOnline.Model.Models.ContactDetail() { Name = "Shop thời trang online", Address = "k34 Lê Văn Thứ", Email = "*****@*****.**", Lat = 21.0633645, Lng = 105.8053274, Phone = "0905629025", Website = "", Other = "", Status = true }; context.ContactDetails.Add(contactDetail); context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error."); foreach (var ve in eve.ValidationErrors) { Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""); } } } } }
private void CreateSlide(ShopOnlineDbContext context) { if (context.Slides.Count() == 0) { List <Slide> listSlide = new List <Slide>() { new Slide() { Name = "Slide 1", DisplayOrder = 1, Status = true, Url = "#", Image = "/Assets/client/images/bag.jpg", Content = @" <h2>FLAT 50% 0FF</h2> <label>FOR ALL PURCHASE <b>VALUE</b></label> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et </ p > <span class=""on-get"">GET NOW</span>" }, new Slide() { Name = "Slide 2", DisplayOrder = 2, Status = true, Url = "#", Image = "/Assets/client/images/bag1.jpg", Content = @"<h2>FLAT 50% 0FF</h2> <label>FOR ALL PURCHASE <b>VALUE</b></label> <span class=""on-get"">GET NOW</span>" }, }; context.Slides.AddRange(listSlide); context.SaveChanges(); } }
public ActionResult Delete(int id) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); var d = ctx.Product.Find(id); return(View(d)); }
private void CreateContactDetail(ShopOnlineDbContext context) { if (context.ContactDetails.Count() == 0) { try { var contactDetail = new ShopOnline.Model.Models.ContactDetail() { Name = "Cửa hàng điện lạnh Xuân Hoàng", Address = "Ngõ 56 Cổ Nhuế", Email = "*****@*****.**", Lat = 21.0657715, Lng = 105.7765664, Phone = "0968207096", Website = "http://google.com.vn", Other = "", Status = true }; context.ContactDetails.Add(contactDetail); context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error."); foreach (var ve in eve.ValidationErrors) { Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""); } } } } }
// GET: Admin public ActionResult Create() { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); ViewBag.CategoryId = new SelectList(ctx.Category.ToList(), "Id", "Name"); return(View()); }
private void CreateUser(ShopOnlineDbContext context) { var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ShopOnlineDbContext())); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ShopOnlineDbContext())); var user = new ApplicationUser() { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, BirthDay = DateTime.Now, FullName = "Truong Thanh Hai" }; if (manager.Users.Count(x => x.UserName == "haitruong") == 0) { manager.Create(user, "123654$"); if (!roleManager.Roles.Any()) { roleManager.Create(new IdentityRole { Name = "Admin" }); roleManager.Create(new IdentityRole { Name = "User" }); } var adminUser = manager.FindByEmail("*****@*****.**"); manager.AddToRoles(adminUser.Id, new string[] { "Admin", "User" }); } }
private void CreateAdminUser(ShopOnlineDbContext dbContext) { var manager = new UserManager <AppUser>(new UserStore <AppUser>(new ShopOnlineDbContext())); var roleManager = new RoleManager <AppRole>(new RoleStore <AppRole>(new ShopOnlineDbContext())); if (manager.Users.Count() == 0) { var user = new AppUser() { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, BirthDay = DateTime.Now, FullName = "Nguyễn Văn Phong", }; manager.Create(user, "ngvanphong2012"); if (!roleManager.Roles.Any()) { roleManager.Create(new AppRole { Name = "Admin", Description = "Admin" }); roleManager.Create(new AppRole { Name = "User", Description = "User" }); } ; var adminUser = manager.FindByEmail("*****@*****.**"); manager.AddToRoles(adminUser.Id, new string[] { "Admin", "User" }); } }
private void CreatePage(ShopOnlineDbContext context) { if (context.Pages.Count() == 0) { try { var page = new Page() { Name = "Giới thiệu", Alias = "gioi-thieu", Content = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium ", Status = true }; context.Pages.Add(page); context.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Trace.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation error."); foreach (var ve in eve.ValidationErrors) { Trace.WriteLine($"- Property: \"{ve.PropertyName}\", Error: \"{ve.ErrorMessage}\""); } } } } }
private void CreateConfigTitle(ShopOnlineDbContext context) { if (!context.SystemConfigs.Any(x => x.Code == "HomeTitle")) { context.SystemConfigs.Add(new SystemConfig() { Code = "HomeTitle", ValueString = "Trang chủ ShopOnline", }); } if (!context.SystemConfigs.Any(x => x.Code == "HomeMetaKeyword")) { context.SystemConfigs.Add(new SystemConfig() { Code = "HomeMetaKeyword", ValueString = "Trang chủ ShopOnline", }); } if (!context.SystemConfigs.Any(x => x.Code == "HomeMetaDescription")) { context.SystemConfigs.Add(new SystemConfig() { Code = "HomeMetaDescription", ValueString = "Trang chủ ShopOnline", }); } }
public void Dispose() { if (context != null) { context.Dispose(); context = null; } }
public ActionResult Create(DetailProductPainting p) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); ctx.Product.Add(p); ctx.SaveChanges(); return(Content("ثبت با موفقیت انجام شد ")); }
public BasketRepository Build() { if (_useDefaultContext) { _context = _contextMock.Object; } return(new BasketRepository(_context)); }
public ActionResult DeleteConfirm(int id) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); var d = ctx.Product.Find(id); TempData["Message"] = $"{d.NameBoard}حذف شد"; ctx.Product.Remove(d); ctx.SaveChanges(); return(RedirectToAction("productlist")); }
private void CreateFooter(ShopOnlineDbContext context) { if (context.Footers.Count(x => x.ID == CommonConstants.DefaultFooterId) == 0) { string content = "Footer"; context.Footers.Add(new Footer() { ID = CommonConstants.DefaultFooterId, Content = content }); context.SaveChanges(); } }
public static ShopOnlineDbContext GetInMemoryContext() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var dbContextOptions = new DbContextOptionsBuilder <ShopOnlineDbContext>() .UseSqlite(connection) .Options; var context = new ShopOnlineDbContext(dbContextOptions); context.Database.EnsureCreated(); return(context); }
public static void SeedBaskets(this ShopOnlineDbContext context) { var baskets = new List <Basket> { new Basket { BuyerId = "*****@*****.**", Id = 1, IsDeleted = false } }; context.AddRange(baskets); context.SaveChanges(); }
public ActionResult Edit(FormCollection viewModel) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); //var model = ctx.Product.Find(viewModel.Id); //if (viewModel.UrlImage1 != null) //{ // var extention = Path.GetExtension(viewModel.UrlImage1.FileName).ToLower(); // if (viewModel.UrlImage1.ContentLength / 1024 >= 150) // { // ModelState.AddModelError("UrlImage1", "سایز فایل باید کمتراز150کیلوبایت باشد"); // //ModelState.AddModelError("","این خطای فرم نمونه است"); // } // if (!(extention == ".jpg" || extention == ".png" || extention == ".jpeg" || extention == ".gif")) // { // ModelState.AddModelError("UrlImage1", "فرمت فایل ارسالی مناسب نیست"); // } //} //if (ModelState.IsValid) //{ // //model.Id = viewModel.Id; // model.CategoryId = viewModel.CategoryId; // model.NameBoard = viewModel.NameBoard; // model.FirstPrice = viewModel.FirstPrice; // model.Reduction = viewModel.Reduction; // model.LastPrice = viewModel.LastPrice; // model.Number = viewModel.Number; // //if (viewModel.UrlImage1 != null) // //{ // // var extention = Path.GetExtension(viewModel.UrlImage1.FileName); // // var fileName = $"{Guid.NewGuid().ToString()}{extention}"; // // var fullPath = Path.Combine(Server.MapPath("~/images/urlimages"), fileName); // // viewModel.UrlImage1.SaveAs(fullPath); // // var UrlImage2 = $"~/images/urlimages/{fileName}"; // // model.UrlImage = UrlImage2; // //} // ctx.SaveChanges(); // TempData["Message"] = "ویرایش باموفقیت انجام شد"; // return RedirectToAction("ProductList", "Admin"); //} //ViewBag.CategoryId = new SelectList(ctx.Category.ToList(), "Id", "Name", viewModel.CategoryId); //TempData["Message"] = "ویرایش با خطا مواجه شده است"; //TempData["MessageClass"] = "danger"; return(View(viewModel)); }
private void CreateProductCategorySamble(ShopOnlineDbContext dbContext) { if (dbContext.ProductCategories.Count() == 0) { List <ProductCategory> listProductCategory = new List <ProductCategory> { new ProductCategory() { Name = "Áo sơ mi", Alias = "Ao-so-mi", Status = true }, new ProductCategory() { Name = "Áo thun", Alias = "Ao-thun", Status = true }, new ProductCategory() { Name = "Đầm váy", Alias = "Dam-vay", Status = true }, }; dbContext.ProductCategories.AddRange(listProductCategory); dbContext.SaveChanges(); } }
public ActionResult Edit(int id) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); var model = ctx.Product.Find(id); ViewBag.CategoryId = new SelectList(ctx.Category.ToList(), "Id", "Name", model.CategoryId); AdminEditViewModel viewModel = new AdminEditViewModel() { Id = model.Id, NameBoard = model.NameBoard, FirstPrice = model.FirstPrice, Reduction = model.Reduction, LastPrice = model.LastPrice, Number = model.Number, TimeGaranty = model.TimeGaranty, CategoryId = model.CategoryId, UrlImage = model.UrlImage, NameArtist = ((DetailProductPainting)model).NameArtist, SizeBoard = ((DetailProductPainting)model).SizeBoard, Technique = ((DetailProductPainting)model).Technique }; return(View(viewModel)); }
public ActionResult Create(DetailProductPainting p, HttpPostedFileBase UrlImage1) { var extention = Path.GetExtension(UrlImage1.FileName).ToLower(); if (UrlImage1.ContentLength / 1024 <= 150 && (extention == ".jpg" || extention == ".jpeg" || extention == ".png" || extention == "gif")) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); var fileName = $"{Guid.NewGuid().ToString()}{extention}"; var fullPath = Path.Combine(Server.MapPath("~/images/urlimages"), fileName); UrlImage1.SaveAs(fullPath); p.UrlImage = $"~/images/urlimages/{fileName}"; ctx.Product.Add(p); ctx.SaveChanges(); //return Content("ثبت با موفقیت انجام شد "); TempData["Messag"] = "ثبت با موفقیت انجام شد "; return(RedirectToAction("ProductList")); } else { TempData["Message"] = "فایل ارسالی مناسب نیست "; TempData["MessageClass"] = "danger"; return(RedirectToAction("Create")); } }
public CredentialDao() { db = new ShopOnlineDbContext(); }
public ActionResult ProductList() { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); return(View(ctx.Product.ToList())); }
public CustomerRepository(ShopOnlineDbContext entitiesContext) : base(entitiesContext) { }
public SlidesDao() { db = new ShopOnlineDbContext(); }
public ProductRepository(ShopOnlineDbContext shopOnlineDbContext) : base(shopOnlineDbContext) { }
public UserGroupDao() { db = new ShopOnlineDbContext(); }
public ReceiptNoteRepository(ShopOnlineDbContext entitiesContext) : base(entitiesContext) { }
public BasketsController(IHttpContextAccessor httpContextAccessor, ShopOnlineDbContext shopOnlineDbContext) { _httpContextAccessor = httpContextAccessor; _shopOnlineDbContext = shopOnlineDbContext; }
public ApplicationUserStore(ShopOnlineDbContext context) : base(context) { }