public async Task <ActionResult <BackResponse> > UpdateVm(Vm vm) { var backResponse = new BackResponse(); if (!ModelState.IsValid) { backResponse.Status = "Model state no valid"; return(BadRequest(backResponse)); } if (vm?.Adapter == null) { backResponse.Status = "Vm adapter is null"; return(BadRequest(backResponse)); } Adapter adapter = await _context.Adapters.Where(x => x.IsOK) .Include(c => c.Credentials) .Include(p => p.Provider) .Where(a => a.Id == vm.Adapter.Id) .SingleOrDefaultAsync(); ServicesResponse servicesResponse; switch (adapter.Provider.Name.ToLower()) { case "ovirt": servicesResponse = await VmService.UpdateVm(adapter, vm); if (!servicesResponse.isSuccess) { backResponse.IsSuccess = false; backResponse.Status = servicesResponse.errorMessage; backResponse.StatusCode = servicesResponse.errorCode; } else { backResponse.IsSuccess = true; } break; } return(Ok(backResponse)); }
public async Task <IActionResult> ProlongVm(Vm vm) { if (!ModelState.IsValid) { return(BadRequest("Model state no valid")); } if (vm?.Adapter == null) { return(BadRequest("Vm adapter is null")); } Audit audit = await _context.Audits.Where(x => x.ClusterId == vm.Cluster.Id).SingleOrDefaultAsync(); if (audit == null) { return(BadRequest("Настройки аудита для кластера не найдены.")); } vm.AuditDate = DateTime.Now.ToShortDateString(); vm.Deadline = DateTime.Now.AddDays(audit.AuditDays).ToShortDateString(); Adapter adapter = await _context.Adapters.Where(x => x.IsOK) .Include(c => c.Credentials) .Include(p => p.Provider) .Where(a => a.Id == vm.Adapter.Id) .SingleOrDefaultAsync(); ServicesResponse servicesResponse; switch (adapter.Provider.Name.ToLower()) { case "ovirt": servicesResponse = await VmService.UpdateVm(adapter, vm); if (!servicesResponse.isSuccess) { return(StatusCode(servicesResponse.errorCode, servicesResponse.errorMessage)); } return(Ok(vm)); } return(BadRequest()); }