Ejemplo n.º 1
0
        public ProductModel SaveThis()
        {
            //Validation
            if (Name == string.Empty)
            {
                return(null);
            }
            //Save
            DataTable dt = this.Save(this.FillMe());

            this.Id = Convert.ToInt32(dt.Rows[0][0].ToString());
            if (Images != null)
            {
                if (Images[0] != null)
                {
                    foreach (string[] im in Images)
                    {
                        ImageModel NewImage = new ImageModel()
                        {
                            Name  = im[0].ToString(),
                            Type  = im[1].ToString(),
                            Image = im[2].ToString()
                        };
                        NewImage = NewImage.SaveThis();
                        ProductImageModel ProductImage = new ProductImageModel()
                        {
                            Product = Id,
                            Image   = NewImage.Id
                        };
                        ProductImage = ProductImage.SaveThis();
                    }
                }
            }
            return(this);
        }
Ejemplo n.º 2
0
 private void UpdateImage()
 {
     if (this.CheckAChange("Image"))
     {
         // Get Image If exists
         ImageModel MyImage = this.GetImageModelFromDb();
         if (MyImage == null)
         {
             // We don't have an old Image => create new Image
             foreach (string[] im in Images)
             {
                 ImageModel NewImage = new ImageModel()
                 {
                     Name  = im[0].ToString(),
                     Type  = im[1].ToString(),
                     Image = im[2].ToString()
                 };
                 NewImage = NewImage.SaveThis();
                 ProductImageModel ProductImage = new ProductImageModel()
                 {
                     Product = Id,
                     Image   = NewImage.Id
                 };
                 ProductImage = ProductImage.SaveThis();
             }
         }
         else
         {
             // We have an old Image
             if (Images == null || Images.Count == 0)
             {
                 // Delete old Image and ProductImage row
                 ProductImageModel prod_img = new ProductImageModel();
                 prod_img = prod_img.FillMeByImageId(MyImage.Id);
                 prod_img.Delete();
                 MyImage.Delete();
             }
             else
             {
                 // Update new Image
                 foreach (string[] im in Images)
                 {
                     MyImage.Name  = im[0].ToString();
                     MyImage.Type  = im[1].ToString();
                     MyImage.Image = im[2].ToString();
                 }
                 MyImage = MyImage.UpdateThis();
             }
         }
     }
 }