Пример #1
0
        public ActionResult Update([FromServices] Context context, [FromBody] ProdutoLinha model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    context.ProdutoLinha.Attach(model);
                    context.Entry(model).State = EntityState.Modified;
                    context.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return(BadRequest(e.Message));
                }
            }

            return(Ok(model));
        }
Пример #2
0
        public void PreencherByVA(ProdutoVa va, Territorio territorio, Usuario usuario, ProdutoLinha linha)
        {
            this.Id = va.Id.ToString();
            this.ProductId = va.Produto.Id.ToString();

            if (va.Status == (char)ProdutoVa.EnumStatus.Teste)
            {
                this.Title = va.Produto.Nome;
            }
            else
            {
                this.Title = va.Produto.Nome;
            }

            this.Name = va.Nome;
            this.Description = va.Descricao;
            this.Keywords = va.PalavrasChave;

            if (va.Status == (char)ProdutoVa.EnumStatus.Teste || va.Versao == null)
            {
                this.Version = va.VersaoTeste.ToString();
            }
            else
            {
                if (va.Versao != null)
                {
                    this.Version = va.Versao.Value.ToString();
                }
            }

            this.Status = va.GetStatusWS();

            if (territorio != null)
            {
                if (territorio.ProdutoLinha != null) {
                    this.LineName = territorio.ProdutoLinha.Nome;
                }
            }
            else if (linha != null)
            {
                this.LineName = linha.Nome;
            }
            else
            {
                //territorio simulado por usuario
                this.LineName = "TESTE";
            }

            if (territorio != null)
            {
                this.BundleURL = va.GetUrlDownload(territorio.Id);
            }
            else if (usuario != null)
            {
                //territorio simulado por usuario
                this.BundleURL = va.GetUrlDownload(usuario.TerritorioSimulado);
            }
            else if (linha != null)
            {
                this.BundleURL = va.GetUrlDownload(linha.TerritorioSimulado);
            }

            this.Pharmacy = va.ProdutoVaSlides.Any(s => s.ProdutoVaSlideArquivos.First().Tipo == (char)ProdutoVaSlideArquivo.EnumTipoArquivo.Farmacia);

            if (va.ProdutoVaCategoria != null) {
                this.CategoryId = va.ProdutoVaCategoria.Id.ToString();
                this.Category = va.ProdutoVaCategoria.Nome;
                this.Type = va.ProdutoVaCategoria.Tipo.ToString();
            }
        }