public bool Add(Book book, HttpPostedFileBase image)
        {
            using (BinaryReader br = new BinaryReader(image.InputStream))
            {
                book.Data = br.ReadBytes(image.ContentLength);
            }
            db.Books.Add(book);
            int saved = db.SaveChanges();

            if (saved > 0)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        public IActionResult AddBook(BookViewModel b)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            var book = new BookModel
            {
                Author       = b.Author,
                Publisher    = b.Publisher,
                SerialNumber = b.SerialNumber,
                Title        = b.Title,
            };

            _context.Books.Add(book);
            _context.SaveChanges();

            return(Ok(book));
        }
        public bool AddUser(User user)
        {
            db.Users.Add(user);
            int isExecute = db.SaveChanges();

            if (isExecute > 0)
            {
                return(true);
            }

            return(false);
        }
Example #4
0
        public IActionResult AddUser([FromBody] UserViewModel u)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            var now = Utility.GetTurkeyCurrentDateTime();

            var user = new UserModel
            {
                FirstName = u.FirstName,
                LastName  = u.LastName,
                Email     = u.Email,
                Password  = u.Password,
                CreatedAt = now
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            return(Ok(user));
        }
        public IActionResult AddBorrowHistory(BorrowHistoryViewModel b)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            var now = Utility.GetTurkeyCurrentDateTime();

            var borrowHistory = new BorrowHistoryModel
            {
                Id         = b.Id,
                BookId     = b.BookId,
                CustomerId = b.CustomerId,
                BorrowDate = now,
                ReturnDate = b.ReturnDate
            };

            _context.BorrowHistories.Add(borrowHistory);
            _context.SaveChanges();

            return(Ok(borrowHistory));
        }