public async Task <IActionResult> Edit(int id, [Bind("BookId,Price,Id")] BookPrice bookPrice) { if (id != bookPrice.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookPrice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookPriceExists(bookPrice.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "Id", "Author", bookPrice.BookId); return(View(bookPrice)); }
public static void BookPriceNotFound(this IGuardClause guardClause, BookPrice bookPrice, Guid bookPriceId) { if (bookPrice == null) { throw new BookPriceNotFoundException(bookPriceId); } }
public async Task <BookPrice> AddBookPrice(Guid bookId, decimal price, string remark) { Guard.Against.NegativePrice(price); BookPrice bookPrice = new BookPrice(bookId, price, remark); await _priceRepository.InsertAsync(bookPrice); return(bookPrice); }
public override uint GetPrice() { double basePrice = BookPrice.GetPrice(); #if DEBUG WriteLine("UsedBookSale : GetPrice"); #endif var price = basePrice * (1 - DiscountRate); return((uint)price); }
public async Task <BookPrice> EditBookPrice(Guid bookPriceId, decimal price) { Guard.Against.NegativePrice(price); BookPrice bookPrice = await _priceRepository.GetAsync(bookPriceId); Guard.Against.BookPriceNotFound(bookPrice, bookPriceId); bookPrice.Price = price; await _priceRepository.UpdateAsync(bookPrice); return(bookPrice); }
public async Task <IActionResult> Create([Bind("BookId,Price,Id")] BookPrice bookPrice) { if (ModelState.IsValid) { _context.Add(bookPrice); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BookId"] = new SelectList(_context.Books, "Id", "Author", bookPrice.BookId); return(View(bookPrice)); }
private void Seed(ModelBuilder modelBuilder) { var visitor1 = new Visitor { Id = -1, Name = "Alex" }; var visitor2 = new Visitor { Id = -2, Name = "Oleg" }; modelBuilder.Entity <Visitor>().HasData(visitor1); modelBuilder.Entity <Visitor>().HasData(visitor2); var book1 = new Book { Id = -1, Title = "Гипербола с половиной", Author = "Элли Брош", PagesCount = 500, VisitorId = visitor1.Id }; var book2 = new Book { Id = -2, Title = "Тревожные люди", Author = "Фредрик Бакман", PagesCount = 600 }; var book3 = new Book { Id = -3, Title = "Симон", Author = "Наринэ Абгарян", PagesCount = 400, VisitorId = visitor1.Id }; var book4 = new Book { Id = -4, Title = "Стеклянный отель", Author = "Эмили Сент-Джон Мандел", PagesCount = 1000 }; modelBuilder.Entity <Book>().HasData(book1); modelBuilder.Entity <Book>().HasData(book2); modelBuilder.Entity <Book>().HasData(book3); modelBuilder.Entity <Book>().HasData(book4); var bookPrice1 = new BookPrice { Id = -1, BookId = book1.Id, Price = 100 }; var bookPrice2 = new BookPrice { Id = -2, BookId = book2.Id, Price = 200 }; var bookPrice3 = new BookPrice { Id = -3, BookId = book3.Id, Price = 300 }; var bookPrice4 = new BookPrice { Id = -4, BookId = book4.Id, Price = 400 }; modelBuilder.Entity <BookPrice>().HasData(bookPrice1); modelBuilder.Entity <BookPrice>().HasData(bookPrice2); modelBuilder.Entity <BookPrice>().HasData(bookPrice3); modelBuilder.Entity <BookPrice>().HasData(bookPrice4); }
public override uint GetPrice() { // throw new NotImplementedException(); var price = BookPrice.GetPrice(); #if DEBUG WriteLine("Yes24PointSale : GetPrice"); #endif // 포인트가 가격보다 작거나 같으면 if (price >= Yes24Point) { return(price - Yes24Point); } else { throw new ArgumentException(message: "사용할 Yes24 포인트가 제품의 가격보다 크다.", paramName: nameof(Yes24Point)); } }
public static void Main() { // Create the XslCompiledTransform and load the stylesheet. XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("prices.xsl"); // Create an XsltArgumentList. XsltArgumentList xslArg = new XsltArgumentList(); // Add an object to calculate the new book price. BookPrice obj = new BookPrice(); xslArg.AddExtensionObject("urn:price-conv", obj); using (XmlWriter w = XmlWriter.Create("output.xml")) { // Transform the file. xslt.Transform("books.xml", xslArg, w); } }
static void FillTables(LibraryContext context) { var bookToAdd1 = new Book { Title = "Title1", Author = "Author1", PagesCount = 100 }; var bookToAdd2 = new Book { Title = "Title2", Author = "Author2", PagesCount = 100 }; context.Books.Add(bookToAdd1); context.Books.Add(bookToAdd2); var bookPrice = new BookPrice { Book = bookToAdd2, Price = 10000m }; context.BookPrices.Add(bookPrice); var visitor = new Visitor { Name = "Ivan", TakenBooks = new List <Book> { bookToAdd1, bookToAdd2 } }; context.Visitors.Add(visitor); context.SaveChanges(); }
public async Task <ActionResult <BookPrice> > AddBookPrice(AddPriceDto dto) { BookPrice bookPrice = await _priceViewService.AddBookPrice(dto); return(CreatedAtAction(nameof(GetPriceList), new { })); }