예제 #1
0
 public void Update(LastUserSettings lastUserSettings)
 {
     try
     {
         db.Entry(lastUserSettings).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
     }
 }
 public void Update(RawSound rawSound)
 {
     try
     {
         db.Entry(rawSound).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
     }
 }
예제 #3
0
 public void SaveProduto(Produto produto)
 {
     if (produto.Id == null)
     {
         context.Produtos.Add(produto);
     }
     else
     {
         context.Entry(produto).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
 public void Delete(SurveyParameterMember surveyParameterMember)
 {
     try
     {
         db.Entry(surveyParameterMember).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
     }
 }
예제 #5
0
 public void Delete(SurveyKeyValue surveyKeyValue)
 {
     try
     {
         db.Entry(surveyKeyValue).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
     }
 }
예제 #6
0
 public void Update(Session session)
 {
     try
     {
         db.Entry(session).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
     }
 }
예제 #7
0
 public void Save(ClientAgent entity)
 {
     if (entity.ClientAgentId > 0)
     {
         _context.ClientAgents.Attach(entity);
         _context.Entry <ClientAgent>(entity).State = System.Data.EntityState.Modified;
     }
     else
     {
         _context.ClientAgents.Add(entity);
     }
     _context.SaveChanges();
 }
예제 #8
0
 public void Delete(UserProfile user)
 {
     try
     {
         db.Entry(user).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         throw ex;
     }
 }
예제 #9
0
 public void Update(PotentialUser pu)
 {
     try
     {
         db.Entry(pu).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         throw ex;
     }
 }
예제 #10
0
        void sapp(Blog blog, IList <Post> posts)
        {
            var blogEntry = _eFContext.Entry(blog);

            Console.WriteLine($"    Blog '{blog.BlogId}' is in state {blogEntry.State} with {posts.Count} posts referenced.");
            foreach (var post in posts)
            {
                var postEntry = _eFContext.Entry(post);

                Console.WriteLine(
                    $"      Post '{post.PostId}' is in state {postEntry.State} " +
                    $"with FK '{post.BlogId?.ToString() ?? "null"}' and {(post.Blog == null ? "no reference to a blog." : $"reference to blog '{post.BlogId}'.")}");
            }
예제 #11
0
 public void Save(Role entity)
 {
     if (entity.RoleId > 0)
     {
         _context.Roles.Attach(entity);
         _context.Entry <Role>(entity).State = System.Data.EntityState.Modified;
     }
     else
     {
         _context.Roles.Add(entity);
     }
     _context.SaveChanges();
 }
예제 #12
0
 public void Save(User entity)
 {
     if (entity.UserId > 0)
     {
         _context.Users.Attach(entity);
         _context.Entry <User>(entity).State = System.Data.EntityState.Modified;
     }
     else
     {
         _context.Users.Add(entity);
     }
     _context.SaveChanges();
 }
예제 #13
0
 public void Delete(MenuOption option)
 {
     try
     {
         db.Entry(option).State = EntityState.Deleted;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         throw ex;
     }
 }
예제 #14
0
 public void Save(Menu entity)
 {
     if (entity.MenuId > 0)
     {
         _context.Menus.Attach(entity);
         _context.Entry <Menu>(entity).State = System.Data.EntityState.Modified;
     }
     else
     {
         _context.Menus.Add(entity);
     }
     _context.SaveChanges();
 }
예제 #15
0
 public void Save(Criteria entity)
 {
     if (entity.CriteriaId > 0)
     {
         _context.Criterias.Attach(entity);
         _context.Entry <Criteria>(entity).State = System.Data.EntityState.Modified;
     }
     else
     {
         _context.Criterias.Add(entity);
     }
     _context.SaveChanges();
 }
예제 #16
0
 public void Save(Property entity)
 {
     if (entity.PropertyId > 0)
     {
         _context.Properties.Attach(entity);
         _context.Entry <Property>(entity).State = System.Data.EntityState.Modified;
     }
     else
     {
         _context.Properties.Add(entity);
     }
     _context.SaveChanges();
 }
예제 #17
0
        public async Task <bool> Save(TblBp tbl)
        {
            try
            {
                _db.Entry(tbl).State = EntityState.Added;
                await _db.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #18
0
        public void Update(Sound sound)
        {
            try
            {
                _ghlr.UpdateDateLastModified(sound.GHLocationID);

                db.Entry(sound).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
            }
        }
 public List <T> AddBulk(List <T> tList)
 {
     //_context.Configuration.AutoDetectChangesEnabled = false;
     tList.ForEach(t =>
     {
         _context.Entry(t).State = EntityState.Added;
         t.CreaUser = sessionInfo._BaseModel.CreaUser;
         t.CreaDate = DateTime.Now;
     });
     _context.Set <T>().AddRange(tList);
     //_context.Configuration.AutoDetectChangesEnabled = true;
     _context.ChangeTracker.DetectChanges();
     return(tList);
 }
예제 #20
0
        //Save Usuarios
        public void SaveUsuario(Usuario usuario)
        {
            var local = context.Usuarios.Local.FirstOrDefault(f => f.Id == usuario.Id);

            if (usuario.Id == null)
            {
                context.Usuarios.Add(usuario);
            }
            else
            {
                context.Entry(local).State   = EntityState.Detached;
                context.Entry(usuario).State = EntityState.Modified;
            }
            context.SaveChanges();
        }
예제 #21
0
        public void Delete(T entity)
        {
            var ativoProperty = entity.GetType().GetProperty("Ativo");

            if (ativoProperty == null)
            {
                throw new Exception();
            }
            else
            {
                ativoProperty.SetValue(entity, false);
                dbSet.Attach(entity);
                context.Entry(entity).State = EntityState.Modified;
            }
        }
예제 #22
0
        public ActionResult Edit([Bind(Include = "ProdutoId,Nome,Ativo,CategoriaId,FornecedorId")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                _context.Entry(produto).State = EntityState.Modified;
                _context.SaveChanges();

                TempData["Message"] = "Produto " + produto.Nome.ToUpper() + " foi alterado";
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoriaId  = new SelectList(_context.Categorias, "CategoryId", "Name", produto.CategoriaId);
            ViewBag.FornecedorId = new SelectList(_context.Fornecedores, "SupplierId", "Name", produto.FornecedorId);
            return(View(produto));
        }
예제 #23
0
        public IHttpActionResult PutProduct(string id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.Id)
            {
                return(BadRequest());
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #24
0
        public IHttpActionResult PutBook(Guid id, Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.BookId)
            {
                return(BadRequest());
            }

            db.Entry(book).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #25
0
 public void GravarGaragem(Garagem garagem)
 {
     try
     {
         using EFContext Context = new EFContext();
         if (garagem.GaragemId == null)
         {
             Context.Garagens.Add(garagem);
         }
         else
         {
             AttachItem(garagem, Context);
             Context.Entry(garagem).State = EntityState.Modified;
         }
         Context.SaveChanges();
     }
     catch (DbUpdateException ex) when((ex.InnerException.InnerException is SqlException && (ex.InnerException.InnerException as SqlException).Number == 2601))
     {
         throw new Exception("Já existe garagem com CNPJ idêntico registrada", ex);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #26
0
 public void AlterarUsuarioFunc(UsuarioFunc usuario)
 {
     using EFContext Context = new EFContext();
     AttachItem(usuario, Context);
     Context.Entry(usuario).State = EntityState.Modified;
     Context.SaveChanges();
 }
예제 #27
0
 public void GravarVeiculo(Veiculo veiculo)
 {
     try
     {
         using EFContext Context = new EFContext();
         if (veiculo.VeiculoId == null)
         {
             Context.Veiculos.Add(veiculo);
         }
         else
         {
             AttachItem(veiculo, Context);
             Context.Entry(veiculo).State = EntityState.Modified;
         }
         Context.SaveChanges();
     }
     catch (DbUpdateException ex) when((ex.InnerException.InnerException is SqlException && (ex.InnerException.InnerException as SqlException).Number == 2601))
     {
         throw new Exception("Já existe um veiculo com Placa e/ou Código Renavam idêntico(s) registrados", ex);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #28
0
        public ActionResult Alterar(Locacao locacao, int[] FilmeId)
        {
            if (ModelState.IsValid)
            {
                //Salva as alterações na tabela dbo.Locacao
                contexto.Entry(locacao).State = EntityState.Modified;
                contexto.SaveChanges();

                //Exclui os registros da tabela dbo.LocacaoFilmes
                persistencia.ExcluirLocacaoFilmes(locacao.Id);

                //Insere somente os filmes checkados na tabela dbo.LocacaoFilmes
                if (FilmeId != null)
                {
                    foreach (int filmeId in FilmeId)
                    {
                        persistencia.InserirLocacaoFilmes(locacao.Id, filmeId);
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(locacao));
        }
        // PUT api/<controller>/5
        public HttpResponseMessage Put(int id, Calculation calculation)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != calculation.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(calculation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #30
0
 public void GravarPeca(Peca peca)
 {
     try
     {
         using EFContext Context = new EFContext();
         if (peca.PecaId == null)
         {
             Context.Pecas.Add(peca);
         }
         else
         {
             AttachItem(peca, Context);
             Context.Entry(peca).State = EntityState.Modified;
         }
         Context.SaveChanges();
     }
     catch (DbUpdateException ex) when((ex.InnerException.InnerException is SqlException && (ex.InnerException.InnerException as SqlException).Number == 2601))
     {
         throw new Exception("Já existe peça com Lote idêntico registrado", ex);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #31
0
        public void CustomerOrderTest()
        {
            System.Data.Entity.Database.SetInitializer<EFContext>(new CreateDatabaseIfNotExists<EFContext>());
            using (var context = new EFContext())
            {
                context.Database.CreateIfNotExists();
                Customer customer = new Customer
                {
                    Name = "Raviendra",
                    Email = "*****@*****.**",

                };
                context.Entry(customer).State = (EntityState) System.Data.EntityState.Added;
                context.SaveChanges();
            }
        }