//Construtor
        public ProdutoFormValidator()
        {
            RuleFor(x => x.Produto.idTipoProduto)
            .NotEmpty().WithMessage("Informe qual é o Tipo de Produto.");

            RuleFor(x => x.Produto.nome)
            .NotEmpty().WithMessage("Informe um nome para o Produto.");

            RuleFor(x => x.Produto.nome)
            .Must((x, nome) => !this.existe(x))
            .WithMessage("Já existe um Produto cadastrado com esse nome.");

            When(x => (x.Produto.flagCalcularFrete == true && x.Produto.flagFreteGratis != true), () => {
                RuleFor(x => x.Produto.peso)
                .GreaterThan(0).WithMessage("O Peso do produto é necessário para calcular o frete.");
            });
            RuleFor(x => x.Produto.descricaoResumida).Length(0, 255).WithMessage("A descrição deve ser preenchida para detalhar o produto max. 255 caracteres.");

            //RuleFor(x => x.Produto.descricaoCompleta)
            //	.Length(0, 1000)
            //	.WithMessage("A descrição completa deve ter no máximo 1000 caracteres.");

            //When(x => (x.Produto.flagCortesia == true), () => {
            //    RuleFor(x => x.Produto.valor)
            //        .Equal(new Decimal(0))
            //        .WithMessage("Para produtos de cortesia, o valor deve ser 0,00.");
            //});

            When(x => x.Produto.flagCortesia != true, () => {
                RuleFor(x => x.Produto.valor)
                .GreaterThan(new Decimal(0)).WithMessage("Informe o valor do produto.");
            });

            When(x => (x.OImagem != null), () => {
                RuleFor(x => x.OImagem)
                .Must((x, OImagem) => UploadConfig.validarImagem(OImagem)).WithMessage("Envie uma imagem válida.");
            });
        }
        //Salvar o arquivo em disco e configurar os caminhos para buscar posteriormente
        public bool upload(ref ArquivoUpload OArquivo, HttpPostedFileBase FileUpload, string pathUpload = "", List <ThumbDTO> listaThumb = null)
        {
            string pathBaseAbs = String.IsNullOrEmpty(pathUpload) ? UtilConfig.pathAbsUpload(OArquivo.idOrganizacao.toInt()) : pathUpload;

            string pathPasta = String.Concat(OArquivo.entidade, "/", OArquivo.categoria, "/", OArquivo.idReferenciaEntidade, "/");

            string pathPastaThumb = String.Concat(pathPasta, "thumb/");

            string nomeArquivo = FileUpload.FileName ?? String.Concat(OArquivo.id.ToString(), OArquivo.extensao);

            OArquivo.path        = String.Concat(pathPasta, nomeArquivo);
            OArquivo.pathThumb   = pathPastaThumb;
            OArquivo.nomeArquivo = nomeArquivo;

            //Criar os diretórios necessários.
            UtilIO.createFolder(Path.Combine(pathBaseAbs, pathPasta));
            UtilIO.createFolder(Path.Combine(pathBaseAbs, pathPastaThumb));

            //Salvar o arquivo principal
            FileUpload.SaveAs(String.Concat(pathBaseAbs, OArquivo.path));

            //Caso seja uma imagem, fazer o redimensionamento para o tamanho padrão do sistema.
            if (UploadConfig.validarImagem(FileUpload))
            {
                Instructions InstructionsImage = new Instructions {
                    Format = OArquivo.extensao.Replace(".", ""), Mode = FitMode.Max
                };

                //Tamanho padrão para apresentação no grid do sistema
                InstructionsImage.Height = 100;

                string diretorioThumbSistema        = String.Concat(pathPastaThumb, "sistema");
                string diretorioArquivoThumbSistema = String.Concat(diretorioThumbSistema, "/", nomeArquivo);

                UtilIO.createFolder(Path.Combine(pathBaseAbs, diretorioThumbSistema));

                FileUpload.InputStream.Seek(0, SeekOrigin.Begin);
                ImageBuilder.Current.Build(new ImageJob(FileUpload, Path.Combine(pathBaseAbs, diretorioArquivoThumbSistema), InstructionsImage));

                if (listaThumb == null || listaThumb.Count == 0)
                {
                    listaThumb = new List <ThumbDTO>();
                    listaThumb.Add(new ThumbDTO {
                        folderName = "sistema", height = 50, width = 0
                    });
                }

                foreach (var Item in listaThumb)
                {
                    InstructionsImage.Width  = Item.width;
                    InstructionsImage.Height = Item.height;

                    string diretorioThumb        = String.Concat(pathPastaThumb, Item.folderName);
                    string diretorioArquivoThumb = String.Concat(diretorioThumb, "/", nomeArquivo);

                    UtilIO.createFolder(Path.Combine(pathBaseAbs, diretorioThumb));

                    ImageBuilder.Current.Build(new ImageJob(FileUpload, Path.Combine(pathBaseAbs, diretorioArquivoThumb), InstructionsImage));
                }
            }

            if (!File.Exists(String.Concat(pathBaseAbs, OArquivo.path)))
            {
                int idArquivo = OArquivo.id;

                this.db.ArquivoUpload.Where(x => x.id == idArquivo).Delete();

                return(false);
            }

            this.db.SaveChanges();

            return(true);
        }