Exemplo n.º 1
0
        public static IEnumerable <SubCategoriaViewModel> ListaCategoriaToListaCategoriaViewModel(IEnumerable <SubCategoria> listaSubCategoria)
        {
            IList <SubCategoriaViewModel> listaSubCategoriaViewModel = null;

            if (listaSubCategoria != null)
            {
                SubCategoriaViewModel subCategoriaViewModel = null;
                listaSubCategoriaViewModel = new List <SubCategoriaViewModel>();

                foreach (var subCategoria in listaSubCategoria)
                {
                    subCategoriaViewModel = new SubCategoriaViewModel();

                    subCategoriaViewModel.SubCategoriaId = subCategoria.SubCategoriaId;
                    subCategoriaViewModel.Descricao      = subCategoria.Descricao;
                    subCategoriaViewModel.Slug           = subCategoria.Slug;

                    subCategoriaViewModel.IdCategoria = subCategoria.Categoria.CategoriaId;

                    if (subCategoria.Campos != null && subCategoria.Campos.Count > 0)
                    {
                        subCategoriaViewModel.CamposViewModel = new List <CampoViewModel>();

                        foreach (var campo in subCategoria.Campos)
                        {
                            CampoViewModel campoViewModel = new CampoViewModel();

                            campoViewModel.CampoId     = campo.CampoId;
                            campoViewModel.Obrigatorio = campo.Obrigatorio;
                            campoViewModel.Ordem       = campo.Ordem;
                            campoViewModel.Descricao   = campo.Descricao;

                            campoViewModel.IdTipoCampo   = campo.TipoCampo.TipoCampoId.ToString();
                            campoViewModel.NomeTipoCampo = campo.TipoCampo.Nome;

                            if (campo.TextoCampos != null && campo.TextoCampos.Count > 0)
                            {
                                campoViewModel.TextoCampos = new List <TextoCampoViewModel>();

                                foreach (var textoCampo in campo.TextoCampos)
                                {
                                    TextoCampoViewModel textoCampoViewModel = new TextoCampoViewModel();

                                    textoCampoViewModel.TextoCampoId = textoCampo.TextoCampoId;
                                    textoCampoViewModel.Texto        = textoCampo.Texto;
                                    textoCampoViewModel.Valor        = textoCampo.Valor;

                                    campoViewModel.TextoCampos.Add(textoCampoViewModel);
                                }
                            }
                            subCategoriaViewModel.CamposViewModel.Add(campoViewModel);
                        }
                    }
                    listaSubCategoriaViewModel.Add(subCategoriaViewModel);
                }
            }
            return(listaSubCategoriaViewModel);
        }
Exemplo n.º 2
0
        public static SubCategoria CategoriaViewModelToCategoria(SubCategoriaViewModel subCategoriaViewModel)
        {
            SubCategoria subCategoria = null;

            if (subCategoriaViewModel != null)
            {
                subCategoria = new SubCategoria();

                subCategoria.SubCategoriaId = subCategoriaViewModel.SubCategoriaId;
                subCategoria.Descricao      = subCategoriaViewModel.Descricao;
                subCategoria.Slug           = subCategoriaViewModel.Slug;

                subCategoria.Categoria = new Categoria {
                    CategoriaId = subCategoriaViewModel.IdCategoria
                };

                if (subCategoriaViewModel.CamposViewModel != null && subCategoriaViewModel.CamposViewModel.Count > 0)
                {
                    subCategoria.Campos = new List <Campo>();

                    foreach (var campoViewModel in subCategoriaViewModel.CamposViewModel)
                    {
                        Campo campo = new Campo();

                        campo.CampoId     = campoViewModel.CampoId;
                        campo.Obrigatorio = campoViewModel.Obrigatorio;
                        campo.Ordem       = campoViewModel.Ordem;
                        campo.Descricao   = campoViewModel.Descricao;

                        campo.TipoCampo = new TipoCampo()
                        {
                            TipoCampoId = Convert.ToInt32(campoViewModel.IdTipoCampo ?? "0")
                        };

                        if (campoViewModel.TextoCampos != null && campoViewModel.TextoCampos.Count > 0)
                        {
                            campo.TextoCampos = new List <TextoCampo>();

                            foreach (var textoCampoViewModel in campoViewModel.TextoCampos)
                            {
                                TextoCampo textoCampo = new TextoCampo();

                                textoCampo.TextoCampoId = textoCampoViewModel.TextoCampoId;
                                textoCampo.Texto        = textoCampoViewModel.Texto;
                                textoCampo.Valor        = textoCampoViewModel.Valor;

                                campo.TextoCampos.Add(textoCampo);
                            }
                        }

                        subCategoria.Campos.Add(campo);
                    }
                }
            }

            return(subCategoria);
        }
 public static void AtualizarSubCategoria(this SubCategoria subcategoria, SubCategoriaViewModel SubCategoriaVM, Usuario usuario)
 {
     subcategoria.UsuarioAlteracao = usuario;
     subcategoria.Ativo            = SubCategoriaVM.Ativo;
     subcategoria.DescSubCategoria = SubCategoriaVM.DescSubCategoria;
     subcategoria.CategoriaId      = SubCategoriaVM.CategoriaId;
     subcategoria.Id          = SubCategoriaVM.Id;
     subcategoria.DtAlteracao = DateTime.Now;
 }
Exemplo n.º 4
0
        public async Task <PartialViewResult> Cadastrar(SubCategoriaViewModel subCategoria)
        {
            string dataJSon = HelpObjectJSon <SubCategoriaViewModel> .Serialize(subCategoria);

            var result = await _chamadaApiSubCategoria2.Post(dataJSon, WebApiGestaoCategoria.AdminCadastrarSubCategoria);

            ViewBag.ExibirMensagem = Mensagem.Exibir(result.ToString());

            return(PartialView("_Mensagem"));
        }
Exemplo n.º 5
0
        public async Task <bool> Cadastrar(SubCategoriaViewModel categoria)
        {
            bool ehCadastrado = false;

            //Categoria categoria = HelpObjectJSon<Categoria>.Deserialize(dataJson);

            ehCadastrado = _subCategoriaService.Cadastrar(categoria);

            return(await Task.FromResult(ehCadastrado));
        }
Exemplo n.º 6
0
        public ActionResult Dinamico(String slugcategoria, String slugsubcategoria)
        {
            SubCategoriaViewModel model = new SubCategoriaViewModel(slugcategoria, slugsubcategoria);

            if (model == null || model.subCategoria == null)
            {
                return(RedirectToAction("PaginaNaoEncontrada", "Erro"));
                //return HttpNotFound();
            }

            ViewBag.IdCategoria = model.subCategoria.Tab_Categoria.idcategoria;

            return(View("Dinamico", model));
        }
        public async Task <IActionResult> Create(SubCategoriaViewModel subCategoriaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(subCategoriaViewModel));
            }

            subCategoriaViewModel.DataCadastro = DateTime.Now;

            var subCategoria = _mapper.Map <SubCategoria>(subCategoriaViewModel);

            await _subCategoriaRepository.Adicionar(subCategoria);

            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult InsertSubCategoria(SubCategoriaViewModel subcategoria, HttpPostedFileBase file, string idcat)
        {
            var    generateGuid = Guid.NewGuid();
            string ruta         = $"Image/{generateGuid}{System.IO.Path.GetExtension(file.FileName)}";
            string filePath     = Path.Combine(Server.MapPath($"~/Image/{generateGuid}{Path.GetExtension(file.FileName)}"));

            file.SaveAs(filePath);

            BLSubCategorias db = new BLSubCategorias();

            subcategoria.UrlImagen   = ruta;
            subcategoria.IdCategoria = Guid.Parse(idcat);
            var result = db.InsertSubcategoria(subcategoria).Result;

            return(View("Index"));
        }
Exemplo n.º 9
0
        public async Task <bool> InsertSubcategoria(SubCategoriaViewModel subcategoria)
        {
            bool validate = false;

            using (var db = new TicketsEntities())
            {
                var result = db.spInsSubCategoria(subcategoria.IdCategoria, subcategoria.Nombre,
                                                  subcategoria.Descripcion, subcategoria.UrlImagen, subcategoria.PrecioNormal,
                                                  subcategoria.PrecioDescuento, subcategoria.CodigoDescuento);
                if (result < 0)
                {
                    validate = true;
                }

                return(validate);
            }
        }
Exemplo n.º 10
0
        public static SubCategoriaViewModel CategoriaToCategoriaViewModel(SubCategoria subCategoria)
        {
            SubCategoriaViewModel subCategoriaViewModel = null;

            if (subCategoria != null)
            {
                subCategoriaViewModel = new SubCategoriaViewModel();

                subCategoriaViewModel.SubCategoriaId = subCategoria.SubCategoriaId;
                subCategoriaViewModel.Descricao      = subCategoria.Descricao;
                subCategoriaViewModel.Slug           = subCategoria.Slug;

                subCategoriaViewModel.IdCategoria = subCategoria.Categoria.CategoriaId;
            }

            return(subCategoriaViewModel);
        }
 public HttpResponseMessage Post(SubCategoriaViewModel subcategoria)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var subcategoriaViewModel = Mapper.Map <SubCategoriaViewModel, SubCategoria>(subcategoria);
             _subcategoriaApp.Add(subcategoriaViewModel);
             return(Request.CreateResponse(HttpStatusCode.Created));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.PreconditionFailed));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
Exemplo n.º 12
0
        public HttpResponseMessage Inserir(HttpRequestMessage request, SubCategoriaViewModel SubCategoriaViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));

                    SubCategoria novaSubCategoria = new SubCategoria()
                    {
                        UsuarioCriacao = usuario,
                        DtCriacao = DateTime.Now,
                        Ativo = SubCategoriaViewModel.Ativo,
                        DescSubCategoria = SubCategoriaViewModel.DescSubCategoria,
                        CategoriaId = SubCategoriaViewModel.CategoriaId
                    };

                    _subCategoriaRep.Add(novaSubCategoria);

                    _unitOfWork.Commit();

                    //Cria Diretório quando se cadastra um nova subcategoria
                    CriarDiretorioImagens(SubCategoriaViewModel, novaSubCategoria);


                    // Update view model
                    SubCategoriaViewModel = Mapper.Map <SubCategoria, SubCategoriaViewModel>(novaSubCategoria);
                    response = request.CreateResponse(HttpStatusCode.Created, SubCategoriaViewModel);
                }

                return response;
            }));
        }
Exemplo n.º 13
0
        public HttpResponseMessage Atualizar(HttpRequestMessage request, SubCategoriaViewModel subcategoriaViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    SubCategoria novaSubCategoria = _subCategoriaRep.GetSingle(subcategoriaViewModel.Id);

                    //Cria Diretório quando se cadastra um nova subcategoria
                    CriarDiretorioImagens(subcategoriaViewModel, novaSubCategoria);

                    if (novaSubCategoria.CategoriaId != subcategoriaViewModel.CategoriaId && novaSubCategoria.Produtos.Count > 0)
                    {
                        response = request.CreateResponse(HttpStatusCode.PreconditionFailed, "Não é possível alterar a Categoria desta sub-categoria, pois já existem imagens associadas a ela.");
                    }
                    else
                    {
                        Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));

                        novaSubCategoria.AtualizarSubCategoria(subcategoriaViewModel, usuario);

                        _unitOfWork.Commit();

                        // Update view model
                        subcategoriaViewModel = Mapper.Map <SubCategoria, SubCategoriaViewModel>(novaSubCategoria);
                        response = request.CreateResponse(HttpStatusCode.OK, subcategoriaViewModel);
                    }
                }

                return response;
            }));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Método para Criar diretório Imagens do Produto
        /// </summary>
        /// <param name="SubCategoriaViewModel"></param>
        /// <param name="novaSubCategoria"></param>
        private void CriarDiretorioImagens(SubCategoriaViewModel SubCategoriaViewModel, SubCategoria novaSubCategoria)
        {
            var categoria = _categoriaRep.GetSingle(SubCategoriaViewModel.CategoriaId);


            var amb = Environment.GetEnvironmentVariable("Amb_EconomizaJa");


            //usa uma variável de ambiente para saber se está executando o projeto no computador ou servidor e cria a pasta
            //DirectoryInfo diretorio = new DirectoryInfo(ConfigurationManager.AppSettings[amb+"_CamImagens"] +
            //                       Util.RemoverAcentos(categoria.DescCategoria.Replace(" ", "_")) + @"\" + Util.RemoverAcentos(novaSubCategoria.DescSubCategoria.Replace(" ", "_")));

            DirectoryInfo diretorio = new DirectoryInfo(ConfigurationManager.AppSettings[amb + "_CamImagens"] +
                                                        categoria.Id.ToString() + @"\" + novaSubCategoria.Id.ToString());


            //Chama o método para verificar se diretório existe, caso exista ele não cria a pasta.
            if (VerificaDiretorioExiste(diretorio))
            {
                diretorio.Create();
            }
        }
Exemplo n.º 15
0
        public async Task <List <SubCategoriaViewModel> > GetSubCategoria(Guid IdCategoria)
        {
            var ListSubcategoria = new List <SubCategoriaViewModel>();

            using (var db = new TicketsEntities())
            {
                var result = db.spSelSubCategorias(IdCategoria);
                foreach (var item in result)
                {
                    var subcategoria = new SubCategoriaViewModel();
                    subcategoria.Nombre          = item.Nombre;
                    subcategoria.CodigoDescuento = item.CodigoDescuento;
                    subcategoria.Descripcion     = item.Descripcion;
                    subcategoria.IdCategoria     = item.IdCategoria;
                    subcategoria.IdSubCategoria  = item.IdSubCategoria;
                    subcategoria.PrecioDescuento = item.PrecioDescuento;
                    subcategoria.PrecioNormal    = item.PrecioNormal;
                    subcategoria.UrlImagen       = item.UrlImagen;
                    ListSubcategoria.Add(subcategoria);
                }
            }

            return(ListSubcategoria);
        }
Exemplo n.º 16
0
        public bool Cadastrar(SubCategoriaViewModel subCategoriaViewModel)
        {
            bool ehCadastrado = false;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    var subCategoria = SubCategoriaMapper.CategoriaViewModelToCategoria(subCategoriaViewModel);

                    _tipoCampoRepository.GetById(Convert.ToInt32(subCategoriaViewModel.CamposViewModel[1].IdTipoCampo));

                    subCategoria.Categoria = _categoriaRepository.GetById(subCategoriaViewModel.IdCategoria);

                    if (subCategoria.Campos != null && subCategoria.Campos.Count > 0)
                    {
                        foreach (var campo in subCategoria.Campos)
                        {
                            campo.TipoCampo = _tipoCampoRepository.GetById(campo.TipoCampo.TipoCampoId);
                        }
                    }

                    _subCategoriaRepository.Cadastrar(subCategoria);

                    ehCadastrado = true;

                    scope.Complete();
                }
            }
            catch (Exception eve)
            {
                // log(ex.Message);
            }

            return(ehCadastrado);
        }
Exemplo n.º 17
0
        public void Cadastrar_sub_Categoria()
        {
            SubCategoriaViewModel subCategoria = new SubCategoriaViewModel();

            subCategoria.Slug      = "veiculos-som";
            subCategoria.Descricao = "Som de veiculos";

            for (int i = 0; i < 2; i++)
            {
                CampoViewModel campo = new CampoViewModel();

                campo.Descricao   = "Descricao " + i;
                campo.Obrigatorio = true;
                campo.Ordem       = (short)i;
                // campo.TipoCampoViewModel = new TipoCampoViewModel() { TipoCampoId = i };

                for (int j = 0; j < 2; j++)
                {
                    TextoCampoViewModel textoCampo = new TextoCampoViewModel();

                    textoCampo.Texto = "Texto " + i;
                    textoCampo.Valor = "Valor " + i;

                    campo.TextoCampos = new List <TextoCampoViewModel>();

                    campo.TextoCampos.Add(textoCampo);
                }
                subCategoria.CamposViewModel.Add(campo);
            }

            SubCategoriaController subCategoriaController = new SubCategoriaController();

            //ViewResult result = (ViewResult)subCategoriaController.Cadastrar(subCategoria);

            //Assert.AreEqual("TRUE", result.Model.ToString());
        }
 public void Update(SubCategoriaViewModel subCategoriaViewModel)
 {
     _subCategoriaService.Update(Mapper.Map <SubCategoriaViewModel, SubCategoria>(subCategoriaViewModel));
 }
        public void Remove(SubCategoriaViewModel subCategoriaViewModel)
        {
            var subCategoria = _subCategoriaService.GetById(subCategoriaViewModel.SubCategoriaId);

            _subCategoriaService.Remove(subCategoria);
        }
 public void Add(SubCategoriaViewModel subCategoriaViewModel)
 {
     _subCategoriaService.Add(Mapper.Map <SubCategoriaViewModel, SubCategoria>(subCategoriaViewModel));
 }
        public async Task <bool> InsertSubCategoria(SubCategoriaViewModel sub)
        {
            var result = await db.InsertSubcategoria(sub);

            return(result);
        }
        //public async Task<IActionResult> Details(Guid? id)
        //{
        //    if (id == null)
        //    {
        //        return NotFound();
        //    }

        //    var subCategoriaViewModel = await _context.SubCategoriaViewModel
        //        .Include(s => s.Categoria)
        //        .FirstOrDefaultAsync(m => m.Id == id);
        //    if (subCategoriaViewModel == null)
        //    {
        //        return NotFound();
        //    }

        //    return View(subCategoriaViewModel);
        //}

        //public async Task<IActionResult> Edit(Guid? id)
        //{
        //    if (id == null)
        //    {
        //        return NotFound();
        //    }

        //    var subCategoriaViewModel = await _context.SubCategoriaViewModel.FindAsync(id);
        //    if (subCategoriaViewModel == null)
        //    {
        //        return NotFound();
        //    }
        //    ViewData["CategoriaId"] = new SelectList(_context.CategoriaViewModel, "Id", "Nome", subCategoriaViewModel.CategoriaId);
        //    return View(subCategoriaViewModel);
        //}

        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public async Task<IActionResult> Edit(Guid id, [Bind("Nome,CategoriaId,Id,Ativo")] SubCategoriaViewModel subCategoriaViewModel)
        //{
        //    if (id != subCategoriaViewModel.Id)
        //    {
        //        return NotFound();
        //    }

        //    if (ModelState.IsValid)
        //    {
        //        try
        //        {
        //            _context.Update(subCategoriaViewModel);
        //            await _context.SaveChangesAsync();
        //        }
        //        catch (DbUpdateConcurrencyException)
        //        {
        //            if (!SubCategoriaViewModelExists(subCategoriaViewModel.Id))
        //            {
        //                return NotFound();
        //            }
        //            else
        //            {
        //                throw;
        //            }
        //        }
        //        return RedirectToAction(nameof(Index));
        //    }
        //    ViewData["CategoriaId"] = new SelectList(_context.CategoriaViewModel, "Id", "Nome", subCategoriaViewModel.CategoriaId);
        //    return View(subCategoriaViewModel);
        //}

        //public async Task<IActionResult> Delete(Guid? id)
        //{
        //    if (id == null)
        //    {
        //        return NotFound();
        //    }

        //    var subCategoriaViewModel = await _context.SubCategoriaViewModel
        //        .Include(s => s.Categoria)
        //        .FirstOrDefaultAsync(m => m.Id == id);
        //    if (subCategoriaViewModel == null)
        //    {
        //        return NotFound();
        //    }

        //    return View(subCategoriaViewModel);
        //}

        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        //public async Task<IActionResult> DeleteConfirmed(Guid id)
        //{
        //    var subCategoriaViewModel = await _context.SubCategoriaViewModel.FindAsync(id);
        //    _context.SubCategoriaViewModel.Remove(subCategoriaViewModel);
        //    await _context.SaveChangesAsync();
        //    return RedirectToAction(nameof(Index));
        //}

        //private bool SubCategoriaViewModelExists(Guid id)
        //{
        //    return _context.SubCategoriaViewModel.Any(e => e.Id == id);
        //}

        private async Task <SubCategoriaViewModel> CarregaCategorias(SubCategoriaViewModel subCategoriaViewModel)
        {
            subCategoriaViewModel.Categorias = _mapper.Map <IEnumerable <CategoriaViewModel> >(await _categoriaRepository.ObterTodos());
            return(subCategoriaViewModel);
        }