예제 #1
0
        /// <summary>
        /// 添加图书
        /// </summary>
        /// <param name="book">图书信息</param>
        /// <returns>添加成功条数</returns>
        public async Task <int> Insert(Book book)
        {
            if (!string.IsNullOrEmpty(book.Img))
            {
                var filePath = "/UploadFile/";

                book.Img = Transport(book.Img, filePath, DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg");
            }

            book.CreateTime = DateTime.Now;
            book.EditTime   = DateTime.Now;
            book.Id         = Guid.NewGuid().ToString().Replace("-", "");
            _context.Book.Add(book);
            return(await _context.SaveChangesAsync().ConfigureAwait(false));
        }
예제 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }