コード例 #1
0
        // POST: Blums/Delete/All
        public async Task <IActionResult> DeleteAll()
        {
            _context.Blums.RemoveRange(_context.Blums);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public async Task CreateBook(BookDTO book)
        {
            Book my_Book = new Book()
            {
                //Id will be auto generated

                Title = book.Title,

                Author = book.Author,

                CategoryId = book.CategoryId,

                Category = book.Category,

                ISBN = book.ISBN,

                Price = book.Price,

                DateOfPublication = book.DateOfPublication
            };

            _context.Books.Add(my_Book);

            await _context.SaveChangesAsync();

            await _context.Books.Include(i => i.Category).ToListAsync();

            book.Id = my_Book.Id;

            book.Category = my_Book.Category;
        }
コード例 #3
0
        public async Task <Product> CreateAsync(Product entity)
        {
            var res = await ctx.Products.AddAsync(entity);

            await ctx.SaveChangesAsync();

            return(res.Entity);
        }
コード例 #4
0
        public async Task <Employee> CreateAsync(Employee entity)
        {
            var res = await _ctx.Emplopyees.AddAsync(entity);

            await _ctx.SaveChangesAsync();

            return(res.Entity);
        }
コード例 #5
0
        public async Task <Department> CreateAsync(Department entity)
        {
            var res = await _ctx.Departments.AddAsync(entity);

            await _ctx.SaveChangesAsync();

            return(res.Entity);
        }
コード例 #6
0
        public async Task <IActionResult> Create(OrderModel orderModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderModel));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("ID,ImageUrl,Name,Description,Price,RamAndStorage,BatteryCapacity")] LaptopModel laptopModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(laptopModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(laptopModel));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("ID,NAME,DSCRIP")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #9
0
        public async Task <IActionResult> UpdateAsset(Asset data)
        {
            var entity = await _dbContext.Assets.FindAsync(data.Id);

            entity.Name        = data.Name;
            entity.Description = data.Description;
            entity.TagNumber   = data.TagNumber;
            _dbContext.Update(entity);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #10
0
        public async Task CreateCategory(CategoryDTO cateogry)
        {
            Category newCategory = new Category()
            {
                //CategoryId is auto generated
                CategoryName = cateogry.CategoryName
            };

            _context.Categories.Add(newCategory);

            await _context.SaveChangesAsync();

            cateogry.CategoryId = newCategory.CategoryId;//Add CategoryId to DTO and return it
        }
コード例 #11
0
        public async Task <Contact> Create(Contact entity)
        {
            try
            {
                _db.Set <Contact>().Add(entity);
                await _db.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                //log exception
                return(null);
            }
        }
コード例 #12
0
        public async Task <Address> Create(Address entity)
        {
            try
            {
                _db.Set <Address>().Add(entity);
                await _db.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                //log exception
                return(null);
            }
        }
コード例 #13
0
        public async Task <ActionResult <Character> > CreateCharacter([FromBody] Character character)
        {
            _context.Add(character);
            await _context.SaveChangesAsync();

            return(Ok());
        }
コード例 #14
0
        public async Task <IActionResult> OnPostAsync()
        {
            _context.Animals.Add(Ani);
            await _context.SaveChangesAsync();

            return(RedirectToAction("/MinhaPagina"));
        }
コード例 #15
0
        public async Task <Category> CreateAsync(Category entity)
        {
            Category cat = null;

            try
            {
                var res = await ctx.Categories.AddAsync(entity);

                await ctx.SaveChangesAsync();

                cat = res.Entity;
                // return res.Entity;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(cat);
        }
コード例 #16
0
        // Functie stergere elemente cu Id-ul mai mare ca cel introdus
        public async Task <IActionResult> StergereElementeById(int numberId)
        {
            //return Content(numberId.ToString());
            // Stergere range elemente mai mari decat Id-ul introdus
            _context.Blums.RemoveRange(_context.Blums.Where(item => item.Id > numberId));
            await _context.SaveChangesAsync();

            // Redirection la Index
            return(RedirectToAction("Index", "Home"));
        }
コード例 #17
0
        public async Task <IActionResult> Create(LoveTeam student)
        {
            if (student == null)
            {
                return(BadRequest());
            }

            try
            {
                context.LoveTeams.Add(student);
                await context.SaveChangesAsync();

                return(Ok(new
                {
                    result = "Successfully saved"
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #18
0
        public async Task <ProfessorViewModel> Handle(CreateProfessorCommand request, CancellationToken cancellationToken)
        {
            var entity = new Professor
            {
                ProfessorId   = request.ProfessorId,
                ProfessorName = request.ProfessorName
            };

            _context.Professors.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(await _mediator.Send(new GetProfessorQuery(entity.ProfessorId), cancellationToken));
        }
コード例 #19
0
        public async Task <StudentViewModel> Handle(CreateStudentCommand request, CancellationToken cancellationToken)
        {
            var entity = new Student
            {
                StudentId   = request.StudentId,
                StudentName = request.StudentName
            };

            _context.Students.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(await _mediator.Send(new GetStudentQuery(entity.StudentId), cancellationToken));
        }
コード例 #20
0
        public async Task CreateCartItem(BookAsCartItemDTO favoriteBook)
        {
            BookAsCartItem chosenBook = new BookAsCartItem()
            {
                Id = favoriteBook.Id,

                Book = favoriteBook.Book,

                Price = favoriteBook.Price,

                Quantity = favoriteBook.Quantity,
            };

            _context.BooksAsCartItems.Add(chosenBook);

            await _context.SaveChangesAsync();

            await _context.BooksAsCartItems.Include(i => i.Book).Include(c => c.Book.Category).ToListAsync();

            favoriteBook.Id = chosenBook.Id;

            favoriteBook.Book = chosenBook.Book;//Book will not be null in postman
        }
コード例 #21
0
        public async Task <StudentDto> Handle(UpdateStudentCommand request, CancellationToken cancellationToken)
        {
            var student = request.Student;

            var entity = await _context.Students
                         .FindAsync(student.StudentId);

            if (entity == null)
            {
                throw new EntityNotFoundException(nameof(Student), student.StudentId);
            }

            entity.StudentId   = student.StudentId;
            entity.StudentName = student.StudentName;

            await _context.SaveChangesAsync(cancellationToken);

            return(StudentDto.Create(entity));
        }
コード例 #22
0
        public async Task <Unit> Handle(DeleteStudentCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Students.FindAsync(request.Id);

            if (entity == null)
            {
                throw new EntityNotFoundException(nameof(Student), request.Id);
            }

            var hasCourses = _context.StudentCourses.Any(c => c.StudentId == entity.StudentId);

            if (hasCourses)
            {
                foreach (var item in _context.StudentCourses)
                {
                    if (item.StudentId == request.Id)
                    {
                        _context.StudentCourses.Remove(item);
                    }
                }
            }
            var hasReports = _context.Reports.Any(c => c.StudentId == entity.StudentId);

            if (hasReports)
            {
                foreach (var item in _context.Reports)
                {
                    if (item.StudentId == request.Id)
                    {
                        _context.Reports.Remove(item);
                    }
                }
            }

            _context.Students.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
コード例 #23
0
 private async Task SaveChanges()
 {
     await context.SaveChangesAsync();
 }