public async Task <IActionResult> PutPenaltiesAccounting(int id, PenaltiesAccounting penaltiesAccounting) { if (id != penaltiesAccounting.PenaltiesAccountingID) { return(BadRequest()); } _context.Entry(penaltiesAccounting).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PenaltiesAccountingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private async Task PostPenalty() { if (!string.IsNullOrWhiteSpace(AccountsDrop.Text) && !string.IsNullOrWhiteSpace(TypeDrop.Text) && !string.IsNullOrWhiteSpace(SumField.Text)) { PenaltiesAccounting penaltiesAccounting = new PenaltiesAccounting { AccountID = (int)AccountsDrop.SelectedValue, Date = DateTime.Now, PenaltyID = (int)TypeDrop.SelectedValue, Sum = Convert.ToDouble(SumField.Text) }; try { await _penaltiesAccountingProxy.AddPenaltiesAccounting(penaltiesAccounting); } catch (HttpException ex) { MessageBox.Show($"Ошибка:{ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ex; } } else { MessageBox.Show("Заполните данные о штрафе", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async Task <PenaltiesAccounting> AddPenaltiesAccounting(PenaltiesAccounting penaltiesAccounting) { var jsonString = JsonConvert.SerializeObject(penaltiesAccounting); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("/api/PenaltiesAccountings", content); var code = response.StatusCode; var result = responseReader.ReadObjectAsync <PenaltiesAccounting>(response); if (code == (HttpStatusCode)200) { return(await result); } return(null); }
public async Task <HttpStatusCode> PostPenaltiesAccounting([FromBody] PenaltiesAccounting penaltiesAccounting) { using (var _context = LibraryContext.Create()) { try { _context.PenaltiesAccountings.Add(penaltiesAccounting); await _context.SaveChangesAsync(); return(HttpStatusCode.Created); } catch (Exception) { return(HttpStatusCode.NoContent); } } }
public async Task <ActionResult <PenaltiesAccounting> > PostPenaltiesAccounting(PenaltiesAccounting penaltiesAccounting) { _context.PenaltiesAccountings.Add(penaltiesAccounting); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPenaltiesAccounting", new { id = penaltiesAccounting.PenaltiesAccountingID }, penaltiesAccounting)); }