Пример #1
0
        public async Task <IActionResult> PostNotebookRates([FromBody] NotebookRates notebookRates)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.NotebookRates.Add(notebookRates);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (NotebookRatesExists(notebookRates.Student.IdentityId, notebookRates.NotebookId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetNotebookRates", new { id = notebookRates.NotebookId }, notebookRates));
        }
        public async Task PostRate(byte rate)
        {
            Busy = true;

            NotebookRates sfn = new NotebookRates {
                StudentId = Settings.StudentId, NotebookId = _viewNotebookStudent.Notebook.Id, Rate = rate
            };

            var content = new StringContent(JsonConvert.SerializeObject(sfn), Encoding.UTF8, "application/json");

            _client.BaseAddress = new Uri("https://altaarefapp.azurewebsites.net");
            var response = await _client.PostAsync("api/NotebookRates", content);

            //return response.IsSuccessStatusCode;

            Busy = false;
        }
Пример #3
0
        public async Task <IActionResult> PutNotebookRates([FromRoute] int NotebookId, [FromRoute] string IdentityId, [FromBody] NotebookRates notebookRates)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (NotebookId != notebookRates.NotebookId || IdentityId != notebookRates.Student.IdentityId)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotebookRatesExists(IdentityId, NotebookId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }