public Image Add(Image image, Furniture furniture)
        {
            furniture.Images.Add(image);
            SaveChanges();

            return image;
        }
 public void Resize(Domain.Image image, IEnumerable<ImageSizeSpecification> sizeSpecs, Furniture furniture)
 {
     foreach (var sizeSpec in sizeSpecs)
     {
         ResizeAndSave(image, furniture, sizeSpec.Width, sizeSpec.Height);
     }
 }
        public Domain.Image Upload(HttpPostedFileBase file, Furniture furniture)
        {
            Condition.Requires(file).IsNotNull();
            Condition.Requires(file.ContentLength).IsGreaterThan(0);
            Condition.Requires(file.FileName).IsNotNullOrWhiteSpace();

            Condition.Requires(furniture).IsNotNull();
            Condition.Requires(furniture.PartNumber).IsNotNullOrWhiteSpace();

            string path, fileName;

            UploadImage(file, furniture, out path, out fileName);

            Domain.Image image = Dependencies.ImageRepository.Add(
                new Domain.Image()
                {
                    Path = UploadPath + path,
                    FileName = fileName
                }, furniture);

            return image;
        }
 public void Delete(Furniture furniture)
 {
     Dependencies.FurnitureRepository.Delete(furniture);
 }
 public void Create(Furniture furniture)
 {
     Dependencies.FurnitureRepository.Add(furniture);
 }
 public static void Furniture(Furniture furniture)
 {
     Condition.Requires(furniture).IsNotNull();
     Condition.Requires(furniture.Name).IsNotNullOrWhiteSpace();
     Condition.Requires(furniture.Price).IsGreaterThan(0);
     Condition.Requires(furniture.Text).IsNotNullOrWhiteSpace();
 }
        public void Update(Furniture furniture)
        {
            Validate.Furniture(furniture);

            //Update requires that the furniture have the partnumber
            Condition.Requires(furniture.PartNumber).IsNotNullOrWhiteSpace();

            this.Dependencies.FurnitureRepository.Update(furniture);
        }
        public void SetProfileImage(Furniture furniture, Image image)
        {
            Condition.Requires(furniture).IsNotNull();

            Condition.Requires(image).IsNotNull();
            Condition.Requires(image.ImageId).IsGreaterThan(0);

            furniture.ProfileImageId = image.ImageId;

            Dependencies.FurnitureRepository.Update(furniture);
        }
 public void Resize(Domain.Image image, ImageSizeSpecification sizeSpec, Furniture furniture)
 {
     ResizeAndSave(image, furniture, sizeSpec.Width, sizeSpec.Height);
 }
        private void ResizeAndSave(Domain.Image image, Furniture furniture, int width, int height)
        {
            using (System.Drawing.Image img = System.Drawing.Image.FromFile(GetVirtualPath(image.VirtualPath)))
            {
                using (Bitmap bitmap = new Bitmap(width, height))
                {
                    using (Graphics graphics = Graphics.FromImage(bitmap))
                    {
                        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                        graphics.DrawImage(img, new Rectangle(0, 0, width, height));
                    }

                    string resizedPath = furniture.PartNumber + "/" + width + "x" + height;

                    CreateDirectory(GetVirtualPath(resizedPath));

                    bitmap.Save(GetVirtualPath(resizedPath) + "/" + image.FileName);

                    Dependencies.ImageSizeRepository.Add(new ImageSize
                    {
                        FileName = image.FileName,
                        Path = UploadPath + resizedPath,
                        Height = height,
                        Width = width,
                        ImageId = image.ImageId
                    });
                }
            }
        }
        private void UploadImage(HttpPostedFileBase file, Furniture furniture, out string path, out string fileName)
        {
            path = furniture.PartNumber + "/" + "Original/";
            fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);

            CreateDirectory(GetVirtualPath(path));

            file.SaveAs(Path.Combine(GetVirtualPath(path), fileName));
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Furnitures EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFurnitures(Furniture furniture)
 {
     base.AddObject("Furnitures", furniture);
 }
 /// <summary>
 /// Create a new Furniture object.
 /// </summary>
 /// <param name="partNumber">Initial value of the PartNumber property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="designerId">Initial value of the DesignerId property.</param>
 /// <param name="designYear">Initial value of the DesignYear property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="furnitureTypeId">Initial value of the FurnitureTypeId property.</param>
 /// <param name="profileImageId">Initial value of the ProfileImageId property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="furnitureId">Initial value of the FurnitureId property.</param>
 public static Furniture CreateFurniture(global::System.String partNumber, global::System.String name, global::System.Int32 designerId, global::System.Int32 designYear, global::System.Decimal price, global::System.Int32 furnitureTypeId, global::System.Int32 profileImageId, global::System.String text, global::System.Int32 furnitureId)
 {
     Furniture furniture = new Furniture();
     furniture.PartNumber = partNumber;
     furniture.Name = name;
     furniture.DesignerId = designerId;
     furniture.DesignYear = designYear;
     furniture.Price = price;
     furniture.FurnitureTypeId = furnitureTypeId;
     furniture.ProfileImageId = profileImageId;
     furniture.Text = text;
     furniture.FurnitureId = furnitureId;
     return furniture;
 }
 public void Delete(Furniture furniture)
 {
     Entities.Furnitures.DeleteObject(furniture);
     SaveChanges();
 }
 public void Add(Furniture item)
 {
     Entities.Furnitures.AddObject(item);
     SaveChanges();
 }
 public void Update(Furniture furniture)
 {
     SaveChanges();
 }