Ejemplo n.º 1
0
        public override void Update(Evento obj)
        {
            var local = _context.Set <Evento>().Local.FirstOrDefault(entry => entry.Id == obj.Id);

            if (local != null)
            {
                _context.Entry(local).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
            }

            base.Update(obj);
        }
Ejemplo n.º 2
0
        public ActionResult DelCar(int id)
        {
            Car car = new Car {
                Id = id
            };

            _db.Entry(car).State = EntityState.Deleted;
            _db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 3
0
 public virtual void Update(TEntity obj)
 {
     try
     {
         _context.Entry(obj).State = EntityState.Modified;
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
        public void Remove(T obj)
        {
            sqlContext.BeginTransaction();
            var local = sqlContext.Set <T>().Local.FirstOrDefault(entry => entry.Id.Equals(obj.Id));

            if (local != null)
            {
                sqlContext.Entry(local).State = EntityState.Detached;
            }
            sqlContext.Set <T>().Remove(obj);
            sqlContext.SendChanges();
        }
Ejemplo n.º 5
0
 public void Remove(TEntity entity)
 {
     try
     {
         //DbSet.Remove(entity);
         sqlContext.Entry(entity).State = EntityState.Deleted;
         sqlContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 6
0
        public bool Update(T obj)
        {
            try
            {
                _context.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PutTripDataModel([FromRoute] int id, [FromBody] TripDataModel tripDataModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tripDataModel.TripId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 8
0
        public TEntity GetById(int id)
        {
            var entity = sqlContext.Set <TEntity>().Find(id);

            sqlContext.Entry(entity).State = EntityState.Detached;
            return(entity);
        }
        public async Task <IActionResult> PutWiki_topic([FromRoute] int id, [FromBody] Topic wiki_topic)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != wiki_topic.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> PutEmployee([FromRoute] long?id, [FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> PutInvoice(int id, Invoice invoice)
        {
            if (id != invoice.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 12
0
        public T Update(T item)
        {
            if (!Exists(item.Id))
            {
                return(null);
            }

            // Pega o estado atual do registro no banco
            // seta as alterações e salva
            var result = dataset.SingleOrDefault(b => b.Id == item.Id);

            if (result != null)
            {
                try
                {
                    _context.Entry(result).CurrentValues.SetValues(item);
                    _context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(result);
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> PutProfessor(int?id, Professor professor)
        {
            if (id != professor.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 14
0
 public async Task UpdateWinner(int id, Bet bet)
 {
     if (bet.id_bet == id)
     {
         _context.Entry(bet).State = EntityState.Modified;
         await _context.SaveChangesAsync();
     }
 }
Ejemplo n.º 15
0
        public void Update(int roleid, int adminid, int userid)
        {
            var user = context.tblUsers.Find(userid);

            user.RoleId               = roleid;
            user.IsActive             = 1;
            user.AdminId              = adminid;
            context.Entry(user).State = EntityState.Modified;
        }
Ejemplo n.º 16
0
        public void Update(T entity)
        {
            var updateEntity = (T)_objectSet.Find(entity.Id);

            if (updateEntity != null)
            {
                _context.Entry(updateEntity).CurrentValues.SetValues(entity);
            }
        }
Ejemplo n.º 17
0
        public virtual void Delete(params TEntity[] entities)
        {
            foreach (var entity in entities)
            {
                var dbEntityEntry = _dbContext.Entry(entity);

                var entry = dbEntityEntry;
                var dbSet = _dbContext.Set <TEntity>();

                if (entry.State == EntityState.Detached)
                {
                    dbSet.Attach(entity);
                }

                dbSet.Remove(entity);
            }

            _dbContext.SaveChanges();
        }
Ejemplo n.º 18
0
        public void Update(Product product)
        {
            Product _product = FindWithId(product.Id);

            if (_product != null)
            {
                context.Entry(_product).CurrentValues.SetValues(product);
            }
            // Does not work if we are using Lazy Load.
            // context.Entry(product).State = EntityState.Modified;
        }
Ejemplo n.º 19
0
        public void Update(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            var entry = context.Entry(entity);

            dbSet.Attach(entity);
            entry.State = EntityState.Modified;
        }
Ejemplo n.º 20
0
        public void Update(CategoryProduct category)
        {
            CategoryProduct _category = FindWithId(category.Id);

            if (_category != null)
            {
                context.Entry(_category).CurrentValues.SetValues(category);
            }
            // Does not work if we are using Lazy Load.
            // context.Entry(category).State = EntityState.Modified;
        }
Ejemplo n.º 21
0
        public void Update(Supplier supplier)
        {
            Supplier _supplier = FindWithId(supplier.Id);

            if (_supplier != null)
            {
                context.Entry(_supplier).CurrentValues.SetValues(supplier);
            }
            // Does not work if we are using Lazy Load.
            // context.Entry(supplier).State = EntityState.Modified;
        }
Ejemplo n.º 22
0
 public void Update(ItemVenda obj)
 {
     try
     {
         sqlContext.Entry(obj).State = EntityState.Modified;
         sqlContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Ejemplo n.º 23
0
 public void Update(TEntity obj)
 {
     try
     {
         sqlContext.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         sqlContext.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Atualizar generico
 /// </summary>
 /// <param name="obj">Obj generico para atualização</param>
 /// <returns>Task</returns>
 public async Task Atualizar(T obj)
 {
     try
     {
         _sqlContext.Entry(obj).State = EntityState.Modified;
         await _sqlContext.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Base Method for Updating an Item in the DB Context.
        /// </summary>
        /// <typeparam name="TEntity">Type Parameter</typeparam>
        /// <param name="entity">Entity to Update</param>
        /// <returns>Resulting Entity</returns>
        protected virtual TEntity Update <TEntity>(TEntity entity) where TEntity : class
        {
            var           entry     = ctx.Entry(entity);
            IKey          key       = entry.Metadata.FindPrimaryKey();
            List <object> keyValues = new List <object>();

            foreach (IProperty prop in key.Properties)
            {
                PropertyInfo pi = prop.PropertyInfo;
                keyValues.Add(pi.GetValue(entity));
            }

            var original = ctx.Find <TEntity>(keyValues.ToArray());

            if (!entity.Equals(original))
            {
                ctx.Entry(original).CurrentValues.SetValues(entity);
            }
            ctx.SaveChanges();
            return(ctx.Entry(entity).Entity);
        }
Ejemplo n.º 26
0
 public void Update(TEntity obj)
 {
     try
     {
         sqlContext.Entry(obj).State = EntityState.Modified;
         sqlContext.SaveChanges();
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
 void IRepositoryBase <TEntity> .Update(TEntity obj)
 {
     try
     {
         sqlContext.Entry(obj).State = EntityState.Modified;
         sqlContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 28
0
 public void Update(T obj)
 {
     try
     {
         sqlContext.Entry(obj).State = EntityState.Modified;
         sqlContext.SaveChanges();
     }
     catch (Exception exc)
     {
         throw exc;
     }
 }
Ejemplo n.º 29
0
 public void Update(Tentity obj)
 {
     try
     {
         _sqlContext.Entry(obj).State = EntityState.Modified;
         _sqlContext.SaveChanges();
     }
     catch (Exception err)
     {
         throw err;
     }
 }
        public BL CadastroTokenBl(BL bl)
        {
            var result = _context.Bls.SingleOrDefault(b =>b.BlNUmber == bl.BlNUmber);
            if (result != null)
            {
                try
                {
                    _context.Entry(result).CurrentValues.SetValues(bl);
                    _context.SaveChanges();
                }
                catch (Exception)
                {

                    throw;
                }
                return result;
            }
            else
            {
                return null;
            }
        }