Exemplo n.º 1
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 2
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            // with entity framework this is not required, but is a good practice,
            // because, maybe another implementation of the ICommanderRepo needs it
            _repository.UpdateCommand(commandModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
Exemplo n.º 3
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);
            if(commandModelFromRepo == null)
            {
                return NotFound();
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);    //!!!Different syntax, because both of these classes has data (existing model)

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return NoContent();
        }
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo); //another form of mapping

            _repository.UpdateCommand(commandModelFromRepo);     //just kept in case you swap out the repo implementation in future
            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 5
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());  //returns 404 Not Found if command id does not exist
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges(); //this makes sure that the command created gets saved in our database

            return(NoContent());       //returns 204 response
        }
Exemplo n.º 6
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo); //doesn't do anything but if implementation changes it is already here
            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 7
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandFromRepo = _commanderRepo.GetCommandById(id);

            if (commandFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandFromRepo);// this syntax because both has data present, previously only source data was available
            //this already upadated our model so no needed implementation in SqlCommanderRepo
            _commanderRepo.UpdateCommand(commandFromRepo);

            _commanderRepo.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 8
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            //Updatedto'dan command'e çevirecek syntax farklı commandModelFromRepo güncellenecek source'a göre
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 9
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo); //REDUNDANT, empty method - to keep in compliance with REST standard

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 10
0
        public ActionResult UpdateCommand(int Id, CommandUpdateDto ObjCmdcreateDto)
        {
            var objUpdatecommandById = _repository.GetCommandById(Id);

            if (objUpdatecommandById == null)
            {
                return(NotFound());
            }

            _mapper.Map(ObjCmdcreateDto, objUpdatecommandById);

            _repository.UpdateCommand(objUpdatecommandById);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 11
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto cmd)
        {
            Command cmdModelFromRepo = _repository.GetCommandById(id);

            if (cmdModelFromRepo == null)
            {
                return(NotFound());
            }
            // Updates original object, which syncs with DB
            _mapper.Map(cmd, cmdModelFromRepo);
            // This should do nothing in most implementations, but might be used by users
            _repository.UpdateCommand(cmdModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 12
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);             // cherche l'objet dans la bdd

            if (commandModelFromRepo == null)
            {
                return(NotFound());                // si il n'existe pas on quitte et envoie 404
            }
            // met commandUpdateDto dans commandModelFromRepo
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo); // update l'objet

            _repository.SaveChanges();                       // sauvegarde l'état de l'objet dans la bdd

            return(NoContent());
        }
Exemplo n.º 13
0
        public ActionResult UpdateCommad(int id, CommandUpdateDto commandUpdateDto)
        {
            var command = _repository.GetCommandById(id);

            if (command == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, command);

            //_repository.UpdateCommand(command); // Useless in this case

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 14
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _Repository.GetCommandById(id);

            if (commandModelFromRepo is null)
            {
                return(NotFound($"No command found with id {id}"));
            }

            _Mapper.Map(commandUpdateDto, commandModelFromRepo);

            _Repository.UpdateCommand(commandModelFromRepo);

            _Repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 15
0
        public ActionResult UpdateCommand(int Id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(Id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            //map from updateDto to model // mapping is just exist but we don't do any thing with it right now
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 16
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo is null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);    // <- useless, but here in case you change your implementation and
                                                                // it needs it, its there.
            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 17
0
        public async Task <ActionResult> UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = await Task.Run(() => _commandAPIRepo.GetCommandById(id));

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            // Mapper will mutate commandModelFromRepo in db context
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            // After muttation, we need to save changes to db
            await Task.Run(() => _commandAPIRepo.SaveChanges());

            return(NoContent());
        }
        public ActionResult <CommandUpdateDto> UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            //It automatically updates the model with the commandUpdateDto
            _mapper.Map(commandUpdateDto, commandModelFromRepo);
            //In our case with sql we don't need to do anything here but either way we call it
            //in case we change the database the update will work the same way
            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 19
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            // check that the resource to be updated exist
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.saveChanges();

            return(NoContent());
        }
Exemplo n.º 20
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            Command commandModelFromRepo = _repo.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            // Ookal doet deze methode niets in ONZE implementatie; stel je hebt een andere repo met wél een implementatie. Dan staat deze hier al.
            // Die zal door het gebruik van de ICommanderRepo deze ook moeten implementeren, dus staat deze hier al.
            _repo.UpdateCommand(commandModelFromRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 21
0
        public async Task <ActionResult> UpdateCommand(int id, CommandUpdateDto commandToUpdate)
        {
            var cmdModelFromRepo = await _commandsRepo.GetCommandByIdAsync(id);

            if (cmdModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandToUpdate, cmdModelFromRepo);

            //_apiRepo.UpdateCommand(cmdModelFromRepo);

            await _commandsRepo.SaveCommandsChanges();

            // Return updated Resource
            return(Ok(_mapper.Map <CommandReadDto>(cmdModelFromRepo)));
        }
Exemplo n.º 22
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto updateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var commandFromRepo = _repository.GetCommandById(id);

            if (commandFromRepo == null)
            {
                return(NotFound());
            }
            var commandModel = _mapper.Map(updateDto, commandFromRepo);

            _repository.UpdateCommand(commandFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
        public ActionResult <Command> UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var command = _respository.GetCommandById(id);

            if (command == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, command);
            _respository.UpdateCommand(command);

            _respository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDto>(command);

            return(CreatedAtRoute(nameof(GetCommand), new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            // does nothing here but left out incase of future i change to EF framework that requires it
            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
        public ActionResult <CommandReadDto> UpdateCommand(int id, CommandUpdateDto cmd)
        {
            var commandModelFromRepo = _repoistory.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(cmd, commandModelFromRepo);
            _repoistory.UpdateCommand(commandModelFromRepo);

            var commandRead = _mapper.Map <CommandReadDto>(commandModelFromRepo);

            return(Ok(
                       commandRead
                       ));
        }
Exemplo n.º 26
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            //Busca no Command o ID correspondente
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);    //Merge current|previous

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 27
0
        public ActionResult UpdateCommand(int id, [FromForm] CommandUpdateDto commandUpdateDto)
        {
            var commandFromRepo = _repository.GetCommandById(id);

            //validations
            if (commandFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandFromRepo);

            _repository.UpdateCommand(commandFromRepo);//Good practice

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 28
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);
            //EF doesn't actually require this, this is a good practice

            _repository.SaveChanges();

            return(NoContent());
        }
Exemplo n.º 29
0
        public ActionResult <CommandReadDto> EditCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            if (commandUpdateDto.Id != id)
            {
                return(NotFound());
            }

            var command = _mapper.Map <Command>(commandUpdateDto);

            _repo.UpdateCommand(command);

            if (_repo.saveChanges())
            {
                //var commandReadDto = _mapper.Map<CommandReadDto>(command);
                return(NoContent());
            }
            return(BadRequest());
        }
Exemplo n.º 30
0
        public ActionResult <CommandReadDto> Update(int id, CommandUpdateDto dto)
        {
            if (id == null || dto == null)
            {
                throw new ArgumentNullException();
            }

            var commandResult = _repository.GetCommandById(id);

            if (commandResult == null)
            {
                return(NotFound());
            }

            _mapper.Map(dto, commandResult);
            _repository.Update(commandResult);
            _repository.SaveChanges();
            return(NoContent());
        }