public int Update(Content entity) { try { Category category = dbContext.Categories.Find(entity.CategoryID); if (category.Status == false) { return(-1); } var content = dbContext.Contents.Find(entity.ID); content.Name = entity.Name; content.MetaTitle = entity.MetaTitle; content.Image = entity.Image; content.Description = entity.Description; content.Detail = entity.Detail; content.CategoryID = entity.CategoryID; content.Status = entity.Status; dbContext.SaveChanges(); } catch (Exception ex) { return(0); } return(1); }
public long Insert(Product entity) { try { if (entity.Price == null) { return(-3); } ProductCategory productCategory = dbContext.ProductCategories.Find(entity.CategoryID); if (productCategory.Status == false) { return(-1); } Brand brand = dbContext.Brands.Find(entity.BrandID); if (brand.Status == false) { return(-2); } dbContext.Products.Add(entity); dbContext.SaveChanges(); } catch (Exception e) { return(0); } return(entity.ID); }
public long Edit(Content content) { //xử lý Alias if (string.IsNullOrEmpty(content.MetaTittle)) { content.MetaTittle = StringHelper.ToUnsignString(content.Name); } //Xử lý Tags content.CreatedDate = DateTime.Now; db.SaveChanges(); if (!string.IsNullOrEmpty(content.Tags)) { this.RemoveAllContentTag(content.ID); string[] tags = content.Tags.Split(','); foreach (var item in tags) { var tagID = StringHelper.ToUnsignString(item); var tagexisted = this.CheckTags(tagID); if (!tagexisted) { this.InsertTags(tagID, item); } //insert to content tag this.InsertContentTags(content.ID, tagID); } } return(content.ID); }
public ActionResult Create(Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Nama", product.CustomerID); return(View(product)); }
public void UpdateImages(long id, string images) { var product = GetID(id); product.MoreImages = images; db.SaveChanges(); }
public bool Change(long id) { var result = db.Users.Find(id).Status; if (result) { db.Users.Find(id).Status = false; db.SaveChanges(); return(false); } else { db.Users.Find(id).Status = true; db.SaveChanges(); return(true); } }
public long Insert(Category entity) { try { var category = dbContext.Categories.SingleOrDefault(x => x.Name.Trim() == entity.Name.Trim()); if (category != null) { return(-1); } dbContext.Categories.Add(entity); dbContext.SaveChanges(); } catch (Exception e) { return(0); } return(entity.ID); }
public long Insert(Brand entity) { try { var brand = dbContext.Brands.SingleOrDefault(x => x.Name.Trim() == entity.Name.Trim()); if (brand != null) { return(-1); } dbContext.Brands.Add(entity); dbContext.SaveChanges(); } catch (Exception e) { return(0); } return(entity.ID); }
public long Insert(User entity) { try { var user = dbContext.Users.SingleOrDefault(x => x.Username == entity.Username); if (user != null) { return(-1); } dbContext.Users.Add(entity); dbContext.SaveChanges(); } catch (Exception e) { return(0); } return(entity.ID); }
public ActionResult Create(Productt productt) { if (ModelState.IsValid) { db.Productts.Add(productt); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public void InsertOrderDetail(long productID, float unitPrice, int quantity, long orderID) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderID = orderID; orderDetail.ProductID = productID; orderDetail.UnitPrice = unitPrice; orderDetail.Quantity = quantity; dbContext.OrderDetails.Add(orderDetail); dbContext.SaveChanges(); }
public bool Insert(OrderDetail orderDetail) { try { db.OrderDetails.Add(orderDetail); db.SaveChanges(); return(true); } catch { return(false); } }
public bool ChangeStatus(long id) { var user = db.Users.Find(id); if (user.Status == true) { user.Status = false; } else { user.Status = true; } db.SaveChanges(); return(user.Status); }
public long Insert(Order order) { db.Orders.Add(order); db.SaveChanges(); return(order.ID); }
public long Insert(Category category) { db.Categories.Add(category); db.SaveChanges(); return(category.ID); }
public long Insert(User user) { db.Users.Add(user); db.SaveChanges(); return(user.ID); }
//Add product use Entity Framework public long Create(Product product) { db.Products.Add(product); db.SaveChanges(); return(product.ID); }
public long Insert(User entity) { db.Users.Add(entity); db.SaveChanges(); return(entity.ID); }
public long InsertOrder(Order order) { dbContext.Orders.Add(order); dbContext.SaveChanges(); return(order.ID); }
public long Create(ProductCategory productCategory) { db.ProductCategories.Add(productCategory); db.SaveChanges(); return(productCategory.ID); }
public void Save() { _context.SaveChanges(); }