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)); }
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)); }
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)); }