Пример #1
0
        public async Task <IActionResult> Create([Bind("IdSegmento,IdEmpresa,DesSegmento,Ativo")] TbSegmentoEmpresa tbSegmentoEmpresa)
        {
            if (ModelState.IsValid)
            {
                var companyFielWasCreated = await segmentoEmpresaRepository.InsertSegmentoEmpresa(tbSegmentoEmpresa);

                if (companyFielWasCreated)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["IdEmpresa"] = new SelectList(await empresaRepository.GetEmpresas(), "IdEmpresa", "RazaoSocial", tbSegmentoEmpresa.IdEmpresa);
            return(View(tbSegmentoEmpresa));
        }
        public async Task <bool> UpdateSegmentoEmpresa(TbSegmentoEmpresa segmentoEmpresa)
        {
            try
            {
                context.Update(segmentoEmpresa);
                await context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("IdSegmento,IdEmpresa,DesSegmento,Ativo")] TbSegmentoEmpresa tbSegmentoEmpresa)
        {
            if (id != tbSegmentoEmpresa.IdSegmento)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var companyFieldWasUpdated = await segmentoEmpresaRepository.UpdateSegmentoEmpresa(tbSegmentoEmpresa);

                if (companyFieldWasUpdated)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["IdEmpresa"] = new SelectList(await empresaRepository.GetEmpresas(), "IdEmpresa", "RazaoSocial", tbSegmentoEmpresa.IdEmpresa);
            return(View(tbSegmentoEmpresa));
        }