Example #1
0
 private async Task PostPenalty()
 {
     if (!string.IsNullOrWhiteSpace(AccountsDrop.Text) && !string.IsNullOrWhiteSpace(TypeField.Text) && !string.IsNullOrWhiteSpace(BookDrop.Text))
     {
         LibraryAccounting libraryAccounting = new LibraryAccounting
         {
             AccountID      = (int)AccountsDrop.SelectedValue,
             BookID         = (int)BookDrop.SelectedValue,
             Type           = TypeField.Text,
             IssueDate      = IssueDatePicker.Value,
             CompletionDate = CompletionDatePicker.Value
         };
         try
         {
             await _libraryAccountingProxy.AddLibraryAccounting(libraryAccounting);
         }
         catch (HttpException ex)
         {
             MessageBox.Show($"Ошибка:{ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             throw ex;
         }
     }
     else
     {
         MessageBox.Show("Заполните данные о штрафе", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public async Task <ActionResult <LibraryAccounting> > PostLibraryAccounting(LibraryAccounting libraryAccounting)
        {
            _context.LibraryAccounting.Add(libraryAccounting);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLibraryAccounting", new { id = libraryAccounting.LibraryAccountingID }, libraryAccounting));
        }
        public async Task <IActionResult> PutLibraryAccounting(int id, LibraryAccounting libraryAccounting)
        {
            if (id != libraryAccounting.LibraryAccountingID)
            {
                return(BadRequest());
            }

            _context.Entry(libraryAccounting).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LibraryAccountingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
        public async Task <LibraryAccounting> AddLibraryAccounting(LibraryAccounting libraryAccounting)
        {
            var jsonString = JsonConvert.SerializeObject(libraryAccounting);
            var content    = new StringContent(jsonString, Encoding.UTF8, "application/json");
            var response   = await httpClient.PostAsync("/api/LibraryAccountings", content);

            var code   = response.StatusCode;
            var result = responseReader.ReadObjectAsync <LibraryAccounting>(response);

            if (code == (HttpStatusCode)200)
            {
                return(await result);
            }
            return(null);
        }
        public async Task <HttpStatusCode> PostLibraryAccounting([FromBody] LibraryAccounting libraryAccounting)
        {
            using (var _context = LibraryContext.Create())
            {
                try
                {
                    _context.LibraryAccounting.Add(libraryAccounting);
                    await _context.SaveChangesAsync();

                    return(HttpStatusCode.Created);
                }
                catch (Exception)
                {
                    return(HttpStatusCode.NoContent);
                }
            }
        }