public void Update(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     _context.Entry(entity).State = EntityState.Modified;
 }
Beispiel #2
0
        public async Task <bool> UpdateAvatar(string id, string name)
        {
            var result = await _context.ClientProfiles.FirstOrDefaultAsync(p => p.Id == id);

            if (result == null)
            {
                return(false);
            }
            result.AvatarImage           = name;
            _context.Entry(result).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(true);
        }
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         //dbContext.AppRoles.Attach(user.AppRole);
         if (user.Id == 0)
         {
             dbContext.Users.Add(user);
         }
         else
         {
             //var userInDb = dbContext.Users.Include(u => u.AppRole)
             //    .SingleOrDefault(u => u.Id == user.Id);
             var  userInDb           = dbContext.Users.Find(user.Id);
             bool wasChangedUserInDb = userInDb != user;
             if (wasChangedUserInDb)
             {
                 AdminLogger.PostLogToDb(dbContext, userInDb, AdminLogger.CheckAction(userInDb, user));
             }
             if (userInDb != null)
             {
                 dbContext.Entry(userInDb).CurrentValues.SetValues(user);
                 //userInDb.AppRole.Permissions = user.AppRole.Permissions;
             }
         }
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
        public IHttpActionResult PutSubCategoria(int id, SubCategoria subCategoria)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        protected async override Task Handle(UpdateUnitRequest request, CancellationToken cancellationToken)
        {
            var entity = await appContext.Units.FindAsync(request.dto.Id);

            if (entity == null)
            {
                return;
            }
            appContext.Entry(entity).CurrentValues.SetValues(new Entities.Models.Unit(request.dto.Id, request.dto.Name));
            await appContext.SaveChangesAsync();
        }
Beispiel #6
0
        protected async override Task Handle(UpdateCustomerRequest request, CancellationToken cancellationToken)
        {
            var entity = await appContext.Customers.FindAsync(request.dto.Id);

            if (entity == null)
            {
                return;
            }
            var Customer = mapper.Map <Customer>(request.dto);

            appContext.Entry(entity).CurrentValues.SetValues(Customer);
            await appContext.SaveChangesAsync();
        }
        protected async override Task Handle(UpdateProductRequest request, CancellationToken cancellationToken)
        {
            var entity = await appContext.Products.FindAsync(request.dto.Id);

            if (entity == null)
            {
                return;
            }
            var product = mapper.Map <Product>(request.dto);

            appContext.Entry(entity).CurrentValues.SetValues(product);
            await appContext.SaveChangesAsync();
        }
Beispiel #8
0
        public Team Update(Team changedTeam)
        {
            try
            {
                _context.Teams.Attach(changedTeam);
                _context.Entry(changedTeam).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
            }catch (Exception ex)
            {
                throw ex;
            }

            return(changedTeam);
        }
Beispiel #9
0
        public async Task <bool> DeleteImage(string imageName)
        {
            var test = _context.Images.FirstOrDefault(x => x.ImageName == imageName);

            if (test == null)
            {
                return(false);
            }
            _context.Entry(test).State = EntityState.Deleted;
            var task = _context.Images.Remove(test);
            await _context.SaveChangesAsync();

            return(task != null);
        }
        protected async override Task Handle(UpdatePlaceRequest request, CancellationToken cancellationToken)
        {
            using var scope = new TransactionScope();
            var entity = await appContext.Places.FindAsync(request.Id);

            if (entity == null)
            {
                return;
            }
            var place = request.Adapt <Place>();

            appContext.Entry(entity).CurrentValues.SetValues(place);
            await appContext.SaveChangesAsync();

            scope.Complete();
        }
Beispiel #11
0
 public Article Update(Article article)
 {
     try
     {
         //var unUpdate = context.Articles.FirstOrDefault(c => c.Author == upd.Author);
         _context.Articles.Attach(article);
         _context.Entry(article).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         Console.Write(ex);
         throw(ex);
     }
     return(article);
 }
Beispiel #12
0
        public async Task <TOutput> Update(TOutput request)
        {
            var mappedRequest = Mapper.Map <TEntity>(request);

            var found = await DbContext.Set <TEntity>()
                        .FirstOrDefaultAsync(x => x.Id == mappedRequest.Id);

            if (found == null)
            {
                return(Mapper.Map <TOutput>(mappedRequest));
            }

            DbContext.Entry(found).CurrentValues.SetValues(mappedRequest);
            await DbContext.SaveChangesAsync();

            return(Mapper.Map <TOutput>(mappedRequest));
        }
 public CompetitionType Update(CompetitionType competitionType)
 {
     try
     {
         if (competitionType != null)
         {
             _context.CompetitionTypes.Attach(competitionType);
             _context.Entry(competitionType).State = System.Data.Entity.EntityState.Modified;
             _context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex);
         throw ex;
     }
     return(competitionType);
 }
Beispiel #14
0
        public Match Update(Match match)
        {
            try
            {
                if (match != null)
                {
                    _context.Matches.Attach(match);
                    _context.Entry(match).State = EntityState.Modified;
                    _context.SaveChanges();
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            return(match);
        }
Beispiel #15
0
        public IHttpActionResult PutCampo(int id, Campo campo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var listaDeOpcoesAnteriores = ListaDeOpcoesAnteriores(id);

            ConfigurarNovaListaDeOpcoesParaCampo(campo);
            db.Entry(campo).State = EntityState.Modified;
            RemoverListaAnteriorDeOpcoesDoCampo(listaDeOpcoesAnteriores);

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public async Task UpdateAsync(long id, TEntity entity)
 {
     _appContext.Entry(entity).State = EntityState.Modified;
     await _appContext.SaveChangesAsync();
 }