public ActionResult GetImageByte(int id = 1)
        {
            ProductPictures product1 = db.ProductPictures.Find(id);

            byte[] img = product1.Picture;
            return(File(img, "image/jpeg"));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,ProductImagePath")] ProductPictures productPictures)
        {
            if (id != productPictures.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productPictures);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductPicturesExists(productPictures.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", productPictures.ProductId);
            return(View(productPictures));
        }
        // GET: Product
        public ActionResult Index()
        {
            List <ProductPictures> c       = new List <ProductPictures>();
            List <ProductModels>   product = new List <ProductModels>();


            foreach (var item in db.Products)
            {
                ProductModels _product = new ProductModels();

                _product.Product_ID  = item.Product_ID;
                _product.ProductName = item.ProductName;
                _product.Stock       = Convert.ToDecimal(item.Stock);

                //var Picture = item.ProductPictures;
                _product.Price       = Convert.ToDecimal(item.UnitPrice);
                _product.Description = item.Description;

                product.Add(_product);
            }
            foreach (var p in db.ProductPictures)
            {
                ProductPictures b = new ProductPictures();
                b.Picture = a.Picture;
                c.Add(b);
            }

            return(View(product.ToList()));
        }
Exemple #4
0
        public ActionResult CreatAllProduct(HttpPostedFileBase imgPhoto, Product p, string SUBNAME)
        {
            /*新增照片*/
            SingleApartmentEntities db = new SingleApartmentEntities();

            //======================================================

            imgPhoto.SaveAs("c:\\temp\\111.jpg");

            FileStream fs = new FileStream("c:\\temp\\111.jpg", FileMode.Open, FileAccess.Read);

            int length = (int)fs.Length;

            byte[] image = new byte[length];

            fs.Read(image, 0, length);

            fs.Close();
            //=====================================================

            //下拉式選單抓id

            int SUBID = (from S in db.ProductSubCategory
                         where S.ProductSubCategoryName == SUBNAME
                         select S.ProductSubCategoryID).FirstOrDefault();

            var PROID = (from P in db.Product
                         where P.ProductSubCategoryID == SUBID
                         select P.ProductSubCategoryID).FirstOrDefault();

            p.Discontinued = "N";

            p.ProductSubCategoryID = PROID;

            db.Product.Add(p);

            //-----------------------


            ProductPictures prodpic = new ProductPictures();

            prodpic.ProductID = p.ProductID;

            //prodpic.ProductPictureID = 2;

            prodpic.ProductPicture = image;

            db.ProductPictures.Add(prodpic);

            db.SaveChanges();
            //======================================================

            return(RedirectToAction("Home", "Product"));
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductImagePath")] ProductPictures productPictures)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productPictures);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", productPictures.ProductId);
            return(View(productPictures));
        }
Exemple #6
0
    string BindPictures()
    {
        List <ProductPicture> pics = ProductPictures.GetPictures(productID);

        if (pics.Count > 0)
        {
            return(Newtonsoft.Json.JavaScriptConvert.SerializeObject(pics));
        }
        else
        {
            return("null");
        }
    }
Exemple #7
0
    void BindPicture()
    {
        if (p == null)
        {
            p = GetProduct();
        }
        List <ProductPicture> pics = ProductPictures.GetPictures(p.ProductID);
        string picStr = "''";

        if (pics != null && pics.Count > 0)
        {
            picStr = Newtonsoft.Json.JavaScriptConvert.SerializeObject(pics);
        }
        base.ExecuteJs("var pictures=" + picStr + ";var _infos={l:" + User.Identity.IsAuthenticated.ToString().ToLower() + ",d:" + p.ProductID + "}", true);
    }
Exemple #8
0
 public ProductEntity(Product Product, params object[] args) : base(Product)
 {
     foreach (object arg in args)
     {
         if (arg is Category Category)
         {
             CategoryEntity = new CategoryEntity(Category);
         }
         if (arg is Manufacturer Manufacturer)
         {
             ManufacturerEntity = new ManufacturerEntity(Manufacturer);
         }
         if (arg is ICollection <Discount> Discounts)
         {
             DiscountEntities = Discounts.Select(model => new DiscountEntity(model)).ToList();
         }
         if (arg is ICollection <Inventory> Inventories)
         {
             InventoryEntities = Inventories.Select(model => new InventoryEntity(model, model.WareHouse)).ToList();
         }
         if (arg is ICollection <IssueNoteLine> IssueNoteLines)
         {
             IssueNoteLineEntities = IssueNoteLines.Select(model => new IssueNoteLineEntity(model, model.IssueNote)).ToList();
         }
         if (arg is ICollection <Pack> Packs)
         {
             PackEntities = Packs.Select(model => new PackEntity(model)).ToList();
         }
         if (arg is ICollection <ProductPicture> ProductPictures)
         {
             ProductPictureEntities = ProductPictures.Select(model => new ProductPictureEntity(model)).ToList();
         }
         if (arg is ICollection <ProductValue> ProductValues)
         {
             ProductValueEntities = ProductValues.Select(model => new ProductValueEntity(model, model.Attribute, model.Language)).ToList();
         }
         if (arg is ICollection <ReceiptNoteLine> ReceiptNoteLines)
         {
             ReceiptNoteLineEntities = ReceiptNoteLines.Select(model => new ReceiptNoteLineEntity(model, model.ReceiptNote)).ToList();
         }
     }
 }
Exemple #9
0
        protected override void Validate()
        {
            if (Category == null)
            {
                AddBrokenRule(ProductBusinessRule.CategoryIsRequired);
            }

            if (!Stores.Any())
            {
                AddBrokenRule(ProductBusinessRule.StoreIsRequired);
            }

            if (!ProductPictures.Any())
            {
                AddBrokenRule(ProductBusinessRule.PictureIsRequired);
            }

            if (!Users.Any())
            {
                AddBrokenRule(ProductBusinessRule.UserIsRequired);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpFileCollection files = context.Request.Files;
                HttpPostedFile     f     = null;
                ProductPicture     p     = null;

                for (int i = 0; i < files.Count; i++)
                {
                    f              = files[i];
                    p              = new ProductPicture();
                    p.PictureName  = f.FileName;
                    p.PictureFile  = f.FileName;
                    p.DisplayOrder = 100;
                    p.ProductID    = int.Parse(context.Request["pictureid"]);
                    ProductPictures.Create(p, f.InputStream);
                }
            }
            catch (Exception ex)
            {
                throw new HHException(ExceptionType.UnknownError, ex.Message);
            }
        }
Exemple #11
0
    public void RaiseCallbackEvent(string eventArgument)
    {
        Guid id;
        TemporaryAttachment ta;

        if (eventArgument == "refreshBinder")
        {
            switch (action)
            {
            case OperateType.Add:
                result = BindAttachment();
                break;

            case OperateType.Edit:
                result = BindPictures();
                break;
            }
        }
        if (eventArgument.StartsWith("deleteAttach"))
        {
            try
            {
                switch (action)
                {
                case OperateType.Add:
                    id = new Guid(eventArgument.Split(':')[1]);
                    TemporaryAttachments.Delete(id);
                    break;

                case OperateType.Edit:
                    ProductPictures.Delete(int.Parse(eventArgument.Split(':')[1]));
                    break;
                }
                result = "0";
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
        }
        if (eventArgument.StartsWith("setDefault"))
        {
            try
            {
                switch (action)
                {
                case OperateType.Add:
                    id = new Guid(eventArgument.Split(':')[1]);
                    ta = TemporaryAttachments.GetTemporaryAttachments(Profile.AccountInfo.UserID, AttachmentType.ProductPhoto)[0];
                    ta.DisplayOrder = 100;
                    TemporaryAttachments.Update(ta);

                    ta = TemporaryAttachments.GetTemporaryAttachment(id);
                    ta.DisplayOrder = 0;
                    TemporaryAttachments.Update(ta);

                    result = BindAttachment();
                    break;

                case OperateType.Edit:
                    int            picId = int.Parse(eventArgument.Split(':')[1]);
                    ProductPicture pics  = ProductPictures.GetPictures(productID)[0];
                    pics.DisplayOrder = 100;
                    ProductPictures.Update(pics);

                    pics = ProductPictures.GetPicture(picId);
                    pics.DisplayOrder = 0;
                    ProductPictures.Update(pics);

                    result = BindPictures();
                    break;
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
        }
    }