示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        public void UpdateImages(long id, string images)
        {
            var product = GetID(id);

            product.MoreImages = images;
            db.SaveChanges();
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
 public ActionResult Create(Productt productt)
 {
     if (ModelState.IsValid)
     {
         db.Productts.Add(productt);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
示例#12
0
        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();
        }
示例#13
0
 public bool Insert(OrderDetail orderDetail)
 {
     try
     {
         db.OrderDetails.Add(orderDetail);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#14
0
        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);
        }
示例#15
0
 public long Insert(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     return(order.ID);
 }
示例#16
0
 public long Insert(Category category)
 {
     db.Categories.Add(category);
     db.SaveChanges();
     return(category.ID);
 }
示例#17
0
文件: UserDAO.cs 项目: TCTR7/Web
 public long Insert(User user)
 {
     db.Users.Add(user);
     db.SaveChanges();
     return(user.ID);
 }
示例#18
0
 //Add product use Entity Framework
 public long Create(Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
     return(product.ID);
 }
示例#19
0
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }
示例#20
0
 public long InsertOrder(Order order)
 {
     dbContext.Orders.Add(order);
     dbContext.SaveChanges();
     return(order.ID);
 }
示例#21
0
 public long Create(ProductCategory productCategory)
 {
     db.ProductCategories.Add(productCategory);
     db.SaveChanges();
     return(productCategory.ID);
 }
示例#22
0
 public void Save()
 {
     _context.SaveChanges();
 }