Exemplo n.º 1
0
 public bool Delete(Departamento departamento)
 {
     Context.Entry(departamento).State = System.Data.Entity.EntityState.Deleted;
     Context.Departamentos.Remove(departamento);
     Context.SaveChanges();
     return(true);
 }
Exemplo n.º 2
0
 public bool Delete(Usuario usuario)
 {
     Context.Entry(usuario).State = System.Data.Entity.EntityState.Deleted;
     Context.Usuarios.Remove(usuario);
     Context.SaveChanges();
     return(true);
 }
Exemplo n.º 3
0
 public bool Delete(Funcionario funcionario)
 {
     Context.Entry(funcionario).State = System.Data.Entity.EntityState.Deleted;
     Context.Funcionarios.Remove(funcionario);
     Context.SaveChanges();
     return(true);
 }
Exemplo n.º 4
0
 public bool Delete(HorarioExpediente horarioExpediente)
 {
     Context.Entry(horarioExpediente).State = System.Data.Entity.EntityState.Deleted;
     Context.HorariosExpediente.Remove(horarioExpediente);
     Context.SaveChanges();
     return(true);
 }
Exemplo n.º 5
0
        public virtual async Task <EntityEntry <TEntity> > DeleteAsync(object id)
        {
            TEntity entityToDelete = await dbSet.FindAsync(id);

            if (context.Entry(entityToDelete).State == EntityState.Detached)
            {
                dbSet.Attach(entityToDelete);
            }
            return(dbSet.Remove(entityToDelete));
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <T> > AddRangeAsync(IEnumerable <T> entities)
        {
            _AspNetCoreWebApiContext.Entry(entities).State = EntityState.Added;
            await Entities.AddRangeAsync(entities);

            await _AspNetCoreWebApiContext.SaveChangesAsync();

            return(entities);
        }
Exemplo n.º 7
0
        public TEntity Update(TEntity entity, object key)
        {
            if (entity == null)
            {
                return(null);
            }
            TEntity exist = _entities.Find(key);

            if (exist != null)
            {
                _appDataContext.Entry(exist).CurrentValues.SetValues(entity);
                _appDataContext.SaveChanges();
            }
            return(exist);
        }
Exemplo n.º 8
0
 public void Atualizar(User user)
 {
     /* Pegar o estado do objeto  - automaticamente ele vai fazer as alterações
      * e persisti-las no banco */
     _context.Entry <User>(user).State = System.Data.Entity.EntityState.Modified;
     _context.SaveChanges();
 }
Exemplo n.º 9
0
        public async Task <IActionResult> PutBookItem([FromRoute] int id, [FromBody] BookItem bookItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(bookItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 10
0
 public void Update(User user)
 {
     _context
     .Entry <User>(user)
     .State = EntityState.Modified;
     _context.SaveChanges();
 }
Exemplo n.º 11
0
        public async Task <IHttpActionResult> PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 12
0
        public async Task <Person> UpdateAsync(Person entity)
        {
            _context.Entry(entity).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 13
0
        /// <inheritdoc />
        /// <exception cref="UserNotFoundException">Thrown when user is not found</exception>
        public async Task RemoveUserByIdAsync(string userId)
        {
            var userToRemove = await _userManager.FindByIdAsync(userId);

            if (userToRemove == null)
            {
                throw new UserNotFoundException();
            }
            await _db.Entry(userToRemove).Collection(u => u.Todos).LoadAsync();

            // Clear cached todos owned by the user
            foreach (var todo in userToRemove.Todos)
            {
                _cache.Remove(CacheConstants.GetSingleTodoCacheKey(
                                  todo.Id, userToRemove.Id));
                _cache.Remove(CacheConstants.GetAllTodosForDayCacheKey(
                                  userToRemove.Id, todo.Due.Date));
            }
            _cache.Remove(CacheConstants.GetAllTodosCacheKey(userToRemove.Id));
            _db.RemoveRange(userToRemove.Todos);

            await _userManager.DeleteAsync(userToRemove);

            await _db.SaveChangesAsync();

            // Clear user if cached and all user list.
            _cache.Remove(CacheConstants.GetSingleUserCacheKey(userToRemove.Id));
            _cache.Remove(CacheConstants.AllUsersCacheKey);
        }
Exemplo n.º 14
0
        public async Task RunCalculationForAllUsersAsync(DateTime calculationDate)
        {
            List <string> users =
                await _context.Users.Select(x => x.Id).ToListAsync();

            foreach (string userId in users)
            {
                DateTime now = calculationDate.Date;
                IEnumerable <SavingsDeposit> savingsDeposits = await _context.SavingsDeposits
                                                               .Where(x => x.Owner == userId && now >= x.StartDate && now <= x.EndDate.AddDays(1))
                                                               .ToListAsync();

                foreach (SavingsDeposit savingsDeposit in savingsDeposits)
                {
                    if (savingsDeposit.LastCalculation.Date < now)
                    {
                        DepositHistory depositHistory = PerformDepositCalculation(savingsDeposit);

                        depositHistory.CalculationDate = calculationDate;

                        savingsDeposit.LastCalculation = calculationDate;

                        savingsDeposit.CurrentProfitAfterTax = depositHistory.TotalProfitAfterTax;

                        _context.DepositsHistory.Add(depositHistory);
                    }

                    _context.Entry(savingsDeposit).State = EntityState.Modified;
                }

                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 15
0
 public bool Delete(Empresa empresa)
 {
     Context.Entry(empresa).State = System.Data.Entity.EntityState.Deleted;
     Context.Empresas.Remove(empresa);
     Context.SaveChanges();
     return(true);
 }
Exemplo n.º 16
0
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 17
0
        public async Task <Unit> Handle(UpdatePartiallyCommand request, CancellationToken cancellationToken)
        {
            var serie = await _context.Series.FindAsync(request.Id);

            if (serie == null)
            {
                throw new SerieNotFoundException(request.Id);
            }

            if (!string.IsNullOrEmpty(request.Title) && request.Title != serie.Title)
            {
                serie.Title = request.Title;
            }

            if (!string.IsNullOrEmpty(request.Description) && request.Description != serie.Description)
            {
                serie.Description = request.Description;
            }

            if (_context.Entry(serie).State != EntityState.Modified)
            {
                throw new Exception("Nothing updated.");
            }

            var success = await _context.SaveChangesAsync() > 0;

            if (success)
            {
                return(Unit.Value);
            }

            throw new Exception("Problem saving changes.");
        }
Exemplo n.º 18
0
 public void Update(Vaga model)
 {
     if (model != null)
     {
         _context.Entry <Vaga>(model).State = EntityState.Modified;
         _context.SaveChanges();
     }
 }
Exemplo n.º 19
0
        public virtual TEntity Atualizar(TEntity obj)
        {
            var entry = Db.Entry(obj);

            DbSet.Attach(obj);
            entry.State = EntityState.Modified;

            return(obj);
        }
Exemplo n.º 20
0
        public bool Update(Empresa empresa)
        {
            AppDataContext con = new AppDataContext();

            con.Entry(empresa).State = System.Data.Entity.EntityState.Modified;
            con.SaveChanges();
            Context = con;
            return(true);
        }
Exemplo n.º 21
0
 public ActionResult Edit([Bind(Include = "Id,Titulo")] Produto produto)
 {
     if (ModelState.IsValid)
     {
         db.Entry(produto).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(produto);
 }
Exemplo n.º 22
0
 public ActionResult Edit([Bind(Include = "Id,Nome")] Autor autor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(autor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(autor));
 }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "Id,Titulo")] Categoria categoria)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoria).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categoria));
 }
Exemplo n.º 24
0
 public ActionResult Edit([Bind(Include = "Id,Titulo,CategoriaId")] Livro livro)
 {
     if (ModelState.IsValid)
     {
         db.Entry(livro).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoriaId = new SelectList(db.Categorias, "Id", "Titulo", livro.CategoriaId);
     return(View(livro));
 }
Exemplo n.º 25
0
        public async Task UpdateSavingsDepositAsync(string userId, SavingsDeposit entity)
        {
            var result = await _context.SavingsDeposits.Where(x => x.Id == entity.Id).Select(x => x.Owner).FirstOrDefaultAsync();

            if (result == null)
            {
                throw new NotFoundException("Deposit not found for current user");
            }

            if (result == userId)
            {
                entity.Owner = userId;
                _context.Entry(entity).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            else
            {
                throw new NotAuthorizedException("User cannot edit this record");
            }
        }
Exemplo n.º 26
0
        public void SaveOrUpdate(Category entity)
        {
            if (entity.Id == 0)
            {
                _context.Categories.Add(entity);
            }
            else
            {
                _context.Entry <Category>(entity).State = EntityState.Modified;
            }

            _context.SaveChanges();
        }
Exemplo n.º 27
0
        public void SaveOrUpdate(Author entity)
        {
            if (entity.Id == 0)
            {
                _context.Authors.Add(entity);
            }
            else
            {
                _context.Entry <Author>(entity).State = EntityState.Modified;
            }

            _context.SaveChanges();
        }
Exemplo n.º 28
0
        public void SaveOrUpdate(Product entity)
        {
            if (entity.Id == 0)
            {
                _context.Products.Add(entity);
            }
            else
            {
                _context.Entry <Product>(entity).State = EntityState.Modified;
            }

            _context.SaveChanges();
        }
Exemplo n.º 29
0
        public void SaveOrUpdate(Book entity)
        {
            if (entity.Id == 0)
            {
                _context.Books.Add(entity);
            }
            else
            {
                _context.Entry <Book>(entity).State = EntityState.Modified;
            }

            _context.SaveChanges();
        }
        private Balance GetBalance(Player player)
        {
            var balance = _context.Balances.Where(x => x.Player.PlayerId == player.PlayerId).FirstOrDefault();

            if (balance != null)
            {
                _context.Entry(balance).State = EntityState.Modified;
            }
            else
            {
                balance = new Balance(player, 0);
                _context.Balances.Add(balance);
            }

            return(balance);
        }