Beispiel #1
0
        public async Task <IActionResult> GetBookView([FromRoute] int id)
        {//получение книги по id
            try
            {
                if (!ModelState.IsValid)
                {
                    Log.WriteSuccess(" BookViewsController.GetBook", "Валидация внутри контроллера неудачна.");
                    return(BadRequest(ModelState));
                }

                var item = await _context.Book.SingleOrDefaultAsync(m => m.Id == id);

                if (item == null)
                {
                    Log.WriteSuccess(" BookViewsController.GetBook", "Книга не найдена.");
                    return(NotFound());
                }
                BookAdd b = new BookAdd()
                {
                    Id        = item.Id,
                    Content   = item.Content,
                    isDeleted = item.isDeleted,
                    Cost      = item.Cost,
                    image     = item.image,
                    Publisher = item.IdPublisher,
                    Stored    = item.Stored,
                    Title     = item.Title,
                    Year      = item.Year
                };
                List <int>               au          = new List <int>();
                List <string>            aus         = new List <string>();
                List <int>               ge          = new List <int>();
                List <string>            ges         = new List <string>();
                IEnumerable <BookAuthor> bookauthors = _context.BookAuthor.Where(f => f.IdBook == item.Id);
                IEnumerable <BookGenre>  bookgenres  = _context.BookGenre.Where(f => f.IdBook == item.Id);
                foreach (BookAuthor line in bookauthors)
                {
                    Author author = _context.Author.Find(line.IdAuthor);
                    au.Add(author.Id);
                    aus.Add(author.Name);
                }
                b.idAuthors = au.ToArray();
                b.Authors   = aus.ToArray();
                foreach (BookGenre line in bookgenres)
                {
                    Genre genre = _context.Genre.Find(line.IdGenre);
                    ge.Add(genre.Id);
                    ges.Add(genre.Name);
                }
                b.idGenres = ge.ToArray();
                b.Genres   = ges.ToArray();
                return(Ok(b));
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return(BadRequest(ModelState));
            }
        }
        // Add new
        public BookBase AddNew(BookAdd newItem)
        {
            // Add the new object
            var addedItem = RAdd(Mapper.Map <Book>(newItem));

            // Return the object
            return(Mapper.Map <BookBase>(addedItem));
        }
 //Order-Closed//
 private void BtnOrderFinish_Click(object sender, EventArgs e)
 {
     _orderDal.Update(_order);
     TxtLastMoney.Text = "";
     _book.Count      += _bookCount;
     _bookDal.Update(_book);
     BookAdd?.Invoke(_book, new EventArgs());
     FillDataOrder();
 }
Beispiel #4
0
        public void AddLine(MinibookMessage message)
        {
            if (IsIndexValid(message.BookHeader.Position))
            {
                BookAdd book = (BookAdd)message.BookHeader;
                cacheDirection.Insert(book.Position, book);

                NormalizeBook();
            }
        }
Beispiel #5
0
        //[Authorize(Roles = "admin")]
        public async Task <IActionResult> Create([FromBody] BookAdd item)
        {//создание новой книги возможно только администратором
            try
            {
                if (!ModelState.IsValid)
                {
                    Log.WriteSuccess(" BooksController.Create", "Валидация внутри контроллера неудачна.");
                    return(BadRequest(ModelState));
                }
                Book book = new Book()
                {
                    Year        = item.Year,
                    Title       = item.Title,
                    Stored      = item.Stored,
                    image       = item.image,
                    IdPublisher = item.Publisher,
                    Cost        = item.Cost,
                    Content     = item.Content,
                    isDeleted   = item.isDeleted
                };
                _context.Book.Add(book);
                for (int i = 0; i < item.idAuthors.Length; i++)
                {
                    BookAuthor bookauthor = new BookAuthor()
                    {
                        IdAuthor = item.idAuthors[i],
                        IdBook   = book.Id
                    };
                    _context.BookAuthor.Add(bookauthor);
                }
                for (int i = 0; i < item.idGenres.Length; i++)
                {
                    BookGenre bookgenre = new BookGenre()
                    {
                        IdGenre = item.idGenres[i],
                        IdBook  = book.Id
                    };
                    _context.BookGenre.Add(bookgenre);
                }
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetBook", new { id = book.Id }, book));
            } catch (Exception ex)
            {
                Log.Write(ex);
                return(BadRequest(ModelState));
            }
        }
Beispiel #6
0
        public static void TestBook()
        {
            var msg = "M:PETR3:A:0:A:13.08:100:15:11071759:0:5";
            BookParseProtocolCMP parse = new BookParseProtocolCMP();

            var     bookCol11 = parse.Parse(msg);
            BookAdd bookAdd   = (BookAdd)bookCol11.BookHeader;

            Console.WriteLine(bookAdd.BrokerId);

            msg = "M:PETR4:A:0:A:99.99:100:131:11041005";

            var bookCol9 = parse.Parse(msg);

            bookAdd = (BookAdd)bookCol9.BookHeader;
            Console.WriteLine(bookAdd.BrokerId);

            msg = "M:PETR3:D:3:5";

            var bookDel = parse.Parse(msg);
            var book    = (BookDelete)bookDel.BookHeader;

            Console.WriteLine(book.DeleteType);
        }
Beispiel #7
0
        private void bookAddBtn_Click(object sender, EventArgs e)
        {
            var bookForm = new BookAdd();

            Nav(bookForm, contentPanel);
        }
Beispiel #8
0
        public async Task <IActionResult> Update([FromRoute] int id, [FromBody] BookAdd book)
        {//обновление информации о существующей книге возможно только администратором
            try
            {
                if (!ModelState.IsValid)
                {
                    Log.WriteSuccess(" BookViewsController.Update", "Валидация внутри контроллера неудачна.");
                    return(BadRequest(ModelState));
                }
                var item = _context.Book.Find(id);
                if (item == null)
                {
                    Log.WriteSuccess(" BookViewsController.Update", "Книга не найдена.");
                    return(NotFound());
                }
                item.Content     = book.Content;
                item.Cost        = book.Cost;
                item.image       = book.image;
                item.Stored      = book.Stored;
                item.Title       = book.Title;
                item.Year        = book.Year;
                item.isDeleted   = book.isDeleted;
                item.IdPublisher = book.Publisher;

                IEnumerable <BookAuthor> bookauthors = _context.BookAuthor.Where(b => b.IdBook == item.Id);
                IEnumerable <BookGenre>  bookgenres  = _context.BookGenre.Where(b => b.IdBook == item.Id);
                foreach (BookAuthor line in bookauthors)
                {
                    IEnumerable <int> el = book.idAuthors.Where(a => a == line.IdAuthor);
                    if (el.Any())//found the same
                    {
                        book.idAuthors = book.idAuthors.Where(val => val != el.FirstOrDefault()).ToArray();
                    }
                    else
                    {
                        _context.BookAuthor.Remove(line);
                    }
                }
                while (book.idAuthors.Any())//found the new
                {
                    int        el = book.idAuthors[0];
                    BookAuthor z  = new BookAuthor()
                    {
                        IdBook   = id,
                        IdAuthor = el
                    };
                    _context.BookAuthor.Add(z);
                    book.idAuthors = book.idAuthors.Where(val => val != el).ToArray();
                }

                foreach (BookGenre line in bookgenres)
                {
                    IEnumerable <int> el = book.idGenres.Where(a => a == line.IdGenre);
                    if (el.Any())//found the same
                    {
                        book.idGenres = book.idGenres.Where(val => val != el.FirstOrDefault()).ToArray();
                    }
                    else
                    {
                        _context.BookGenre.Remove(line);
                    }
                }

                while (book.idGenres.Any())//found the new
                {
                    int       el = book.idGenres[0];
                    BookGenre z  = new BookGenre()
                    {
                        IdBook  = id,
                        IdGenre = el
                    };
                    _context.BookGenre.Add(z);
                    book.idGenres = book.idGenres.Where(val => val != el).ToArray();
                }

                _context.Book.Update(item);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return(BadRequest(ModelState));
            }
        }