Inheritance: MonoBehaviour, IIgnitable
        public IHttpActionResult GetBookcaseRate(string id)
        {
            try
            {
                conn.Open();
                id = "'" + id + "'";
                String     url = "select AVG(Rate) as rate, count(bookId) as countNum from BookCase where bookId = " + id;
                SqlCommand cmd = new SqlCommand(url, conn);
                reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    bookcase = new Bookcase();
                    if (!reader.IsDBNull(0))
                    {
                        bookcase.rate = reader.GetInt32(0);
                    }
                    if (!reader.IsDBNull(1))
                    {
                        bookcase.countDownload = reader.GetInt32(1);
                    }
                    return(Ok(bookcase));
                }
            }
            catch (Exception e)
            {
                return(NotFound());
            }
            finally
            {
                closeConnect();
            }
            return(NotFound());
        }
        public IHttpActionResult GetMark(int accId, int bookId)
        {
            try
            {
                conn.Open();

                String     url = "select BookMark from BookCase where accId = " + accId + " and bookId = " + bookId;
                SqlCommand cmd = new SqlCommand(url, conn);
                reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    bookcase = new Bookcase();
                    if (!reader.IsDBNull(0))
                    {
                        bookcase.bookMark = reader.GetInt32(0);
                    }

                    return(Ok(bookcase));
                }
            }
            catch (Exception e)
            {
                return(NotFound());
            }
            finally
            {
                closeConnect();
            }
            return(NotFound());
        }
        public async Task <IActionResult> add(int bookcase_id, int star, string review)
        {
            try {
                Bookcase bookcase = await _bookcaseRepository.Get(bookcase_id);

                if (bookcase == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                var  username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                User user     = await _userRepository.FindByUsername(username);

                if (user == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                RateBookcase rateBookcase = new RateBookcase
                {
                    bookcase_id = bookcase.bookcase_id,
                    star        = star,
                    review      = review,
                    user_id     = user.user_id
                };

                await _rateBookcaseRepository.Add(rateBookcase);

                return(Ok(new Respone(200, "ok", null)));
            } catch (Exception e) {
                return(BadRequest(new Respone(400, "Failed", null)));
            }
        }
        public async Task <IActionResult> getReturnCode(int bookcase_id)
        {
            try {
                var  username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                User user     = await _userRepository.FindByUsername(username);

                if (user == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                Bookcase bookcase = await _bookcaseRepository.Get(bookcase_id);

                if (bookcase.user_id != user.user_id)
                {
                    return(BadRequest(new Respone(400, "Failed", null)));
                }

                Borrow borrow = await _borrowRepository.FindByBookcase(bookcase_id);

                if (borrow == null || borrow.return_date != null)
                {
                    return(BadRequest(new Respone(400, "Chưa mượn", null)));
                }

                var resultCode = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("Return " + borrow.borrow_id));
                return(Ok(new Respone(200, "ok", new {
                    code = resultCode
                })));
            } catch (Exception e) {
                return(BadRequest(new Respone(400, "Failed", null)));
            }
        }
Beispiel #5
0
        private static IFurniture EnterBookcase()
        {
            Bookcase b = null;

            while (b == null)
            {
                try
                {
                    Console.WriteLine("Выберете матреиал 1 - дерево, в остальных случаях сталь");
                    Material mat = SelectMaterial();
                    Console.WriteLine("Введите количество полок");
                    int shelfCount = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Введите стартовую цену");
                    float startPrice = Convert.ToSingle(Console.ReadLine());
                    Console.WriteLine("Введите год выпуска");
                    int      year     = Convert.ToInt32(Console.ReadLine());
                    Location location = SelectLocation();
                    Console.WriteLine("Введите количество книжек на полке");
                    int count = Convert.ToInt32(Console.ReadLine());
                    b = new Bookcase(mat, shelfCount, startPrice, year, location, count);
                }
                catch (FormatException e)
                {
                    Console.WriteLine("что-то неправильно!");
                }
            }

            return(b);
        }
        public async Task <IActionResult> delete(int bookcase_id)
        {
            try {
                Bookcase bookcase = await _bookcaseRepository.Get(bookcase_id);

                if (bookcase == null)
                {
                    return(NotFound(new Respone(404, "Bookcase not found", null)));
                }

                var  username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                User user     = await _userRepository.FindByUsername(username);

                if (user == null)
                {
                    return(NotFound(new Respone(404, "NotFound", null)));
                }

                if (bookcase.user_id == user.user_id)
                {
                    await _bookcaseRepository.Delete(bookcase_id);
                }

                return(Ok(new Respone(200, "ok", null)));
            } catch (Exception e) {
                return(BadRequest(new Respone(400, "Failed", null)));
            }
        }
        public async Task <IActionResult> add(string sku)
        {
            try {
                Book book = await _bookRepository.FindBySKU(sku);

                if (book == null)
                {
                    return(NotFound(new Respone(404, "Book not found", null)));
                }

                var  username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                User user     = await _userRepository.FindByUsername(username);

                if (user == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                Bookcase bookcase = new Bookcase
                {
                    book_id = book.book_id,
                    user_id = user.user_id
                };

                await _bookcaseRepository.Add(bookcase);

                return(Ok(new Respone(200, "ok", null)));
            } catch (Exception e) {
                return(BadRequest(new Respone(400, "Failed", null)));
            }
        }
        public async Task <IActionResult> get(int bookcase_id)
        {
            try {
                Bookcase bookcase = await _bookcaseRepository.Get(bookcase_id);

                if (bookcase == null)
                {
                    return(NotFound(new Respone(404, "Bookcase not found", null)));
                }

                var  username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                User user     = await _userRepository.FindByUsername(username);

                if (user == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                if (bookcase.user_id != user.user_id)
                {
                    return(BadRequest(new Respone(400, "Failed", null)));
                }

                Book book = await _bookRepository.Get(bookcase.book_id);

                var dict = new Dictionary <String, object>();
                dict.Add("bookcase_id", bookcase.bookcase_id);
                dict.Add("book", book);

                return(Ok(new Respone(200, "ok", dict)));
            } catch (Exception e) {
                return(BadRequest(new Respone(400, "Failed", null)));
            }
        }
Beispiel #9
0
    public void bindCase()
    {
        string sql = "select * from tb_bookcase";

        Bookcase.DataSource   = dataOperate.getDataset(sql, "tb_bookcase");
        Bookcase.DataKeyNames = new string[] { "bookcaseID" };
        Bookcase.DataBind();
    }
Beispiel #10
0
        public Bookcase Get()
        {
            Bookcase bookcase = new Bookcase {
            };

            if ((bookcase.Name == null) && (bookcase.Size == 0) && (bookcase.ShelvesCount == 0))
            {
                Log.Info("до 200см высотой шкафы");
            }
            return(bookcase);
        }
        public IHttpActionResult GetBookCaseByUserId(string id)
        {
            try
            {
                conn.Open();
                id = "'" + id + "'";
                String url = "select b.bookId as bookId, b.bookName as bookName, b.bookImage as bookImage," +
                             " b.bookLink as bookLink, au.autName as autName," +
                             " bc.BookMark as bookMard, bc.Rate as rate,  b.bookDescription as bookDescription " +
                             "from BookCase bc, Book b, Account a, Author au " +
                             "where bc.accId = a.accId and bc.bookId = b.bookId and b.AuthorautId = au.autId " +
                             "and a.accId = " + id + " order by  b.bookName";
                SqlCommand cmd = new SqlCommand(url, conn);
                reader = cmd.ExecuteReader();
                List <Bookcase> lst = new List <Bookcase>();
                while (reader.Read())
                {
                    bookcase        = new Bookcase();
                    bookcase.bookId = reader.GetInt32(0);
                    bookcase.name   = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                    {
                        bookcase.bookImage = reader.GetString(2);
                    }

                    bookcase.bookLink = reader.GetString(3);
                    bookcase.autName  = reader.GetString(4);
                    bookcase.bookMark = reader.GetInt32(5);
                    if (!reader.IsDBNull(6))
                    {
                        bookcase.rate = (double)reader.GetInt32(6);
                    }
                    if (!reader.IsDBNull(7))
                    {
                        bookcase.bookDescription = reader.GetString(7);
                    }
                    lst.Add(bookcase);
                }
                return(Ok(lst));
            }
            catch (Exception e)
            {
                return(NotFound());
            }
            finally
            {
                closeConnect();
            }
            return(NotFound());
        }
        static void Main(string[] args)
        {
            // Класс шкаф - содержит полки, содержит фиксированное
            // количество полок. Позволяет брать и класть книгу.

            Bookcase bookcase = new Bookcase(2, 5);

            Book book1 = new Book("author1", "name1", "text1", 1900, 100);
            Book book2 = new Book("author2", "name2", "text2", 2000, 200);

            bookcase.AddBook(book1, 2);
            bookcase.AddBook(book2, 1);

            Book book3 = bookcase.GetBook("name1");
        }
        public async Task <IActionResult> borrow(String code)
        {
            try {
                code = Encoding.UTF8.GetString(Convert.FromBase64String(code));
                int bookcase_id = Convert.ToInt32(code.Substring(6));

                Borrow borrowed = await _borrowRepository.FindByBookcase(bookcase_id);

                if (borrowed != null && borrowed.return_date == null)
                {
                    return(BadRequest(new Respone(400, "Borrowed", null)));
                }

                Bookcase bookcase = await _bookcaseRepository.Get(bookcase_id);

                if (bookcase == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                var  username = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                User user     = await _userRepository.FindByUsername(username);

                if (user == null)
                {
                    return(NotFound(new Respone(404, "Not Found", null)));
                }

                if (bookcase.user_id == user.user_id)
                {
                    return(BadRequest(new Respone(400, "Failed", null)));
                }

                Borrow borrow = new Borrow {
                    user_id_borrow = user.user_id,
                    bookcase_id    = bookcase_id
                };

                await _borrowRepository.Add(borrow);

                return(Ok(new Respone(200, "ok", null)));
            } catch (Exception e) {
                return(BadRequest(new Respone(400, "Failed", null)));
            }
        }
Beispiel #14
0
 protected void Bookcase_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
     Bookcase.PageIndex = e.NewPageIndex;                //设置当前页的索引
     Bookcase.DataBind();
 }