예제 #1
0
        //===========================================================
        //===========================================================

        #region -- Delete User --
        public bool DeleteUser(int Id)
        {
            EatWellDBContext db   = new EatWellDBContext();
            Users            user = db.Users.FirstOrDefault(x => x.UserId == Id);

            if (user == null)
            {
                return(false);
            }
            db.Users.Remove(user);
            db.SaveChangesAsync();
            return(true);
        }
        //===========================================================
        //===========================================================

        #region -- Delete Category --
        public bool DeleteCategory(int Id)
        {
            EatWellDBContext db       = new EatWellDBContext();
            Categories       category = db.Categories.FirstOrDefault(x => x.CategoryId == Id);

            if (category == null)
            {
                return(false);
            }
            db.Categories.Remove(category);
            db.SaveChangesAsync();
            return(true);
        }
        //===========================================================
        //===========================================================

        #region -- Update Product --

        public SingleRsp UpdateProduct(ProductsReq pro)
        {
            var res = new SingleRsp();

            var product = All.Where(x => x.ProductId == pro.ProductId).FirstOrDefault();

            if (product != null)
            {
                product.CategoryId  = pro.CategoryId;
                product.ProductName = pro.ProductName;
                product.Photo       = pro.Photo;
                product.Description = pro.Description;
                product.ProductSlug = pro.ProductSlug;
                product.IsActive    = pro.IsActive;

                res = _rep.UpdateProduct(product);

                foreach (var po in product.ProductOptions)
                {
                    EatWellDBContext db = new EatWellDBContext();
                    var productoption   = new ProductOptions();

                    productoption.ProductId = product.ProductId;
                    productoption.OptionId  = po.OptionId;
                    productoption.Price     = po.Price;

                    db.ProductOptions.Update(productoption);
                    db.SaveChangesAsync();
                }
            }
            else
            {
            }

            return(res);
        }