Exemplo n.º 1
0
        public ErrorMessage addPic(PicDetail pic, int id)
        {
            ErrorMessage error = new ErrorMessage();

            error.IsSuccess = true;
            //using (var data = item.Database.BeginTransaction())
            //{
            //    try
            //    {
            //        pic.ProductID = id;
            //        item.PicDetails.Add(pic);
            //        item.SaveChanges();
            //        data.Commit();
            //    }
            //    catch (Exception ex)
            //    {
            //        error.Message = ex.Message;
            //        error.IsSuccess = false;
            //        data.Rollback();

            //        return error;
            //    }
            //}
            return(error);
        }
Exemplo n.º 2
0
        public ActionResult Create(JsonProductDetail product)
        {
            PrductServices services = new PrductServices();

            Product p = ChangeIt(product);

            p.ProductID = product.ProductID;

            JsonURL u = new JsonURL();

            u.Url1 = product.PicUrl1;
            u.Url2 = product.PicUrl2;
            u.Url3 = product.PicUrl3;

            JavaScriptSerializer js = new JavaScriptSerializer();
            string    jsonData      = js.Serialize(u);//序列化
            PicDetail pd            = new PicDetail();

            pd.PicUrl = jsonData;

            services.addProduct(p, pd);

            //services.addProduct();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        //public Product GetProduct( string ProductName, String CategoryName, string ProductDescription, int UnitsInStock,int ProductPrice)
        //{
        //    Product product = new Product() {  CategoryName = ProductName, ProductDescription = CategoryName, ProductName = ProductName, UnitsInStock = UnitsInStock, ProductPrice= ProductPrice };
        //    return product;
        //}
        //public PicDetail GetPicDetail(string PicUrl )
        //{
        //    PicDetail PicDetail = new PicDetail() { PicUrl= PicUrl };
        //    return PicDetail;
        //}
        //public Category GetCategory(string CategoryName,string CategoryPic,string CategoryDescription)
        //{
        //    Category Category = new Category() {  CategoryDescription=CategoryDescription, CategoryName=CategoryName, CategoryPic=CategoryPic };
        //    return Category;
        //}
        public ErrorMessage addProduct(Product product, PicDetail pic)
        {
            ErrorMessage error = new ErrorMessage();

            error.IsSuccess = true;
            item.Products.Add(product);
            item.SaveChanges();
            item.Database.ExecuteSqlCommand($"insert into PicDetails values({product.ProductID},'{pic.PicUrl}')");
            //using (var data = item.Database.BeginTransaction())
            //{
            //    try
            //    {
            //        data.Commit();
            //    }
            //    catch (Exception ex)
            //    {
            //        error.Message = ex.Message;
            //        error.IsSuccess = false;
            //        data.Rollback();

            //        return error;
            //    }
            //}
            return(error);
        }
        public XmlElement ToXMLString(XmlDocument xmlDoc)
        {
            XmlElement picItem = xmlDoc.CreateElement("PictureItem");

            picItem.SetAttribute("ID", ID.ToString());
            picItem.SetAttribute("Pic1Url", Pic1Url);
            picItem.SetAttribute("Pic2Url", Pic2Url);
            picItem.SetAttribute("PicDetail", PicDetail.ToString());
            picItem.SetAttribute("pic1LocalName", Pic1LocalName);
            picItem.SetAttribute("pic2LocalName", Pic2LocalName);

            return(picItem);
        }
Exemplo n.º 5
0
 public bool CreateProduct(Product product, PicDetail pic)
 {
     try
     {
         _ProductNew.Crate(product);
         _PicNew.Crate(pic);
         _ProductNew.SaveChange();
     }
     catch (Exception ex) {
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
 public bool DeleteProduct(int id)
 {
     try
     {
         string  sql     = "select * from product where id=" + id;
         Product product = _ProductNew.GetData(sql).FirstOrDefault();
         sql = "select * from PicDetail where id=" + id;
         PicDetail pic = _PicNew.GetData(sql).FirstOrDefault();
         _ProductNew.Delete(product);
         _PicNew.Delete(pic);
         _ProductNew.SaveChange();
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 7
0
        public ErrorMessage EditProduct(Product product, PicDetail pic)
        {
            ErrorMessage error = new ErrorMessage();

            error.IsSuccess = true;
            try
            {
                item.Entry(product).State = EntityState.Modified;
                item.Entry(pic).State     = EntityState.Modified;
                item.SaveChanges();
            }
            catch (Exception ex)
            {
                error.IsSuccess = false;
                error.Message   = ex.Message;
                return(error);
            }
            return(error);
        }
Exemplo n.º 8
0
        public string ProductQuickView(int id)
        {
            Product product      = item.Products.Find(id);
            var     categoryname = (from c in item.Categories
                                    where c.CategoryID == product.CategoryID
                                    select c.CategoryName).FirstOrDefault();
            PicDetail picDetail   = item.PicDetails.Find(id);
            var       currentitem = new ProductList
            {
                ProductID          = product.ProductID,
                CategoryName       = categoryname,
                ProductName        = product.ProductName,
                ProductDescription = product.ProductDescription,
                UnitsInStock       = product.UnitsInStock,
                ProductPrice       = product.ProductPrice,
                Url = picDetail.PicUrl
            };

            return(JsonConvert.SerializeObject(currentitem));
        }
Exemplo n.º 9
0
 public ActionResult Create(Product product, PicDetail pic)
 {
     return(View());
 }
Exemplo n.º 10
0
 public ActionResult ProductList(Product product, Category category, PicDetail picDetail, HttpPostedFileBase file)
 {
     return(View());
 }
Exemplo n.º 11
0
        public ActionResult ProductIndex(string cat, int id)
        {
            var        isWish     = "false";
            HttpCookie rqstCookie = HttpContext.Request.Cookies.Get("myaccount");

            if (rqstCookie != null)
            {
                var memberDataObj = FormsAuthentication.Decrypt(rqstCookie.Value);
                var memberData    = JsonConvert.DeserializeObject <Member>(memberDataObj.UserData);

                var wishproducts = (from p in item.Products
                                    join w in item.WishLists
                                    on p.ProductID equals w.ProductID
                                    where memberData.MemberID == w.MemberID
                                    select p.ProductID).ToList();
                if (wishproducts.Contains(id))
                {
                    isWish = "true";
                }
            }
            ViewBag.isWish = isWish;
            //沒有傳入id(小嫚暫時拿掉)
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}

            using (ItemContext item = new ItemContext())
            {
                Product   product   = item.Products.Find(id);
                PicDetail picDetail = item.PicDetails.Find(id);
                //傳入的id找不到商品
                if (product == null)
                {
                    return(HttpNotFound());
                }
                //ViewBag.MemberID = memberData.MemberID;(小嫚暫時拿掉)
                //預設為1
                ViewBag.CartID             = 1;
                ViewBag.ProductID          = id;
                ViewBag.ProductDescription = product.ProductDescription;
                ViewBag.ProductName        = product.ProductName;
                ViewBag.ProductPrice       = product.ProductPrice;
                ViewBag.ProductUrl         = picDetail.PicUrl;
                //ViewBag.ProductUrl = JsonConvert.SerializeObject(picDetail.PicUrl);
                var parentstring = FindCategoryParents(product.CategoryID);
                var parents      = FindCategoryParents(product.CategoryID).Replace(@"""", "").Replace(@"\\", "").Replace(@"[", "").Replace(@"]", "").Split(',');
                ViewBag.parents = parents.Reverse();

                List <ProductList> products = (from p in item.Products
                                               join c in item.Categories
                                               on p.CategoryID equals c.CategoryID
                                               join pic in item.PicDetails
                                               on p.ProductID equals pic.ProductID
                                               where p.CategoryID == product.CategoryID
                                               select new ProductList
                {
                    ProductID = p.ProductID,
                    CategoryName = c.CategoryName,
                    ProductName = p.ProductName,
                    ProductDescription = p.ProductDescription,
                    UnitsInStock = p.UnitsInStock,
                    ProductPrice = p.ProductPrice,
                    Url = pic.PicUrl
                }).ToList();
                return(View(products));
            }
        }