コード例 #1
0
        //kitab elave etmek uchun metod

        public void AddBook()
        {
            try
            {
                Book book = new Book()
                {
                    Name       = txtBookname.Text,
                    Author     = txtBookAuthor.Text,
                    PageCount  = Convert.ToInt32(txtBookPage.Text),
                    Genre      = txtBookgenre.Text,
                    BookStatus = true
                };

                txtBookname.Clear();
                txtBookAuthor.Clear();
                txtBookPage.Clear();
                txtBookgenre.Clear();

                db.Books.Add(book);
                db.SaveChanges();
                FillBooks();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
コード例 #2
0
        public IHttpActionResult PutCategories(int id, Categories categories)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categories.category_id)
            {
                return(BadRequest());
            }

            db.Entry(categories).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoriesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public ActionResult Create(ManagersCooperativesViewModels managerCoop)
        {
            if (ModelState.IsValid && validForm(managerCoop))
            {
                // Si la coopérative existe, on ne l'ajoute pas en BD
                if (managerCoop.manager.IDCooperative == 0 || managerCoop.manager.IDCooperative == null)
                {
                    db.Cooperative.Add(managerCoop.cooperative);
                    db.SaveChanges();
                    managerCoop.manager.IDCooperative = managerCoop.cooperative.IDCooperative;
                }

                managerCoop.manager.ManagerPassword = UtilResources.EncryptPassword(Request.Form["password1"]);

                db.Manager.Add(managerCoop.manager);
                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", UtilResources.GetLabel("Tous les champs doivent contenir une valeur"));
            }
            return(View(managerCoop));
        }
コード例 #4
0
        public IHttpActionResult PutBorrowedBooks(int id, BorrowedBooks borrowedBooks)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != borrowedBooks.borrowed_book_id)
            {
                return(BadRequest());
            }

            db.Entry(borrowedBooks).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BorrowedBooksExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #5
0
        // user elave edilmesi
        public void AddUser()
        {
            try
            {
                User user = new User()
                {
                    Name    = txtUsername.Text,
                    Surname = txtUserSurname.Text,
                    Email   = txtUserEmail.Text,
                    Number  = Convert.ToInt32(txtUserNmb.Text)
                };

                txtUsername.Clear();
                txtUserSurname.Clear();
                txtUserEmail.Clear();
                txtUserNmb.Clear();

                db.Users.Add(user);
                db.SaveChanges();
                dgvUsers.Rows.Clear();
                FillUsers();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
コード例 #6
0
        public IHttpActionResult PutStock(int id, Stock stock)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != stock.stock_id)
            {
                return(BadRequest());
            }

            db.Entry(stock).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StockExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #7
0
ファイル: VoucherF.cs プロジェクト: zork1996/QuanLyThuVien
        public bool Insert(Voucher model)
        {
            Book bookEntry = db.Books.Where(x => x.ID == model.BookID).FirstOrDefault();

            bookEntry.Quantity = (int)bookEntry.Quantity - (int)model.Quantity;
            db.Vouchers.Add(model);
            db.SaveChanges();
            return(true);
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "Id,ISBN,Title,Author,Publisher,Category,Year_Released,Pages,Num_of_Copies,Shelf_Number")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "Id,P_Category,Name,ISBN,Volume_Number,Year,Page_Number,Shelf_Num")] Period period)
        {
            if (ModelState.IsValid)
            {
                db.Periods.Add(period);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(period));
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "Id,StudentID,L_Name,F_Name,Class")] Student student)
        {
            if (ModelState.IsValid)
            {
                TempData["StudId"] = student.StudentID;
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Create", "Users"));
            }

            return(View(student));
        }
コード例 #11
0
 private void btnupdate_Click(object sender, EventArgs e)
 {
     updatedstd.StudentName  = txtname.Text;
     updatedstd.SchoolNumber = txtnumber.Text;
     if (cmbdepartment.SelectedItem != null)
     {
         updatedstd.DepartmentID = service.DepartmentService.GetByCondition(x => x.DepartmentName == cmbdepartment.SelectedItem.ToString()).FirstOrDefault().ID;
     }
     db.SaveChanges();
     MessageBox.Show("Student Details Updated");
     dataGridView1.DataSource = service.StudentService.GetAll();
     clear();
 }
コード例 #12
0
        public bool Create(SpecialCategoryBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // check duplicated
                    var currentSpecialCategory = libraryDb.SpecialCategories.FirstOrDefault(s => s.Name == model.Name);
                    if (currentSpecialCategory != null)
                    {
                        throw new ArgumentNullException();
                    }
                    // Insert db
                    var specialCategoryInfo = _entityMapper.Map <SpecialCategoryBindingModel, SpecialCategory>(model);
                    libraryDb.SpecialCategories.Add(specialCategoryInfo);
                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #13
0
        public bool Update(BookBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var book = libraryDb.Books.FirstOrDefault(s => s.Id.Equals(model.Id));
                    if (book == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }
                    book.Name        = model.Name;
                    book.Language    = model.Language;
                    book.ReleaseYear = model.ReleaseYear;
                    book.PageCount   = model.PageCount;
                    //book.AuthorId = model.AuthorId;
                    //book.PublisherId = model.PulisherId;
                    book.Note  = model.Note;
                    book.Price = model.Price;
                    //book.CategoryId = model.CategoryId;
                    //book.SpecialCategoryId = model.SpecialCategoryId;
                    //book.BookShelfId = model.BookShelfId;

                    libraryDb.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #14
0
        public bool Create(BookBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // check duplicated
                    var currentBook = libraryDb.Books.FirstOrDefault(s => s.Id.Equals(model.Id));
                    if (currentBook != null)
                    {
                        throw new ArgumentNullException();
                    }
                    // Insert db
                    var bookInfo = _entityMapper.Map <BookBindingModel, Book>(model);
                    libraryDb.Books.Add(bookInfo);
                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #15
0
ファイル: BorrowerDAO.cs プロジェクト: dattoo730/LibraryD
        //add new borrower
        public bool AddBorrower(BorrowerDTO b)
        {
            using (LibraryManagementEntities entities = new LibraryManagementEntities())
            {
                Borrower b1 = new Borrower();

                b1.borrowerID        = b.BorrowerID;
                b1.borrowerName      = b.BorrowerName;
                b1.borrowerGender    = b.BorrowerGender;
                b1.borrowerPhone     = b.BorrowerPhone;
                b1.borrowerAddress   = b.BorrowerAddress;
                b1.borrowerEmail     = b.BorrowerEmail;
                b1.borrowerBirthDate = b.BorrowerBirthDate;

                entities.Borrowers.Add(b1);
                int ret = entities.SaveChanges();
                if (ret == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #16
0
        public bool Create(PublisherBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // check duplicated
                    var currentPublishers = libraryDb.Publishers.FirstOrDefault(s => s.Id == model.Id);
                    if (currentPublishers != null)
                    {
                        throw new ArgumentNullException();
                    }
                    // Insert db
                    var publishersInfo = _entityMapper.Map <PublisherBindingModel, Publisher>(model);
                    libraryDb.Publishers.Add(publishersInfo);
                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #17
0
        public bool InsertDetailOrder(List <DetailOrdersDTO> dto, int orderId)
        {
            var temp = db.OrderTbls.Find(orderId);

            if (temp != null)
            {
                if (dto != null)
                {
                    foreach (var i in dto)
                    {
                        DetailOrder dtop = new DetailOrder();
                        dtop.orderID          = orderId;
                        dtop.bookID           = i.BookId;
                        dtop.quantityBorrowed = i.QuantityBorrowed;
                        db.DetailOrders.Add(dtop);

                        Book b = db.Books.Find(i.BookId);
                        b.quantity       -= i.QuantityBorrowed;
                        db.Entry(b).State = EntityState.Modified;
                    }
                    db.SaveChanges();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #18
0
        public bool Update(BorrowerBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var borrower = libraryDb.Borrowers.FirstOrDefault(s => s.Id == model.Id);
                    if (borrower == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }

                    borrower.ReaderId   = model.ReaderId;
                    borrower.BookId     = model.BookId;
                    borrower.BorrowDate = model.BorrowDate;
                    borrower.PayDate    = model.PayDate;
                    borrower.Note       = model.Note;

                    libraryDb.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #19
0
        public bool Delete(string id)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var book = libraryDb.Books.FirstOrDefault(s => s.Id.Equals(id));
                    if (book == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }

                    libraryDb.Books.Remove(book);

                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #20
0
        public bool Delete(int id)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var reader = libraryDb.Readers.FirstOrDefault(s => s.Id == id);
                    if (reader == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }

                    libraryDb.Readers.Remove(reader);

                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #21
0
        public bool Create(ReaderBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // check duplicated
                    var readerAuthor = libraryDb.Readers.FirstOrDefault(s => s.Id == model.Id);
                    if (readerAuthor != null)
                    {
                        throw new ArgumentNullException();
                    }
                    // Insert db
                    var readerInfo = _entityMapper.Map <ReaderBindingModel, Reader>(model);
                    libraryDb.Readers.Add(readerInfo);
                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #22
0
        public bool Update(ReaderBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // Check first get item
                    var reader = libraryDb.Readers.FirstOrDefault(s => s.Id == model.Id);
                    if (reader == null)
                    {
                        throw new ArgumentNullException("No exist");
                    }
                    reader.Name        = model.Name;
                    reader.Gender      = model.Gender;
                    reader.Address     = model.Address;
                    reader.PhoneNumber = model.PhoneNumber;
                    reader.Email       = model.Email;
                    reader.DayOfBirth  = model.DayOfBirth;
                    //reader.PositionId = model.PositionId;
                    //reader.UnitId = model.UnitId;
                    reader.Note = model.Note;

                    libraryDb.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #23
0
        public bool Create(UnitBindingModel model)
        {
            try
            {
                using (var libraryDb = new LibraryManagementEntities())
                {
                    // check duplicated
                    var currentUnit = libraryDb.Units.FirstOrDefault(s => s.Name == model.Name);
                    if (currentUnit != null)
                    {
                        throw new ArgumentNullException();
                    }
                    // Insert db
                    var unitInfo = _entityMapper.Map <UnitBindingModel, Unit>(model);
                    libraryDb.Units.Add(unitInfo);
                    libraryDb.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #24
0
        public ActionResult Create([Bind(Include = "Id,User_Name,Password,Type,Date_Created,Created_by")] User user)
        {
            if (ModelState.IsValid)
            {
                user.User_Name    = TempData["StudId"] as string;
                user.Password     = EasyEncryption.SHA.ComputeSHA256Hash(user.Password);
                user.Type         = "Student";
                user.Date_Created = DateTime.Now;
                user.Created_by   = "Online Portal";
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Login"));
            }

            return(View(user));
        }
コード例 #25
0
        public ActionResult Create([Bind(Include = "IDStudent,FirstName,LastName,Email,PhoneNumber,StudentPassword")] Student student)
        {
            if (ModelState.IsValid && validForm())
            {
                student.StudentPassword = UtilResources.EncryptPassword(Request.Form["password1"]);


                db.Student.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", UtilResources.GetLabel("Tous les champs doivent contenir une valeur"));
            }
            return(View(student));
        }
コード例 #26
0
 private void btnupdate_Click(object sender, EventArgs e)
 {
     updatedbook.BookName = txtname.Text;
     updatedbook.Author   = txtauthor.Text;
     if (comboBox1.SelectedItem != null)
     {
         updatedbook.GenresID = service.GenresService.GetByCondition(x => x.CategoryName == comboBox1.SelectedItem.ToString()).FirstOrDefault().ID;
     }
     if (checkBox1.Checked)
     {
         updatedbook.Available = true;
     }
     else
     {
         updatedbook.Available = false;
     }
     db.SaveChanges();
     MessageBox.Show("Book Details Updated");
     dataGridView1.DataSource = service.BooksService.GetAll();
     clear();
 }
コード例 #27
0
        // PUT: odata/Users(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <User> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            User user = db.Users.Find(key);

            if (user == null)
            {
                return(NotFound());
            }

            patch.Put(user);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(user));
        }
コード例 #28
0
        //Yeni orderin yaradilmasi
        public void AddOrder()
        {
            try
            {
                Order order = new Order();
                Book  book  = (Book)cmbBooks.SelectedItem;
                User  user  = (User)cmbUsers.SelectedItem;


                //Order propertileri elave olunur
                order.User        = user;
                order.UserId      = user.Id;
                order.TakeDate    = DateTime.Now;
                order.Deadline    = DateTime.Now.AddMonths(1);
                order.DelayedDays = 0;
                order.Book        = book;
                order.BookId      = book.Id;
                order.FinePrice   = 0;


                //Kitab stokdan goturuldu
                book.BookStatus = false;



                db.Orders.Add(order);
                db.SaveChanges();

                dgvOrders.Rows.Clear();
                FillOrders();
            }
            catch (Exception exp)
            {
                MessageBox.Show("Something is wrong");
            }
        }
コード例 #29
0
 public bool AddBorrower(Borrower b)
 {
     using (LibraryManagementEntities entities = new LibraryManagementEntities())
     {
         entities.Borrowers.Add(b);
         int ret = entities.SaveChanges();
         if (ret == 1)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
コード例 #30
0
        public static void ChangeLanguageTwo()
        {
            LibraryManagementEntities db = new LibraryManagementEntities();
            Settings config = db.Settings.Single();

            if (config.IDLanguage == 1)
            {
                IDLanguage = 2;
            }
            else
            {
                IDLanguage = 1;
            }
            config.IDLanguage      = IDLanguage;
            db.Entry(config).State = EntityState.Modified;
            db.SaveChanges();
        }