public async Task <IActionResult> Create(AuthorViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                Author author = new Author
                {
                    Picture     = uniqueFileName,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    DateofBirth = model.DateofBirth,
                    DateofDeath = model.DateofBirth,
                    Biography   = model.Biography,
                    Rewards     = model.Rewards,
                    Book        = model.Book,
                    Books       = model.Books
                };

                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemple #2
0
        /*       public async Task<IActionResult> Create([Bind("Title, OriginalTitle, Genre, Synopsis, NumberofPages, Picture, Price, ReleaseDate, Publisher, Movie, Author, Authorid")]Book book)
         *     {
         *         if (ModelState.IsValid)
         *         {
         *
         *             _context.Add(book);
         *             await _context.SaveChangesAsync();
         *             return RedirectToAction(nameof(Index));
         *         }
         *       PopulateDropDownList(book.Authorid);
         *        return View();
         *     }
         */
        public async Task <IActionResult> Create(BookViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                Book book = new Book
                {
                    Picture       = uniqueFileName,
                    Title         = model.Title,
                    OriginalTitle = model.OriginalTitle,
                    Genre         = model.Genre,
                    Synopsis      = model.Synopsis,
                    NumberofPages = model.NumberofPages,
                    Price         = model.Price,
                    ReleaseDate   = model.ReleaseDate,
                    Publisher     = model.Publisher,
                    Movie         = model.Movie,
                    Authorid      = model.Authorid
                };

                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
        public async Task <IActionResult> PutBookstoreOrder(int id, BookstoreOrder bookstoreOrder)
        {
            if (id != bookstoreOrder.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Category,BookTitle,BookAuthor,BookPrice,BookDescription,Bestseller,Publisher,ReleaseDate,Pages")] Book book)
        {
            bool NotUniqueTitle = db.Books.Any(x => x.BookTitle == book.BookTitle);

            if (NotUniqueTitle)
            {
                ModelState.AddModelError("Title", "Książka o tym tytule już istnieje");
            }
            try
            {
                if (ModelState.IsValid)
                {
                    db.Add(book);
                    await db.SaveChangesAsync();

                    TempData["Message"] = "Dodano książkę o tytule " + book.BookTitle + ", której autorem jest " + book.BookAuthor;
                    var title  = book.BookTitle;
                    var author = book.BookAuthor;
                    HttpContext.Session.SetString("Session_1", "Niedawno dodano informacje o książce: " + title + ", której autorem jest " + author);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (System.Data.DataException)
            {
                ModelState.AddModelError("", "Dodawanie książki nie powiodło się");
            }
            return(View(book));
        }
Exemple #5
0
        public async Task <Warehouse> Create(Warehouse warehouse)
        {
            var entry = await context.Warehouses.AddAsync(warehouse);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #6
0
        public async Task <Agency> Create(Agency agency)
        {
            var entry = await context.Agencies.AddAsync(agency);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #7
0
        public async Task <Employee> Create(Employee employee)
        {
            var entry = await context.Employees.AddAsync(employee);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #8
0
        public async Task <Other> Create(Other other)
        {
            var entry = await context.Others.AddAsync(other);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #9
0
        public async Task <Account> Create(Account account)
        {
            var entry = await context.Accounts.AddAsync(account);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #10
0
        public async Task <Book> Create(Book book)
        {
            var entry = await context.Books.AddAsync(book);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #11
0
        public async Task <Vendor> Create(Vendor vendor)
        {
            var entry = await context.Vendors.AddAsync(vendor);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #12
0
        public async Task <IActionResult> Create([Bind("BookId,Author,Title,Year,ISBN")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Exemple #14
0
        public async Task <IActionResult> Create([Bind("ID,name,brand,model")] Printer printer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(printer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(printer));
        }
Exemple #15
0
        public async Task <IActionResult> Create([Bind("Id,Firstname,Lastname")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemple #16
0
        public async Task <IActionResult> Create([Bind("UserId,Nick,Password,Email,City,Street,HouseNumber,PostalCode")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task Delete(Guid id)
        {
            var book = await GetBookWithImage(id);

            if (book != null)
            {
                _context.Images.Remove(book.CoverImage);
                _context.Books.Remove(book);
                await _context.SaveChangesAsync();
            }
        }
Exemple #18
0
        public async Task <IActionResult> Create([Bind("TItle, Synopsis, BookId, Picture, ReleaseDate, Trailer, Rating, Book")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateDropDownList(movie.BookId);
            return(View());
        }
Exemple #19
0
        public async Task <IActionResult> Create([Bind("Title, OriginalTitle, Genre, Synopsis, NumberofPages, Picture, Price, ReleaseDate, Publisher, Movie, Author, Authorid")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateDropDownList(book.Authorid);
            return(View());
        }
        public async Task <IActionResult> Create([Bind("ISBN,Title,Language,Pages,AuthorId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Author, "Id", "Name", book.AuthorId);
            return(View(book));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ItemID,Name,DisplayName,Price,ItemCategoryID")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Entry(item).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ItemCategoryID = new SelectList(db.ItemCategories, "ItemCategoryID", "Name", item.ItemCategoryID);
            return(View(item));
        }
Exemple #22
0
        public async Task <IActionResult> Create([Bind("Id,Total,Details,DateCreated,DateModified,CustomerId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Id", order.CustomerId);
            return(View(order));
        }
        public async Task <ActionResult> Create([Bind(Include = "CartID,CreateTimestamp,OrderID")] Cart cart)
        {
            if (ModelState.IsValid)
            {
                cart.CartID = Guid.NewGuid();
                db.Carts.Add(cart);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.OrderID = new SelectList(db.Orders, "OrderID", "OrderID", cart.OrderID);
            return(View(cart));
        }
Exemple #24
0
        public async Task <IActionResult> Addproduct(Addproductmodal productToAdd)
        {
            var existingbook = entity.Books.Where(s => s.ISBN == productToAdd.book.ISBN).FirstOrDefault();

            if (existingbook == null)
            {
                using (var Client = new HttpClient())
                {
                    StringContent content = new StringContent(JsonConvert.SerializeObject(productToAdd.book), Encoding.UTF8, "application/json");
                    using (var response = await Client.PostAsync("https://localhost:5001/api/Book", content))
                    {
                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            _logger.LogInformation(response.Content.ToString());
                        }
                        else
                        {
                            return(BadRequest(response.Content.ToString()));
                        }
                    }
                }
                existingbook = entity.Books.Where(s => s.ISBN == productToAdd.book.ISBN).FirstOrDefault();
            }
            var productCheck = entity.Products.Where(s => s.BookId == existingbook.BookId && s.vendor_Id == productToAdd.vendor_Id).FirstOrDefault();

            if (productCheck != null)
            {
                return(BadRequest("This product already exist"));
            }
            try
            {
                await entity.Products.AddAsync(new products
                {
                    BookId          = existingbook.BookId,
                    vendor_Id       = productToAdd.vendor_Id,
                    Quantity        = productToAdd.Quantity,
                    price           = productToAdd.price,
                    DiscountPercent = productToAdd.DiscountPercent
                });

                await entity.SaveChangesAsync();
            }
            catch
            {
                return(BadRequest("something went wrong"));
            }

            return(Ok("product has been added succesfully"));
        }
Exemple #25
0
        public async Task <Import> Create(Import import)
        {
            var entry = await context.Imports.AddAsync(import);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #26
0
        public async Task <Export> Create(Export export)
        {
            var entry = await context.Exports.AddAsync(export);

            await context.SaveChangesAsync();

            return(entry.Entity);
        }
Exemple #27
0
        public async Task <int> AddNewBook(BookModel model)
        {
            var newbook = new Books()
            {
                bookname    = model.bookname,
                author      = model.author,
                description = model.description,
                TotalPages  = model.TotalPages.HasValue?model.TotalPages.Value:0
            };
            await _context.Books.AddAsync(newbook);

            await _context.SaveChangesAsync();

            return(newbook.id);
        }
 public async Task <bool> SaveChangesAsync()
 {
     return((await _context.SaveChangesAsync()) > 0);
 }