Ejemplo n.º 1
0
        public async Task <ActionResponse> UpdateAsync(Dictionary <string, object> model)
        {
            var id      = Guid.Parse(model["id"].ToString());
            var captain = await _grpcService.GetByIdAsync(id);

            if (model.TryGetValue("status", out var status))
            {
                var captainNewStatus = (CaptainStatus)int.Parse(status.ToString());
                if (captainNewStatus == CaptainStatus.HasTeam || captainNewStatus == CaptainStatus.Unassigned)
                {
                    return(ActionResponse.InvalidStatus(
                               $"{CaptainStatus.Deleted.ToString()}, {CaptainStatus.Unknown.ToString()}," +
                               $" {CaptainStatus.Retired.ToString()}"));
                }

                if (captainNewStatus == CaptainStatus.Deleted && captain.Status != CaptainStatus.Unassigned)
                {
                    return(ActionResponse.CantDelete(nameof(Captain)));
                }
            }

            if (captain.Id != id)
            {
                return(ActionResponse.NotFound("Captain"));
            }

            UpdateObjectByReflection.SetProperties(model, captain);

            return(await _grpcService.UpdateAsync(captain));
        }
Ejemplo n.º 2
0
        public async Task <ActionResponse> UpdateAsync(Dictionary <string, object> model)
        {
            var id    = Guid.Parse(model["id"].ToString());
            var robot = await _grpcService.GetByIdAsync(id);

            if (model.TryGetValue("status", out var status))
            {
                var robotNewStatus = (RobotStatus)int.Parse(status.ToString());
                if (robotNewStatus == RobotStatus.Assigned || robotNewStatus == RobotStatus.Unassigned)
                {
                    return(ActionResponse.InvalidStatus($"{RobotStatus.On.ToString()}, {RobotStatus.Off.ToString()}," +
                                                        $" {RobotStatus.Exploring.ToString()}, {RobotStatus.Deleted.ToString()}" +
                                                        $", {RobotStatus.Broken.ToString()}"));
                }
                if (robotNewStatus == RobotStatus.Deleted && robot.Status != RobotStatus.Unassigned)
                {
                    return(ActionResponse.CantDelete(nameof(Robot)));
                }
            }

            if (robot.Id != id)
            {
                return(ActionResponse.NotFound("Robot"));
            }

            UpdateObjectByReflection.SetProperties(model, robot);
            return(await _grpcService.UpdateAsync(robot));
        }
Ejemplo n.º 3
0
        public async Task <ActionResponse> UpdateAsync(Dictionary <string, object> model)
        {
            var id      = Guid.Parse(model["id"].ToString());
            var shuttle = await _grpcService.GetByIdAsync(id);

            if (model.TryGetValue("status", out var status))
            {
                var shuttleNewStatus = (ShuttleStatus)int.Parse(status.ToString());
                if (shuttleNewStatus == ShuttleStatus.Assigned || shuttleNewStatus == ShuttleStatus.Unassigned)
                {
                    return(ActionResponse.InvalidStatus($"{ShuttleStatus.Deleted.ToString()}, {ShuttleStatus.Broken.ToString()}," +
                                                        $" {ShuttleStatus.Off.ToString()}, {ShuttleStatus.On.ToString()}"));
                }

                if (shuttleNewStatus == ShuttleStatus.Deleted && shuttle.Status != ShuttleStatus.Unassigned)
                {
                    return(ActionResponse.CantDelete(nameof(Shuttle)));
                }
            }

            if (shuttle.Id != id)
            {
                return(ActionResponse.NotFound("Shuttle"));
            }

            UpdateObjectByReflection.SetProperties(model, shuttle);
            return(await _grpcService.UpdateAsync(shuttle));
        }
Ejemplo n.º 4
0
        public async Task <ActionResponse> UpdateAsync(Dictionary <string, object> model)
        {
            if (model.TryGetValue("status", out var status))
            {
                var teamNewStatus = int.Parse(status.ToString());
                if (!(teamNewStatus == (int)TeamStatus.Deleted || teamNewStatus == (int)TeamStatus.Lost))
                {
                    return(ActionResponse.InvalidStatus($"{TeamStatus.Deleted.ToString()}, {TeamStatus.Lost.ToString()}"));
                }
            }
            var id   = Guid.Parse(model["id"].ToString());
            var team = await _grpcService.GetByIdAsync(id);

            if (team.Id != id)
            {
                return(ActionResponse.NotFound("Team"));
            }

            UpdateObjectByReflection.SetProperties(model, team);
            return(await _grpcService.UpdateAsync(team));
        }
Ejemplo n.º 5
0
        public async Task <ActionResponse> UpdateAsync(Dictionary <string, object> model)
        {
            if (model.TryGetValue("status", out var status))
            {
                var planetNewStatus = int.Parse(status.ToString());
                if (!(planetNewStatus == (int)PlanetStatus.EnRoute ||
                      planetNewStatus == (int)PlanetStatus.NotExplored))
                {
                    return(ActionResponse.InvalidStatus(
                               $"{PlanetStatus.EnRoute.ToString()}, {PlanetStatus.NotExplored.ToString()},"));
                }
            }
            var id     = Guid.Parse(model["id"].ToString());
            var planet = await _grpcService.GetByIdAsync(id);

            if (planet.Id != id)
            {
                return(ActionResponse.NotFound("Planet"));
            }

            UpdateObjectByReflection.SetProperties(model, planet);
            return(await _grpcService.UpdateAsync(planet));
        }