Example #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(Category.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <ActionResult> Update([FromBody] Student student)
        {
            if (student == null)
            {
                response = new Response(false, "Student data is not supplied", null);
                return(NotFound(response));
            }
            if (!ModelState.IsValid)
            {
                response = new Response(false, "Error Message", ModelState);
                return(BadRequest(ModelState));
            }

            Student existingStudent = _mainContext.Students.FirstOrDefault(s => s.StudentId == student.StudentId);

            if (existingStudent == null)
            {
                response = new Response(false, "Student does not exist in the database", null);
                return(NotFound(response));
            }

            existingStudent.FirstName    = student.FirstName;
            existingStudent.LastName     = student.LastName;
            existingStudent.MobileNumber = student.MobileNumber;
            existingStudent.City         = student.City;
            existingStudent.Email        = student.Email;

            _mainContext.Attach(existingStudent).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _mainContext.SaveChangesAsync();

            response = new Response(true, "Update the student Successfully", existingStudent);
            return(Ok(response));
        }
Example #3
0
        public async Task <IActionResult> Add(string owner, string username)
        {
            UserContacts userContacts = _context.UserContacts.SingleOrDefault(el => (el.owner == owner));

            JObject currentContacts = userContacts.contacts;

            if (currentContacts["username"] == null)
            {
                currentContacts.Add(username, username);
            }

            userContacts.contacts = currentContacts;

            _context.Attach(userContacts);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task Update(Post post, int id)
        {
            Post existingPost = _mainContext.posts.FirstOrDefault(p => p.id == id);

            existingPost.title  = post.title;
            existingPost.author = post.author;
            existingPost.body   = post.body;
            existingPost.status = post.status;
            _mainContext.Attach(existingPost).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _mainContext.SaveChangesAsync();
        }
Example #5
0
        public async Task Update(Comment comment, int id)
        {
            Comment existingComment = _mainContext.comments.FirstOrDefault(c => c.id == id);

            existingComment.commentBody = comment.commentBody;
            existingComment.userId      = comment.userId;
            existingComment.postId      = comment.postId;

            _mainContext.Attach(existingComment).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _mainContext.SaveChangesAsync();
        }
Example #6
0
        public async Task Update(int id, Book book)
        {
            if (book == null)
            {
                throw new ArgumentNullException(nameof(Book));
            }
            Book existingBook = _mainContext.books.FirstOrDefault(b => b.BookId == id);

            if (existingBook == null)
            {
                throw new ArgumentNullException(nameof(existingBook));
            }
            existingBook.BookName      = book.BookName;
            existingBook.AuthorName    = book.AuthorName;
            existingBook.publisherName = book.publisherName;

            _mainContext.Attach(existingBook).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _mainContext.SaveChangesAsync();
        }
Example #7
0
        public async void Update(Student student)
        {
            if (student == null)
            {
                throw new ArgumentNullException(nameof(student));
            }

            Student existingStudent = _mainContext.Students.FirstOrDefault(s => s.StudentId == student.StudentId);

            if (existingStudent == null)
            {
                throw new ArgumentNullException(nameof(existingStudent));
            }

            existingStudent.FirstName    = student.FirstName;
            existingStudent.LastName     = student.LastName;
            existingStudent.MobileNumber = student.MobileNumber;
            existingStudent.City         = student.City;
            existingStudent.Email        = student.Email;

            _mainContext.Attach(existingStudent).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _mainContext.SaveChangesAsync();
        }