public async Task <IActionResult> Edit([FromBody] ClientViewmodel model, int id) { try { var company = await context.Companies.FindAsync(model.CompanyId); if (company == null) { return(NotFound(new { message = $"Company with ID {model.CompanyId} was not found." })); } var client = await context.Clients.FindAsync(id); if (client == null) { return(NotFound(new { message = $"Client with ID {id} was not found." })); } client.Address = model.Address; client.Company = company; client.Email = model.Email; client.IdNumber = model.IdNumber; client.Name = model.Name; client.PhoneNumber = model.PhoneNumber; await context.SaveChangesAsync(); return(Ok(client)); } catch (Exception ex) { _logger.LogError($"Unable to update client", ex); return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> Create(ClientViewmodel model) { try { var company = await context.Companies.FindAsync(model.CompanyId); if (company == null) { return(NotFound(new { message = $"Company with ID {model.CompanyId} was not found." })); } var client = new Client { Address = model.Address, Company = company, Email = model.Email, Id = model.Id, IdNumber = model.IdNumber, Name = model.Name, PhoneNumber = model.PhoneNumber }; await context.Clients.AddAsync(client); await context.SaveChangesAsync(); return(Ok(client)); } catch (Exception ex) { _logger.LogError($"Unable to create client", ex); return(BadRequest(ex.ToString())); } }
public async Task <IActionResult> Get(int id) { try { var client = await context.Clients.Include(x => x.Company).FirstOrDefaultAsync(x => x.Id == id); if (client == null) { return(NotFound(new { message = $"Client with ID {id} was not found." })); } var model = new ClientViewmodel { Address = client.Address, Company = new CompanyViewmodel { Address = client.Company.Address, Id = client.Company.Id, Name = client.Company.Name }, CompanyId = client.Company.Id, Email = client.Email, Id = client.Id, IdNumber = client.IdNumber, Name = client.Name, PhoneNumber = client.PhoneNumber }; return(Ok(model)); } catch (Exception ex) { _logger.LogError($"Unable to get client", ex); return(BadRequest(ex.ToString())); } }
public async Task OnGetAsync(int?id) { try { if (id != null) { _ = int.TryParse(id.ToString(), out int clientId); Client = await GetClientAsync(clientId); } } catch (Exception ex) { _logger.LogError(ex, "[Clients DeleteModel] OnGet failed"); } }
private async Task <ClientViewmodel> GetClientAsync(int?id) { var client = await context.Clients.Include(x => x.Company).FirstOrDefaultAsync(x => x.Id == id); var model = new ClientViewmodel { Address = client.Address, Company = new CompanyViewmodel { Address = client.Company.Address, Id = client.Company.Id, Name = client.Company.Name }, CompanyId = client.Company.Id, Email = client.Email, Id = client.Id, IdNumber = client.IdNumber, Name = client.Name, PhoneNumber = client.PhoneNumber }; return(model); }
public void Initialize() { #region plist //init plist ParameterList = new List <List <DataGridStringItem> >(); Parameter0List = new List <DataGridStringItem>() { new DataGridStringItem() { Value = "aio_numeric_s2e_nopath_onlytimeloss.py" }, new DataGridStringItem() { Value = "aio_numeric_s2e_noplanned_nopath_onlytimeloss.py" }, new DataGridStringItem() { Value = "aio_numeric_s2e_noplanned_onlytimeloss.py" }, new DataGridStringItem() { Value = "aio_numeric_s2e_onlytimeloss.py" }, new DataGridStringItem() { Value = "aio_numeric_s2e_rgb_noplanned_onlytimeloss.py" }, new DataGridStringItem() { Value = "aio_numeric_s2e_rgb_onlytimeloss.py" } }; ParameterList.Add(Parameter0List); Parameter1List = new List <DataGridStringItem>(); for (int i = 1; i <= 30; i++) { Parameter1List.Add(new DataGridStringItem() { Value = i.ToString() }); } ParameterList.Add(Parameter1List); Parameter2List = new List <DataGridStringItem>() { new DataGridStringItem() { Value = "100" } }; ParameterList.Add(Parameter2List); Parameter3List = new List <DataGridStringItem>() { new DataGridStringItem() { Value = "0.1" } }; ParameterList.Add(Parameter3List); Parameter4List = new List <DataGridStringItem>() { new DataGridStringItem() { Value = "20" } }; ParameterList.Add(Parameter4List); Parameter5List = new List <DataGridStringItem>() { new DataGridStringItem() { Value = "1" } }; ParameterList.Add(Parameter5List); #endregion //ui TODO fix error when multithreaded this.GenerateWorkCommand = new RelayCommand <object>(GenerateWork, false); //int dispatcher = Dispatcher.CurrentDispatcher; ClientList = new ObservableCollection <ClientViewmodel>(); _core = new Core(); _core.PropertyChanged += (sender, args) => NotifyPropertyChanged(args.PropertyName); _core.NewClientEvent += pClient => { //do nothing }; _core.ClientDisconnectedEvent += pClient => { dispatcher.Invoke(() => { this.ClientList.Remove(this.ClientList.First(t => t.ID == pClient.ID)); NotifyPropertyChanged(nameof(ConnectedClientsString)); }); }; _core.ClientUpdatedEvent += delegate(Client pClient) { dispatcher.Invoke(() => { var client = this.ClientList.FirstOrDefault(t => t.ID == pClient.ID); if (client == null) { client = new ClientViewmodel(pClient) { ID = pClient.ID }; this.ClientList.Add(client); NotifyPropertyChanged(nameof(ConnectedClientsString)); } client.UpdateValues(pClient); }); }; _core.NewLogMessageEvent += delegate(string message) { dispatcher.Invoke(() => { if (message != null) { //max log limit 1000 if (LogMessages.Count > 1000) { LogMessages.Dequeue(); } LogMessages.Enqueue($"[{DateTime.UtcNow:G}] {message}"); NotifyPropertyChanged(nameof(Log)); } }); }; _core.NewConsoleLogMessage += delegate(Client pClient, string message) { dispatcher.Invoke(() => { var client = this.ClientList.FirstOrDefault(t => t.ID == pClient.ID); if (client != null && !String.IsNullOrWhiteSpace(message)) { client.LogMessages.Add($"[{DateTime.UtcNow:G}] {message}"); } }); }; _core.Initialize(); QueuedWorkItems.CollectionChanged += (sender, args) => NotifyPropertyChanged(nameof(QueuedOperationsCount)); ActiveWorkItems.CollectionChanged += (sender, args) => NotifyPropertyChanged(nameof(ActiveOperationsCount)); NotifyPropertyChanged(String.Empty); }