コード例 #1
0
        protected void GrdBook_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int row     = int.Parse(e.CommandArgument.ToString());
            var issueId = int.Parse(GrdBook.Rows[row].Cells[0].Text.Trim());

            if (e.CommandName == "Submit")
            {
                using (DemoLibraryAppEntities context = new DemoLibraryAppEntities())
                {
                    LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;
                    var            issuedEntry = context.Issues.Where(x => x.IssueID == issueId).SingleOrDefault();
                    if (issuedEntry.ReturnDate == null)
                    {
                        issuedEntry.ReturnDate = DateTime.Now;
                        context.SaveChanges();
                        BindGrid();
                        Errorlabel.Text = " Submitted Successfully!";
                    }
                    else
                    {
                        Errorlabel.Text = "Already Submitted..!";
                    }
                }
            }
        }
コード例 #2
0
        protected void Insert(object sender, EventArgs e)
        {
            using (DemoLibraryAppEntities entities = new DemoLibraryAppEntities())
            {
                LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;
                Book           NewBook     = new Book
                {
                    Title     = txtNewTitle.Text,
                    Author    = txtAuthor.Text,
                    Category  = txtCategory.Text,
                    Year      = int.Parse(txtYear.Text),
                    Quantity  = int.Parse(txtQuantity.Text),
                    Available = int.Parse(txtQuantity.Text),

                    IsDeleted = 0,
                    CreatedBy = currentUser.Name
                };

                entities.Books.Add(NewBook);
                entities.SaveChanges();
            }

            this.BindGrid();
            txtAuthor.Text   = "";
            txtCategory.Text = "";
            txtYear.Text     = "";
            txtQuantity.Text = "";
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurrentUser"] != null)
            {
                LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;

                SignedInUser.Text = "Signed in as: " + currentUser.Name.ToString();
            }
        }
コード例 #4
0
 private void BindGrid()
 {
     using (DemoLibraryAppEntities entities = new DemoLibraryAppEntities())
     {
         LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;
         GrdBook.DataSource = (from t1 in entities.Issues
                               join t2 in entities.Books
                               on t1.BookID equals t2.BookID
                               select new { t1.IssueID, t1.UserID, currentUser.Name, t1.BookID, t2.Title, t2.Author, t1.IssueDate, t1.ReturnDate }).ToList();
         GrdBook.DataBind();
     }
 }
コード例 #5
0
 private void BindGrid()
 {
     using (DemoLibraryAppEntities entities = new DemoLibraryAppEntities())
     {
         LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;
         GrdBook.DataSource = (from t1 in entities.Issues
                               join t2 in entities.Books
                               on t1.BookID equals t2.BookID
                               where t1.UserID == currentUser.UserID
                               orderby t1.IssueDate descending
                               select t2).Take(5).ToList();
         GrdBook.DataBind();
     }
 }
コード例 #6
0
        protected void Login_Click(object sender, EventArgs e)
        {
            try
            {
                string uname = Username.Text;
                string pass  = Password.Text;

                using (DemoLibraryAppEntities context = new DemoLibraryAppEntities())
                {
                    var user = context.Users.FirstOrDefault(u => u.Username == uname);
                    if (user != null)
                    {
                        if (user.Password == pass)
                        {
                            Session["CurrentUser"] = user;
                            LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;
                            if (currentUser.UserRole == "User")
                            {
                                Response.Redirect("HomeUser.aspx");
                            }
                            else
                            {
                                Response.Redirect("BookDB.aspx");
                            }
                        }
                        else
                        {
                            Response.Redirect("Register.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("Register.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["CurrentUser"] != null)
                {
                    LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;

                    if (currentUser.UserRole == "User")
                    {
                    }
                    else
                    {
                        Response.Redirect("BookDB.aspx");
                    }
                }
                else
                {
                    Response.Redirect("Login.aspx");
                }
            }
        }
コード例 #8
0
        private bool IssueBook(int bookId)
        {
            int resultCount = 0;

            using (DemoLibraryAppEntities context = new DemoLibraryAppEntities())
            {
                LibraryDB.User currentUser = Session["CurrentUser"] as LibraryDB.User;
                Book           bookToIssue = context.Books.Where(x => x.BookID == bookId).SingleOrDefault();

                if (!IsAlreadyIssued(currentUser.UserID, bookId))
                {
                    bookToIssue.Issues.Add(new Issue
                    {
                        BookID    = bookToIssue.BookID,
                        UserID    = currentUser.UserID,
                        IssueDate = DateTime.Now
                    });
                    --bookToIssue.Available;
                    resultCount = context.SaveChanges();
                }
            }
            return(resultCount > 0);
        }