public Book Post([FromBody] AddBook bookItem) { try { var theAuthor = _shopOnlineDbContext.Authors.Where(author => author.Id == bookItem.AuthorId).FirstOrDefault(); if (theAuthor == null) { return(null); } var newBook = new Book { Name = bookItem.Name, PublishDate = bookItem.PublishDate, AvailableCopies = bookItem.AvailableCopies, AuthorId = theAuthor.Id, Author = theAuthor, }; _shopOnlineDbContext.Books.Add(newBook); _shopOnlineDbContext.SaveChanges(); return(newBook); } catch (Exception ex) { throw ex; } }
public bool ChangeStatus(int id) { var logo = db.LOGO.Find(id); logo.Status = !logo.Status; db.SaveChanges(); return(logo.Status); }
public bool ChangeStatus(int id) { var slide = db.SLIDE.Find(id); slide.Status = !slide.Status; db.SaveChanges(); return(slide.Status); }
public bool ChangeStatus(int id) { var user = db.FEEDBACK.Find(id); user.Status = !user.Status; db.SaveChanges(); return(user.Status); }
public void Insert(string roleID, string userGrID) { var credential = new CREDENTIAL(); credential.UserGroupID = userGrID; credential.RoleID = roleID; db.CREDENTIAL.Add(credential); db.SaveChanges(); }
public void InsertView(long id) { var product = db.PRODUCT.Find(id); if (product.ViewCount.HasValue) { product.ViewCount += 1; } else { product.ViewCount = 1; } db.SaveChanges(); }
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 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}\""); } } } } }
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 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 int Insert(USERGROUP entity) { if (db.USERGROUP.Any(x => x.Name == entity.Name)) { return(-1); } try { db.USERGROUP.Add(entity); db.SaveChanges(); return(1); } catch { return(0); } }
public ActionResult Create(DetailProductPainting p) { ShopOnlineDbContext ctx = new ShopOnlineDbContext(); ctx.Product.Add(p); ctx.SaveChanges(); return(Content("ثبت با موفقیت انجام شد ")); }
public Basket Post([FromBody] AddBasketItem basketItem) { var buyerId = _httpContextAccessor.HttpContext.Request.Headers["#BuyerId"].ToString(); var product = _shopOnlineDbContext.Products.FirstOrDefault(p => p.Id == basketItem.ProductId); if (product == null) { return(null); } var basket = _shopOnlineDbContext.Baskets.FirstOrDefault(b => b.BuyerId == buyerId && !b.IsDeleted); if (basket != null) { basket.Items.Add(new BasketItem { Price = product.Price, Quantity = basketItem.Quantity, Name = product.Name }); basket.Total += product.Price * basketItem.Quantity; _shopOnlineDbContext.SaveChanges(); return(basket); } var newBasket = new Basket { BuyerId = buyerId, Items = new List <BasketItem> { new BasketItem { Price = product.Price, Quantity = basketItem.Quantity, Name = product.Name } }, Total = basketItem.Quantity * product.Price }; _shopOnlineDbContext.Baskets.Add(newBasket); _shopOnlineDbContext.SaveChanges(); return(newBasket); }
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")); }
public bool Insert(ORDERDETAIL detail) { try { db.ORDERDETAIL.Add(detail); db.SaveChanges(); return(true); } catch { return(false); } }
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 void SeedBaskets(this ShopOnlineDbContext context) { var baskets = new List <Basket> { new Basket { BuyerId = "*****@*****.**", Id = 1, IsDeleted = false } }; context.AddRange(baskets); context.SaveChanges(); }
public Author Post([FromBody] AddAuthor authorItem) { try { var newAuthor = new Author { Name = authorItem.Name, Age = authorItem.Age }; _shopOnlineDbContext.Authors.Add(newAuthor); _shopOnlineDbContext.SaveChanges(); return(newAuthor); } catch (Exception ex) { throw ex; } }
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 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 int InsertFeedBack(FEEDBACK fb) { db.FEEDBACK.Add(fb); db.SaveChanges(); return(fb.ID); }
public void Save() { _dbContext.SaveChanges(); }
public LipColor AddLipColor(LipColor lipColor) { _context.LipColor.Add(lipColor); _context.SaveChanges(); return(lipColor); }
public long Insert(CONTENT entity) { db.CONTENT.Add(entity); db.SaveChanges(); return(entity.ID); }
public long Insert(PRODUCT entity) { db.PRODUCT.Add(entity); db.SaveChanges(); return(entity.ID); }
public Books Add(Books book) { _context.Books.Add(book); _context.SaveChanges(); return(book); }
public long Insert(ORDER order) { db.ORDER.Add(order); db.SaveChanges(); return(order.ID); }
public long Insert(USER entity) { db.USER.Add(entity); db.SaveChanges(); return(entity.ID); }
private void CreateFunction(ShopOnlineDbContext context) { if (context.Functions.Count() == 0) { context.Functions.AddRange(new List <Function>() { new Function() { ID = "SYSTEM", Name = "Hệ thống", ParentId = null, DisplayOrder = 1, Status = true, URL = "/", IconCss = "fa-desktop" }, new Function() { ID = "ROLE", Name = "Nhóm", ParentId = "SYSTEM", DisplayOrder = 1, Status = true, URL = "/main/role/index", IconCss = "fa-home" }, new Function() { ID = "FUNCTION", Name = "Chức năng", ParentId = "SYSTEM", DisplayOrder = 2, Status = true, URL = "/main/function/index", IconCss = "fa-home" }, new Function() { ID = "USER", Name = "Người dùng", ParentId = "SYSTEM", DisplayOrder = 3, Status = true, URL = "/main/user/index", IconCss = "fa-home" }, new Function() { ID = "PRODUCT", Name = "Sản phẩm", ParentId = null, DisplayOrder = 2, Status = true, URL = "/", IconCss = "fa-chevron-down" }, new Function() { ID = "PRODUCT_CATEGORY", Name = "Danh mục", ParentId = "PRODUCT", DisplayOrder = 1, Status = true, URL = "/main/product-category/index", IconCss = "fa-chevron-down" }, new Function() { ID = "PRODUCT_LIST", Name = "Sản phẩm", ParentId = "PRODUCT", DisplayOrder = 2, Status = true, URL = "/main/product/index", IconCss = "fa-chevron-down" }, new Function() { ID = "ORDER", Name = "Hóa đơn", ParentId = "PRODUCT", DisplayOrder = 3, Status = true, URL = "/main/order/index", IconCss = "fa-chevron-down" }, new Function() { ID = "CONTENT", Name = "Nội dung", ParentId = null, DisplayOrder = 3, Status = true, URL = "/", IconCss = "fa-table" }, new Function() { ID = "POST_CATEGORY", Name = "Danh mục", ParentId = "CONTENT", DisplayOrder = 1, Status = true, URL = "/main/post-category/index", IconCss = "fa-table" }, new Function() { ID = "POST", Name = "Bài viết", ParentId = "CONTENT", DisplayOrder = 2, Status = true, URL = "/main/post/index", IconCss = "fa-table" }, new Function() { ID = "SLIDE", Name = "Slide", ParentId = "CONTENT", DisplayOrder = 3, Status = true, URL = "/main/slide/index", IconCss = "fa-table" }, new Function() { ID = "UTILITY", Name = "Tiện ích", ParentId = null, DisplayOrder = 4, Status = true, URL = "/", IconCss = "fa-clone" }, new Function() { ID = "FOOTER", Name = "Footer", ParentId = "UTILITY", DisplayOrder = 1, Status = true, URL = "/main/footer/index", IconCss = "fa-clone" }, new Function() { ID = "CONTACT", Name = "Liên hệ", ParentId = "UTILITY", DisplayOrder = 2, Status = true, URL = "/main/contact/index", IconCss = "fa-clone" }, new Function() { ID = "TAG", Name = "Tag", ParentId = "UTILITY", DisplayOrder = 3, Status = true, URL = "/main/tag/index", IconCss = "fa-clone" }, new Function() { ID = "SIZE", Name = "Size", ParentId = "UTILITY", DisplayOrder = 4, Status = true, URL = "/main/size/index", IconCss = "fa-clone" }, new Function() { ID = "SYSTEMCONFIG", Name = "Systemconfig", ParentId = "UTILITY", DisplayOrder = 5, Status = true, URL = "/main/systemconfig/index", IconCss = "fa-clone" }, }); context.SaveChanges(); } }
public long Insert(CATEGORY category) { db.CATEGORY.Add(category); db.SaveChanges(); return(category.ID); }