Ejemplo n.º 1
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

                throw;
            }

            return(NoContent());
        }
        public async Task <ActionResult <SavedSystemDto> > UpdateSystem(int id, UpdateSystemDto systemDto)
        {
            if (!(SystemExists(id) && systemDto.Id.Equals(id)))
            {
                return(BadRequest("system with this id does not exist"));
            }

            _context.Entry(_mapper.Map <Domain.ConfigModels.SystemModels.System>(systemDto)).State = EntityState.Modified;

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

                throw;
            }

            return(await _context.Systems.Where(x => x.Id.Equals(id)).Select(x => _mapper.Map <SavedSystemDto>(x)).FirstAsync());
        }
        public async Task <ActionResult <SavedMicroServiceDto> > PutMicroservice(int id, UpdatedMicroserviceDto microserviceDto)
        {
            if (!(MicroserviceExists(id) && (id == microserviceDto.Id)))
            {
                return(BadRequest("microservice with this id does not exist"));
            }

            _context.Entry(_mapper.Map <Microservice>(microserviceDto)).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(_mapper.Map <SavedMicroServiceDto>(
                       await _context.MicroServices
                       .Include(y => y.System)
                       .FirstAsync(c => c.Id.Equals(id))));
        }
Ejemplo n.º 4
0
        public bool EditExistingCountry(Country Country)
        {
            try
            {
                ConfigurationContext.Entry(Country).State = EntityState.Modified;
                ConfigurationContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogException(ex);
                return(false);
            }
        }
Ejemplo n.º 5
0
 public void Update(T t)
 {
     _context.Set <T>().Update(t);
     _context.Entry(t).Property(x => x.CreationDate).IsModified = false;
     _context.SaveChanges();
 }