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

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

            return(CreatedAtAction("GetStudentFavNotebooks",
                                   new { NotebookId = studentFavNotebooks.NotebookId, StudentId = studentFavNotebooks.StudentId }, studentFavNotebooks));
        }
        // Add Current to favorite
        private bool AddToFavorite()
        {
            StudentFavNotebooks sfn = new StudentFavNotebooks {
                StudentId = Settings.StudentId, NotebookId = _viewNotebookStudent.Notebook.Id
            };

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

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

            return(response.IsSuccessStatusCode);
        }
Пример #3
0
        public async Task <IActionResult> PutStudentFavNotebooks([FromRoute] string IdentityId, [FromRoute] int NotebookId, [FromBody] StudentFavNotebooks studentFavNotebooks)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }