コード例 #1
0
        public async Task <IActionResult> PutClassroomModel([FromRoute] int id, [FromBody] ClassroomModel classroomModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != classroomModel.classroomId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutResponseModel([FromRoute] string id, [FromBody] ResponseModel responseModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != responseModel.responseType)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutPerson(int id, Person person)
        {
            if (id != person.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
0
        public async Task <IActionResult> PutMens([FromRoute] int id, [FromBody] Ingredient ingredient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ingredient.ingredientID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Code,Initials,FristName,Surname,Address1,Address2,DateOFBirth,Status,Id")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("FristName,Surname,Relationship,FkEmployeeId,Id")] EmployeeFamily employeeFamily)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employeeFamily);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FkEmployeeId"] = new SelectList(_context.Employees, "Id", "Address1", employeeFamily.FkEmployeeId);
            return(View(employeeFamily));
        }
コード例 #7
0
        public async Task <IActionResult> PostPost([FromBody] Post post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await usermanager.GetUserAsync(User);

            post.ID       = user.Id;
            post.dateTime = DateTime.Now;

            context.Post.Add(post);
            await context.SaveChangesAsync();

            return(CreatedAtAction("GetPost", new { id = post.ID }, post));
        }
コード例 #8
0
        public async Task <IActionResult> Delete(int id)
        {
            var bookFromDb = await _db.Book.FirstOrDefaultAsync(u => u.Id == id);

            if (bookFromDb == null)
            {
                return(Json(new { success = false, message = "Error while Deleting" }));
            }
            _db.Book.Remove(bookFromDb);
            await _db.SaveChangesAsync();

            return(Json(new { success = true, message = "Delete successful" }));
        }
コード例 #9
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Book.Id == 0)
                {
                    _db.Book.Add(Book);
                }
                else
                {
                    _db.Book.Update(Book);
                }

                await _db.SaveChangesAsync();

                return(RedirectToPage("Books"));
            }
            return(RedirectToPage());
        }