public ActionResult Create([Bind(Include = "l_id,l_name,l_password")] Librarian librarian) { if (ModelState.IsValid) { db.Librarians.Add(librarian); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(librarian)); }
public ActionResult Create([Bind(Include = "editorial_id,editorial_nombre")] Editorial editorial) { if (ModelState.IsValid) { db.Editorials.Add(editorial); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(editorial)); }
public ActionResult Create([Bind(Include = "administrador_id,administrador_nombre,administrador_usuario,administrador_password,administrador_email")] Administrador administrador) { if (ModelState.IsValid) { db.Administradors.Add(administrador); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(administrador)); }
public ActionResult Create([Bind(Include = "ejemplar_id,ejemplar_numero,ejemplar_estado,libro_id")] Ejemplar ejemplar) { if (ModelState.IsValid) { db.Ejemplars.Add(ejemplar); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.libro_id = new SelectList(db.Libroes, "libro_id", "libro_nombre", ejemplar.libro_id); return(View(ejemplar)); }
public ActionResult Create([Bind(Include = "BookId,BookTitle,SerialNumber,CategoryId")] Book book) { if (ModelState.IsValid) { db.Book.Add(book); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(db.Category, "CategoryId", "CategoryName", book.CategoryId); return(View(book)); }
public ActionResult Create([Bind(Include = "cliente_id,cliente_name,cliente_cedula,cliente_telefono,ciudad_id")] Cliente cliente) { if (ModelState.IsValid) { db.Clientes.Add(cliente); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ciudad_id = new SelectList(db.Ciudads, "ciudad_id", "ciudad_nombre", cliente.ciudad_id); return(View(cliente)); }
public ActionResult Create([Bind(Include = "prestamo_id,prestamo_fecha_desde,prestamo_fecha_hasta,prestamo_fecha_entrega,prestamo_estado_devolucion,prestamo_estado,cliente_id")] Prestamo prestamo) { if (ModelState.IsValid) { db.Prestamoes.Add(prestamo); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.cliente_id = new SelectList(db.Clientes, "cliente_id", "cliente_name", prestamo.cliente_id); return(View(prestamo)); }
public ActionResult Create([Bind(Include = "proveedor_id,proveedor_nombre,proveedor_telefono,proveedor_direccion,ciudad_id")] Proveedor proveedor) { if (ModelState.IsValid) { db.Proveedors.Add(proveedor); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ciudad_id = new SelectList(db.Ciudads, "ciudad_id", "ciudad_nombre", proveedor.ciudad_id); return(View(proveedor)); }
public ActionResult AddUser(TBLUser p) { db.TBLUser.Add(p); var loc = db.Libraries.Where(a => a.LibrariesID == p.Libraries.LibrariesID).FirstOrDefault(); p.Libraries = loc; db.SaveChanges(); return(View("Index")); }
public ActionResult Add(StaffAccount staff) { if (ModelState.IsValid) { //encrypt password staff.Password = Password.Encrypt(staff.Password); _db.StaffAccounts.Add(staff); _db.SaveChanges(); TempData["message"] = $"Add Staff successfully!"; return(RedirectToAction("Index", new { key = staff.Username })); } return(View()); }
public ActionResult Create([Bind(Include = "eje_prestamo_id,ejemplar_id,prestamo_id")] EjemplarPrestamo ejemplarPrestamo) { if (ModelState.IsValid) { db.EjemplarPrestamoes.Add(ejemplarPrestamo); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ejemplar_id = new SelectList(db.Ejemplars, "ejemplar_id", "ejemplar_numero", ejemplarPrestamo.ejemplar_id); ViewBag.prestamo_id = new SelectList(db.Prestamoes, "prestamo_id", "prestamo_estado_devolucion", ejemplarPrestamo.prestamo_id); return(View(ejemplarPrestamo)); }
public ActionResult Create([Bind(Include = "BookID,PublisherID,Pages")] BookCopy bookCopy) { if (ModelState.IsValid) { db.BookCopies.Add(bookCopy); db.SaveChanges(); return(RedirectToAction("Details", "Books", new { id = bookCopy.BookID })); } ViewBag.BookID = new SelectList(db.Books, "BookID", "Name", bookCopy.BookID); ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "Name", bookCopy.PublisherID); return(View(bookCopy)); }
public ActionResult Create([Bind(Include = "BorrowHistoryId,BookId,CustomerId,BorrowDate,ReturnDate")] BorrowHistory borrowHistory) { if (ModelState.IsValid) { db.BorrowHistory.Add(borrowHistory); db.SaveChanges(); return(RedirectToAction("Index", "Book")); } ViewBag.CustomerId = new SelectList(db.Customer, "CustomerId", "Name", borrowHistory.CustomerId); borrowHistory.Book = db.Book.Find(borrowHistory.BookId); return(View(borrowHistory)); }
// Check if the book parameters are correct or not, and the add the book to database, and bring it to the DgvBooks private void BtnAddBook_Click(object sender, EventArgs e) { // Check for empty places if (string.IsNullOrEmpty(TxtBookName.Text) || CmbAuthors.SelectedIndex == -1) { MessageBox.Show("Kitab və müəllif adı boş ola bilməz"); return; } // Take the selected author: int SelectedAuthorId = Convert.ToInt32(CmbAuthors.SelectedItem.ToString().Split('-')[0]); // Check if the book exists or not if (db.Books.Any(b => b.Name == TxtBookName.Text && b.AuthorId == SelectedAuthorId)) { MessageBox.Show("Bu kitab artıq mövcuddur. Əlavə etmək üçün sayını artıra bilərsiniz..."); return; } Book book = new Book { Name = TxtBookName.Text, AuthorId = SelectedAuthorId, Price = NumPrice.Value, Count = Convert.ToInt32(NumCount.Value) }; //Second method to check: //ValidationContext context = new ValidationContext(book); //var list = new List<ValidationResult>(); //bool isValid = Validator.TryValidateObject(book, context, list); //if (isValid) //{ // MessageBox.Show("valid"); // return; //} //else //{ // foreach (var item in list) // { // label6.Text += item.ErrorMessage; // } // return; //} db.Books.Add(book); db.SaveChanges(); DgvBooks.Rows.Add(book.Id, book.AuthorId, book.Name, book.Author.Name, book.Price, "0/" + book.Count); MessageBox.Show("Kitab əlavə olundu!"); Reset(); }
public ActionResult Add(Book book) { if (ModelState.IsValid) { book = uploadImage(book); _db.Books.Add(book); _db.SaveChanges(); ModelState.Clear(); TempData["message"] = $"Add book successfully!"; return(RedirectToAction("Index", new { key = book.ID + " " })); } book.AvailableAuthors = getAuthors(); book.AvailableCategories = getCategories(); return(View(book)); }
public ActionResult Create([Bind(Include = "libro_id,libro_nombre,libro_fecha,libro_precio,proveedor_id,editorial_id,autor_id,genero_id")] Libro libro) { if (ModelState.IsValid) { db.Libroes.Add(libro); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.autor_id = new SelectList(db.Autors, "autor_id", "autor_nombre", libro.autor_id); ViewBag.editorial_id = new SelectList(db.Editorials, "editorial_id", "editorial_nombre", libro.editorial_id); ViewBag.genero_id = new SelectList(db.Generoes, "genero_id", "genero_nombre", libro.genero_id); ViewBag.proveedor_id = new SelectList(db.Proveedors, "proveedor_id", "proveedor_nombre", libro.proveedor_id); return(View(libro)); }
public ActionResult AddBook(TBLBook p) { var book = db.TBLCategory.Where(k => k.CategoryID == p.TBLCategory.CategoryID).FirstOrDefault(); var aut = db.TblAuthor.Where(a => a.authorID == p.TblAuthor.authorID).FirstOrDefault(); var loc = db.Libraries.Where(a => a.LibrariesID == p.Libraries.LibrariesID).FirstOrDefault(); p.TBLCategory = book; p.TblAuthor = aut; p.Libraries = loc; db.TBLBook.Add(p); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Add New Book Loan Touple to Database And Fines. /// </summary> /// <param name="bookId">Book Id</param> /// <param name="branchId">Branch Id</param> /// <param name="cardNumber">Card Number</param> /// <param name="dateOut">Date Out</param> /// <param name="dueDate">Due Date</param> public bool AddNewBookLoanAndFines(string bookId, int branchId, int cardNumber, DateTime dateOut, DateTime dueDate) { tblBOOK_LOANS bookLoans; tblFINE fines; bool result; int newLoanId; try { using (LibraryEntities entity = new LibraryEntities()) { #region Add New Book Loans bookLoans = new tblBOOK_LOANS(); bookLoans.Book_id = bookId.Trim(); bookLoans.Branch_id = branchId; bookLoans.Card_no = cardNumber; bookLoans.Date_out = dateOut; bookLoans.Due_date = dueDate; entity.AddTotblBOOK_LOANS(bookLoans); entity.SaveChanges(); newLoanId = (from latest in entity.tblBOOK_LOANS where latest.Book_id == bookId.Trim() && latest.Branch_id == branchId && latest.Card_no == cardNumber select latest.Loan_id).FirstOrDefault(); #endregion #region Add New Fines fines = new tblFINE(); fines.Book_id = bookId.Trim(); fines.Loan_id = newLoanId; fines.paid = true; fines.Fine_amount = 0; fines.Branch_id = branchId; entity.AddTotblFINES(fines); entity.SaveChanges(); #endregion result = true; } return(result); } catch (Exception e) { result = false; return(result); // Exception In Entity } }
// Decide what to do when the selected conditions are applied... private void BtnEndReservation_Click(object sender, EventArgs e) { if (CmbBookStatus.SelectedIndex == -1 || (RbtnGiveChance.Checked && NumLimitToReturn.Value == 0) || (RbtnSetPayment.Checked && NumPenalty.Value == 0) || string.IsNullOrEmpty(TxtComment.Text)) { MessageBox.Show("Boş sahə buraxmayın!"); return; } Reservation.Penalty = NumPenalty.Value; Reservation.BookStatus = Convert.ToInt32(CmbBookStatus.SelectedItem.ToString().Split('-')[0]); Reservation.Comment = TxtComment.Text; Reservation.TakenBackBy = User.Id; if (NumLimitToReturn.Value != 0) { Reservation.LimitToReturn = Convert.ToInt32(NumLimitToReturn.Value); } else { Reservation.TakenBackAt = DateTime.Now; } db.SaveChanges(); MessageBox.Show("Kitab qaytarıldı..."); if (Reservations != null) { Reservations.DgvReservations.Rows[Reservations.ClickedRow].Cells[8].Value = User.Name + " " + User.Surname; Reservations.DgvReservations.Rows[Reservations.ClickedRow].Cells[9].Value = Reservation.TakenBackAt?.ToString("dd.MM.yyyy"); Reservations.DgvReservations.Rows[Reservations.ClickedRow].Cells[10].Value = Reservation.Penalty?.ToString("0.00") + " AZN"; Reservations.DgvReservations.Rows[Reservations.ClickedRow].Cells[11].Value = Reservation.Case.Status; } if (MainBoard != null) { MainBoard.CreateLateBooksPanels(); } this.Close(); }
private void buttonReserve_Click(object sender, EventArgs e) { LibraryEntities context = new LibraryEntities(); List<int> books = new List<int>(); foreach (DataGridViewRow row in dataGridViewBooks.SelectedRows) { if (row.Cells[0].Value != null) { books.Add(Convert.ToInt32(row.Cells[0].Value)); } } if (books.Count > 0) { var client = (from c in context.Clients where c.ClientID == id select c).SingleOrDefault(); foreach (LibraryReader.ClientsBook cBook in client.ClientsBooks) { if (books.Contains(cBook.BookID)) { cBook.Reservation = true; MessageBox.Show("Резервирането е успешно!"); } } context.SaveChanges(); } }
public bool Update(ref Subscriber subscriber) { Trace.WriteLine(subscriber.ToObjectString()); if (subscriber == null || string.IsNullOrEmpty(subscriber.Email)) { return(false); } using (LibraryEntities context = new LibraryEntities("name=" + GlobalCache.GetResolvedString("DatabaseConfiguration"))) { string email = subscriber.Email.ToLower(); var currentSubscriber = context.Subscribers .FirstOrDefault(s => s.Email.ToLower() == email); if (currentSubscriber == null) { return(false); } currentSubscriber.Email = subscriber.Email; currentSubscriber.Name = subscriber.Name; currentSubscriber.Address = subscriber.Address; currentSubscriber.City = subscriber.City; currentSubscriber.State = subscriber.State; currentSubscriber.PostalCode = subscriber.PostalCode; return(context.SaveChanges() > 0); } }
public bool Checkin(string isbn, DateTime checkedout, out DateTime?checkedin) { bool result = false; checkedin = null; using (LibraryEntities context = new LibraryEntities("name=" + GlobalCache.GetResolvedString("DatabaseConfiguration"))) { var book = context.Books .Where(b => (b.ISBN == isbn)) .FirstOrDefault(); if (book == null) { return(false); } Checkout checkout = context.Checkouts .Where(bc => bc.DateOut == checkedout && bc.DateIn == null && bc.ISBN == isbn) .FirstOrDefault(); if (checkout == null) { return(false); } checkout.DateIn = checkedin = DateTime.UtcNow; result = (context.SaveChanges() > 0); } return(result); }
// POST api/albums public void Post([FromBody] Album album) { LibraryEntities context = new LibraryEntities(); context.Albums.Add(album); context.SaveChanges(); }
private void DecrementBook(ListBookClass book) { Book decrementBook = _db.Books.Where(bk => bk.Id == book.Id).First(); decrementBook.Count = decrementBook.Count - book.Count; _db.SaveChanges(); }
public ActionResult BookReturned(int bookId) { using (LibraryEntities db = new LibraryEntities()) { if (ModelState.IsValid) { /*UPDATE DATA MODEL SO TRANSACTION HOLDS BORROW AND RETURN FIELDS COPY ONLY FOR COPY ID ISBN AND Y/N BORRED OR NOT*/ int cuID = Int32.Parse(Session["custID"].ToString()); var returnQuery = from c in db.Copies join t in db.Transactions on c.CopyID equals t.CopyID where c.CopyID == t.CopyID && c.Isbn == bookId && t.CustID == cuID select c; foreach (Copy cp in returnQuery.ToList()) { cp.Borrow_Date = null; cp.Return_Date = null; cp.Borrowed = "n"; db.SaveChanges(); if (cp.Borrowed == "n") { TempData["returnMessage"] = "Book Returned"; return(RedirectToAction("UserArea")); } } } //end model state if ModelState.Clear(); } return(RedirectToAction("UserArea")); }
public ActionResult NewTemporaryPassword(string user) { using (var db = new LibraryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { Login targetLogin = db.Logins.Where(x => x.Username == user).SingleOrDefault(); if (targetLogin == null) { return(notification.ResetPasswordUserNotFound()); } var newTempPassword = GenerateTemporaryPassword(); targetLogin.PasswordHash = HashString(newTempPassword); targetLogin.IsPasswordTemporary = true; db.SaveChanges(); transaction.Commit(); return(notification.ResetPasswordSuccess(newTempPassword)); } catch { transaction.Rollback(); return(notification.UnknownError()); } } } }
public ActionResult UpdatePassword(string passwordHash) { using (var db = new LibraryEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var activeAccount = (AccountAdapter)System.Web.HttpContext.Current.Session["activeAccount"]; Login userLogin = db.Logins.Where(x => x.AccountId == activeAccount.AccountNumber).SingleOrDefault(); userLogin.PasswordHash = passwordHash; userLogin.IsPasswordTemporary = false; db.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); return(new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError)); } } } return(RedirectToAction("Home")); }
public Boolean authorize(String login, String password) { MD5 algoritm = MD5.Create(); password = GetMd5Hash(algoritm, password); Admin admin = context.Admin.Where(a => a.Login == login).FirstOrDefault <Admin>(); if (admin == null) { return(false); } else { if (admin.Password.Equals(password)) { admin.Last_login = System.DateTime.Now; AdminService.actualAdmin = admin; context.SaveChanges(); return(true); } else { return(false); } } }
public ActionResult Registration(Reg) { if (ModelState.IsValid) { User user = null; using (LibraryEntities db = new LibraryEntities()) { user = db.User.FirstOrDefault(u => u.Email == db.User); } if (user == null) { using (LibraryEntities db = new LibraryEntities()) { db.userAccount.Add(new User { Email = db.Email, Password = db.Password, Name = db.UserName }); db.SaveChanges(); //user = db.userAccount.Where(u => u.Email == db.Email && u.Password == db.Password).FirstOrDefault(); } if (user != null) { FormsAuthentication.SetAuthCookie(db.Email, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(model)); }
public ActionResult BookSuggestions([Bind(Include = "CustID,Name,AuthName,Isbn,Subject,Year,Type")] ReqStudent reqObj) { Debug.WriteLine("FUUCCKKK"); int cID = Int32.Parse(Session["custID"].ToString()); using (LibraryEntities db = new LibraryEntities()) { // Add books. if (ModelState.IsValid) { reqObj.CustID = cID; reqObj.Type = "Book"; reqObj.ReqConfirmation = "Pending"; db.ReqStudents.Add(reqObj); try { db.SaveChanges(); TempData["reqSent"] = "Request Sent"; return(RedirectToAction("UserArea")); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } ModelState.Clear(); } } //end ModelStateif return(View()); } //end ActionResult
// POST api/artists public void Post([FromBody] Artist artist) { LibraryEntities context = new LibraryEntities(); context.Artists.Add(artist); context.SaveChanges(); }