Example #1
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     if (ControlProblems())
     {
         DiagnosisDetails();
         if (detailType == DetailType.Add)
         {
             bookManager.Add(book);
             notification.shownot("Ekleme işlemi başarılı");
         }
         else if (detailType == DetailType.Edit && IsExcelData == true)
         {
             bookManager.Add(book);
             notification.shownot("Ekleme işlemi başarılı");
             ContinueBooks();
         }
         else if (detailType == DetailType.Edit)
         {
             bookManager.Update(book);
             notification.shownot(book.BookName + " güncelleme işlemi başarılı");
         }
         detailType    = DetailType.Edit;
         book.Identity = bookManager.LastId;
         ChangesDetection();
     }
 }
        public ActionResult Add(Book book)
        {
            if (ModelState.IsValid)
            {
                string error = _bookManager.IsExists(book);
                if (error != "")
                {
                    ViewBag.FMsg = "Entry failed!! Same " + error + " Already exists";
                    return(View(book));
                }

                HttpPostedFileBase image = Request.Files["ImageData"];

                bool IsExecute = _bookManager.Add(book, image);

                if (IsExecute)
                {
                    return(RedirectToAction("Show"));
                }
                else
                {
                    return(View(book));
                }
            }

            return(View(book));
        }
        static async Task MainAsync(string[] args)
        {
            var manager = new BookManager();
            await manager.Add("CLR via PHP", "Jeffrey Richter", "Fantasy");

            var books = await manager.GetAll();

            foreach (var book in books)
            {
                foreach (var item in book)
                {
                    Console.Write($"{item} ");
                }
                Console.WriteLine();
            }

            //var book =

            //foreach (var item in book) {
            //    Console.WriteLine(item);
            //}


            //var client = new HttpClient();
            //var url = "http://xam150.azurewebsites.net/api/books";
            //client.DefaultRequestHeaders.Add("Authorization", "f3ae2a49-a398-496f-b4d0-068e9531dcda");
            //// f3ae2a49-a398-496f-b4d0-068e9531dcda

            //    Book book = new Book() {
            //        Title = "CLR via C#",
            //        Authors = new List<string>(new[] { "Jeffrey Richter" }),
            //        ISBN = string.Empty,
            //        Genre = "Fantasy",
            //        PublishDate = DateTime.Now.Date,
            //    };

            //    var response = await client.PostAsync(url,
            //        new StringContent(
            //            JsonConvert.SerializeObject(book),
            //            Encoding.UTF8, "application/json"));

            //    Console.WriteLine(JsonConvert.DeserializeObject<Book>(
            //        await response.Content.ReadAsStringAsync()));
            //}


            //var response = await client.GetAsync(url);
            //if (response.StatusCode == HttpStatusCode.OK) {
            //    var content = response.Content;
            //    var data = await content.ReadAsStringAsync();
            //    var books = JsonConvert.DeserializeObject<Book[]>(data);
            //    foreach (var item in books) {
            //        Console.WriteLine($"{item.Title} {item.Authors.FirstOrDefault()}\n");
            //    }
            //} else if (response.StatusCode == HttpStatusCode.Unauthorized) {
            //    Console.WriteLine("Shalom, you need to get new token");
            //} else {
            //    Console.WriteLine();
            //}
        }
Example #4
0
        async void OnDismiss(object sender, EventArgs e)
        {
            string title  = titleCell.Text;
            string author = authorCell.Text;
            string genre  = genreCell.Text;

            if (string.IsNullOrWhiteSpace(title) ||
                string.IsNullOrWhiteSpace(author) ||
                string.IsNullOrWhiteSpace(genre))
            {
                await this.DisplayAlert("Missing Information",
                                        "You must enter values for the Title, Author, and Genre.",
                                        "OK");
            }
            else
            {
                if (existingBook != null)
                {
                    existingBook.Title      = title;
                    existingBook.Genre      = genre;
                    existingBook.Authors[0] = author;

                    await manager.Update(existingBook);
                }
                else
                {
                    Book book = await manager.Add(title, author, genre);

                    books.Add(book);
                }

                await Navigation.PopModalAsync();
            }
        }
Example #5
0
        private static void TopluUrunEkleme(BookManager bookManager)
        {
            List <Book> books = new List <Book>
            {
                new Book {
                    CategoryId = 5, BookName = "Yeni Dünya", BookAuthor = "Sabahattin Ali", UnitPrice = 19, UnitInStock = 10, PublishingHouse = "YKY", BookPublishingHouseId = 5, BookTypeOfBookId = 1
                },
                new Book {
                    CategoryId = 4, BookName = "Satranç", BookAuthor = "Stefan Zwenıg", UnitPrice = 20, UnitInStock = 15, PublishingHouse = "Kırmızı Kedi", BookPublishingHouseId = 4, BookTypeOfBookId = 2
                },
                new Book {
                    CategoryId = 3, BookName = "İçimizdeki Şeytan", BookAuthor = "Sabahattin Ali", UnitPrice = 25, UnitInStock = 50, PublishingHouse = "YKY", BookPublishingHouseId = 5, BookTypeOfBookId = 3
                },
                new Book {
                    CategoryId = 2, BookName = "Milenya'ya Mektuplar", BookAuthor = "Franz Kafka", UnitPrice = 27, UnitInStock = 18, PublishingHouse = "MaviÇatı", BookPublishingHouseId = 3, BookTypeOfBookId = 4
                },
                new Book {
                    CategoryId = 1, BookName = "Şanzelize Düğün Salonu", BookAuthor = "Tarık Tufan", UnitPrice = 29, UnitInStock = 46, PublishingHouse = "Profil Kitap", BookPublishingHouseId = 2, BookTypeOfBookId = 5
                }
            };

            foreach (var book in books)
            {
                bookManager.Add(book);
            }
        }
        async void OnDismiss(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            button.IsEnabled = false;
            try
            {
                string title  = titleCell.Text;
                string author = authorCell.Text;
                string genre  = genreCell.Text;

                if (string.IsNullOrWhiteSpace(title) ||
                    string.IsNullOrWhiteSpace(author) ||
                    string.IsNullOrWhiteSpace(genre))
                {
                    await this.DisplayAlert("Missing Information",
                                            "You must enter values for the Title, Author, and Genre.",
                                            "OK");
                }
                else
                {
                    IsBusy = true;
                    if (existingBook != null)
                    {
                        existingBook.Title      = title;
                        existingBook.Genre      = genre;
                        existingBook.Authors[0] = author;

                        await manager.Update(existingBook);

                        int pos = books.IndexOf(existingBook);
                        books.RemoveAt(pos);
                        books.Insert(pos, existingBook);
                    }
                    else
                    {
                        var book = await manager.Add(title, author, genre);
                    }

                    await Navigation.PopModalAsync();
                }
            }
            catch (Exception ex)
            {
                await this.DisplayAlert("Error",
                                        ex.Message,
                                        "OK");
            }
            finally
            {
                IsBusy           = false;
                button.IsEnabled = true;
            }
        }
Example #7
0
 public ActionResult Create(BookInfo book, HttpPostedFileBase file)
 {
     if (_bManager.Add(book))
     {
         return(Content("<script>alert('添加成功!');location.href='/home/bookinfo'</script>"));
     }
     else
     {
         return(Content("<script>alert('添加失败!');location.href='/home/bookinfo'</script>"));
     }
 }
Example #8
0
        private void CreateBook(object sender, EventArgs e)
        {
            Book b = new Book()
            {
                Title       = titleText.Text,
                ISBN        = isbnText.Text,
                Description = descText.Text
            };

            bm.Add(b);
        }
Example #9
0
        private static void TekUrunEkleme(BookManager bookManager)
        {
            bookManager.Add(new Book {
                BookName = "İslam Tarihi-1", BookAuthor = "Adem Apak", PublishingHouse = "Ensar Yayınları", BookPublishingHouseId = 8, BookTypeOfBookId = 9, CategoryId = 5, UnitInStock = 12, UnitPrice = 29
            });

            foreach (var book in bookManager.GetAll())
            {
                Console.WriteLine(book.BookName);
            }
        }
Example #10
0
 public ActionResult Create(BookVm model)
 {
     if (ModelState.IsValid)
     {
         var  books  = Mapper.Map <Book>(model);
         bool isSave = _bookManager.Add(books);
         if (isSave)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View());
 }
 private void btnAddBook_Click(object sender, EventArgs e)
 {
     if ((tbxName.Text == "" || tbxAuthor.Text == "" || tbxPrice.Text == "" || tbxQuantity.Text == "" || dtpPublishDate?.Value == null))
     {
         MessageBox.Show(@"Please fill out inputs");
     }
     else
     {
         if (dtpPublishDate != null)
         {
             _bookManager.Add(new Book
             {
                 Name        = tbxName.Text,
                 Author      = tbxAuthor.Text,
                 PublishDate = dtpPublishDate.Value,
                 Price       = Convert.ToDecimal(tbxPrice.Text),
                 Quantity    = Convert.ToInt32(tbxQuantity.Text)
             });
         }
         ClearInputs();
         LoadBooks();
         MessageBox.Show(@"Book Successfully Added!");
     }
 }
Example #12
0
        public IActionResult AddEbookSubmit(Ebook ebook, IFormFile imgFile, IFormFile epub, IFormFile mobi)
        {
            if (HttpContext.Session.GetString("auth") != "true")
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("AddEbook"));
            }
            ImageManager imageManager = new ImageManager(environment, "images/covers/ebooks");
            FileManager  epubManager  = new FileManager(environment, "ebooks/epub");
            FileManager  mobiManager  = new FileManager(environment, "ebooks/mobi");
            int          result       = imageManager.uploadImage(imgFile);

            switch (result)
            {
            case 1:
                Console.WriteLine("\n\n\n*** Wrong File Type! ***");
                ViewData["feedback"] = "Wrong File Type";
                return(RedirectToAction("AddEbook"));

            case 2:
                Console.WriteLine("\n\n\n*** File Too Large! ***");
                ViewData["feedback"] = "File Too Large";
                return(RedirectToAction("AddEbook"));

            case 3:
                Console.WriteLine("\n\n\n*** File Name Too Long! ***");
                ViewData["feedback"] = "File Name Too Long";
                return(RedirectToAction("AddEbook"));

            case 4:
                Console.WriteLine("\n\n\n*** Error Saving File! ***");
                ViewData["feedback"] = "Error Saving File";
                return(RedirectToAction("AddEbook"));

            case 5:
                ViewData["feedback"] = "Success";
                ebook.imgFile        = imageManager.fileName;
                int epubResult = epubManager.uploadFile(epub);
                if (epubResult == 5)
                {
                    ebook.epub = epubManager.fileName;
                    int mobiResult = mobiManager.uploadFile(mobi);
                    if (mobiResult == 5)
                    {
                        ebook.mobi = mobiManager.fileName;
                        bookManager.Add(ebook);
                        bookManager.SaveChanges();
                        return(RedirectToAction("Ebooks"));
                    }
                    else
                    {
                        Console.WriteLine("\n\n\n***Error Adding MOBI! " + mobiResult + " ***");
                        return(RedirectToAction("AddEbook"));
                    }
                }
                else
                {
                    Console.WriteLine("\n\n\n***Error Adding ePub! " + epubResult + " ***");
                    return(RedirectToAction("AddEbook"));
                }

            default:
                Console.WriteLine("\n\n\n*** No File Selected! ***");
                ViewData["feedback"] = "No File Selected";
                return(RedirectToAction("AddEbook"));
            }
        }
        private async void AddBookButtonClicked(object sender, EventArgs e)
        {
            await bookManager.Add(TitleEntry.Text, DescriptionEntry.Text, ISBNEntry.Text);

            await Navigation.PushAsync(new MainPage());
        }
Example #14
0
 [ValidateInput(false)]//表示忽略过滤器
 public ActionResult Edit(Book book, HttpPostedFileBase cover)
 {
     if (ModelState.IsValid)
     {
         //检查标题与ISBN是否和重复
         if (IsExistsTitleAndISBN(book))
         {
             //重新获得下拉列表数据
             PrepareDropDownListData(book);
             return(View(book));
         }
         if (book.Id != 0)//修改
         {
             //如果上传文件失败
             if (!UploadFiles(book, cover))
             {
                 TempData["message"] = "修改图书失败";
                 //重新获得下拉列表数据
                 PrepareDropDownListData(book);
                 return(View(book));
             }
             try
             {
                 bm.Update(book);
                 TempData["message"] = "修改图书成功";
                 return(RedirectToAction("Index"));
             }
             catch (Exception)
             {
                 TempData["message"] = "修改图书失败";
                 //重新获得下拉列表数据
                 PrepareDropDownListData(book);
                 return(View(book));
             }
         }
         else//新增
         {
             if (UploadFiles(book, cover) && bm.Add(book) == 1)
             {
                 TempData["message"] = "添加图书成功";
                 string info = "<script>location.href=confirm('添加图书成功,是否继续添加图书?')?'" + Url.Action("Edit") + "':'" + Url.Action("Index") + "';</script>";
                 return(Content(info));
             }
             else
             {
                 TempData["message"] = "添加图书失败";
                 //重新获得下拉列表数据
                 PrepareDropDownListData(book);
                 return(View(book));
             }
         }
     }
     else
     {
         //给出版社与分类添加错误提示
         if (book.Categorie.Id == 0)
         {
             ModelState.AddModelError("Categorie", "请选择图书分类");
         }
         if (book.Publisher.Id == 0)
         {
             ModelState.AddModelError("Publisher", "请选择出版社");
         }
         //重新获得下拉列表数据
         PrepareDropDownListData(book);
         //判断标题、ISBN是否重复
         if (book != null)
         {
             IsExistsTitleAndISBN(book);
         }
         return(View(book));
     }
 }