public IHttpActionResult PutCluster(int id, [FromBody] ClusterDTO cluster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Cluster entity = UnitOfWork.ClusterRepository.GetByID(id); if (entity == null) { return(NotFound()); } else if (entity.ApplicationUsers.FirstOrDefault(x => x.Id == UserRecord.Id) == null) { return(Unauthorized()); } entity.Name = cluster.Name; entity.Description = cluster.Description; UnitOfWork.ClusterRepository.Update(entity); try { UnitOfWork.Save(); } catch (DbUpdateConcurrencyException e) { return(InternalServerError(new Exception(string.Format("Failed to update cluster {0}", entity.Id), e))); } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Get(int id) { var cluster = clusterRepository.GetClusterById(id); if (cluster == null) { return(NotFound()); } var clusterDTO = new ClusterDTO(cluster); return(Ok(clusterDTO)); }
public IActionResult Update([FromServices] ClusterService service, [FromBody] ClusterDTO ClusterDto, int id) { var ClusterRepo = service.GetById(predicate: x => x.IdCluster == id); var mapped = Mapper.Map(ClusterDto, ClusterRepo); var result = service.Update <ClusterValidator>(mapped); //Retornos vazios são NotFound if (result == null) { return(NotFound()); } return(Ok(result)); }
public IHttpActionResult PostCluster([FromBody] ClusterDTO cluster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = new Cluster() { Name = cluster.Name, Description = cluster.Description, ApplicationUsers = new List <ApplicationUser>() { UserRecord } }; UnitOfWork.ClusterRepository.Insert(entity); UnitOfWork.Save(); return(CreatedAtRoute("GetCluster", new { id = entity.Id }, Mapper.Map <GetClusterDTO>(entity))); }
public async Task <IActionResult> CreateAsync([FromServices] ClusterService service, [FromBody] ClusterDTO ClusterDto) { try { var retornoNetwork = await service.CreateNetwork(ClusterDto.NomeCluster); var retornoSubnet = await service.CreateSubnet(retornoNetwork.Id, ClusterDto.NomeCluster); var retornoRouter = await service.CreateRouter(ClusterDto.NomeCluster); var retornoInterface = await service.AddRouterInterface(retornoSubnet.Id, retornoRouter.Id); var retorno = await service.CreateServer(ClusterDto.NomeCluster, ClusterDto.IdImage, ClusterDto.IdFlavor, retornoNetwork.Id); ClusterDto.IdServer = retorno.Id; ClusterDto.IdNetwork = retornoNetwork.Id; var interfacePort = await service.GetAllServerInterfaces(retorno.Id); var floatingIp = await service.AssociateFloatingIp("78c9ed54-cca8-4f1b-837d-b15c185cce17", interfacePort[0].PortId); ClusterDto.FloatingIP = floatingIp.FloatingIpAddress; ClusterDto.DataCriacao = DateTime.Now; } catch { return(null); } var mapped = Mapper.Map <Cluster>(ClusterDto); var result = service.Add <ClusterValidator>(mapped); return(new ObjectResult(result)); }