Beispiel #1
0
        public async Task SetRouteForPlanet(UpdatePlanetViewModel planetModel)
        {
            var planet = await _planetRepository.GetById(planetModel.Id);

            planet.Description = planetModel.Description;
            planet.Status      = planetModel.PlanetStatus;
            await _planetRepository.Update(planetModel.Id, planet);
        }
Beispiel #2
0
        public IActionResult UpdatePlanet(int id, [FromBody] UpdatePlanetViewModel planetViewModel)
        {
            try
            {
                Planet planetToUpdate = appDbContext.Planets.Where(p => p.Id == id)
                                        .Include(p => p.ExplorersTeam)
                                        .ThenInclude(p => p.Captain)
                                        .Include(p => p.ExplorersTeam)
                                        .ThenInclude(p => p.Robots)
                                        .FirstOrDefault();

                Status        status        = appDbContext.Statuses.Where(s => s.Id == planetViewModel.StatusId).FirstOrDefault();
                ExplorersTeam explorersTeam = null;

                IfCaptainHasChangedSetLastCaptainAvaialable(planetViewModel.CaptainId, planetViewModel.LastCaptainId);
                SetRobotsAvailable(planetViewModel.RobotsToSetAvailable);

                Captain captain = appDbContext.Captains.Where(c => c.Id == planetViewModel.CaptainId.ToString()).FirstOrDefault();
                if (captain != null)
                {
                    captain.IsAvailable          = false;
                    explorersTeam                = UpdateExplorersTeam(planetViewModel.Robots, captain);
                    planetToUpdate.ExplorersTeam = explorersTeam;
                }
                else
                {
                    planetToUpdate.ExplorersTeam.Captain = null;
                    planetToUpdate.ExplorersTeam.Robots  = null;
                }

                planetToUpdate.Name        = planetViewModel.Name;
                planetToUpdate.ImageUrl    = planetViewModel.ImageUrl;
                planetToUpdate.Description = planetViewModel.Description;
                planetToUpdate.Status      = status;

                appDbContext.SaveChanges();

                return(new OkObjectResult("Planet succesfully added."));
            }
            catch (Exception exc)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            };
        }
        public async Task <IActionResult> Update([FromBody] UpdatePlanetViewModel viewModel)
        {
            await _planetService.UpdatePlanetAfterVisit(viewModel);

            return(Ok());
        }