private void AddClientBtn_Click(object sender, EventArgs e) { ClientEditForm form = new ClientEditForm(); var result = form.ShowDialog(); if (result == DialogResult.OK) { _clientsRepository.Insert(form.Client); FillGrids(); } }
public ResponseModel <int> Post([FromBody] ClientsModel dataToAdd) { var resp = new ResponseModel <int>(); try { if (dataToAdd == null) { throw new Exception("Data is null"); } var model = new Clients() { Name = dataToAdd.Name, IsActive = dataToAdd.IsActive, Creation = DateTime.Now, Updated = DateTime.Now, IdGroup = dataToAdd.IdGroup }; IClientsRepository appRepo = new ClientsRepository(new DataBaseContext()); if (appRepo.ExistByName(model.IdGroup, model.Name)) { throw new Exception("Client already exist"); } if (appRepo.Insert(model)) { resp.Data = model.Id; resp.Status = 200; resp.Description = "OK"; } else { throw new Exception("Not inserted"); } } catch (Exception ex) { resp.Status = 500; resp.Description = $"Error: {ex.Message}"; resp.Data = 0; } return(resp); }