protected void Submit(object sender, EventArgs e)
        {
            Customer newCustomer = new Customer()
            {
                FirstName = firstName.Text,
                LastName  = lastName.Text,
                Email     = email.Text,
                Phone     = phone.Text,
                JoinDate  = DateTime.UtcNow
            };

            try
            {
                using (LibraryEntities db = new LibraryEntities())
                {
                    db.Customers.Add(newCustomer);
                    db.SaveChanges();

                    firstName.Text = "";
                    lastName.Text  = "";
                    email.Text     = "";
                    phone.Text     = "";

                    status.Text = "Successfully added!";
                }
            }
            catch (IndexOutOfRangeException)
            {
                status.Text = "Additional unsucessful, please try again!";
            }
        }
        protected void searchButton_Click(object sender, EventArgs e)
        {
            String searchBy      = searchOption.SelectedValue;
            String searchKeyword = searchValue.Text;

            if (!validColumns.Contains(searchBy) || searchBy == "")
            {
                return; // Prevent sql injection
            }

            // Perform search
            using (LibraryEntities db = new LibraryEntities())
            {
                List <Customer> resultList;
                if (searchBy == "Id")
                {
                    resultList = db.Customers.SqlQuery("SELECT * FROM dbo.Customers WHERE Id = @keyword", new SqlParameter("keyword", searchKeyword)).ToList();
                }
                else
                {
                    resultList = db.Customers.SqlQuery("SELECT * FROM dbo.Customers WHERE " + searchBy + " LIKE '%'+@keyword+'%'",
                                                       new SqlParameter("keyword", searchKeyword)).ToList();
                }

                CustomersGridView.DataSource = resultList;
                CustomersGridView.DataBind();
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         //CustomersGridView.DataSource = db.Librarians.ToList();
         //CustomersGridView.DataBind();
     }
 }
示例#4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var db = new LibraryEntities())
            {
                if (DropDownList1.SelectedValue.Equals("Title"))
                {
                    var selectItems = db.Media.Where(x => x.Title.Contains(TextBox1.Text)).ToList();

                    GridView1.DataSource = selectItems;
                    GridView1.DataBind();
                }
            }
        }
示例#5
0
        protected void Logon_Click(object sender, EventArgs e)
        {
            String username = UserEmail.Text;
            String password = Password.Text;

            using (LibraryEntities db = new LibraryEntities())
            {
                var user = (from c in db.Customers
                            where c.Email.Equals(username, StringComparison.CurrentCultureIgnoreCase)
                            select c).FirstOrDefault();

                if (user != null)
                {
                    FormsAuthentication.RedirectFromLoginPage(user.Id.ToString(), true);
                }
                else
                {
                    Msg.Text = "Invalid username/password combination.";
                }
            }
        }
示例#6
0
        protected void Submit(object sender, EventArgs e)
        {
            Media newMedia = new Media()
            {
                Title       = title.Text,
                Author1     = author.Text,
                ISBN1       = isbn.Text,
                Year        = year.Text,
                Publisher   = publisher.Text,
                Genre       = genre.Text,
                Description = description.Text,
            };

            try
            {
                using (LibraryEntities db = new LibraryEntities())
                {
                    db.Media.Add(newMedia);
                    db.SaveChanges();

                    title.Text       = "";
                    author.Text      = "";
                    isbn.Text        = "";
                    year.Text        = "";
                    publisher.Text   = "";
                    genre.Text       = "";
                    description.Text = "";

                    status.Text = "Successfully added!";
                }
            }
            catch (IndexOutOfRangeException)
            {
                status.Text = "Additional unsucessful, please try again!";
            }
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int userId = Convert.ToInt32(Context.User.Identity.Name);

            using (LibraryEntities db = new LibraryEntities()){
                List <CheckedOut> checkOuts    = db.CheckedOuts.Include("Copy").Include("Copy.Medium").Where(co => co.CustomerId == userId).Select(co => co).ToList();
                List <Resevation> reservations = db.Resevations.Include("Copy").Include("Copy.Medium").Where(r => r.CustomerId == userId).Select(r => r).ToList();

                List <CheckedOut> checkedOutBooks = new List <CheckedOut>();
                List <CheckedOut> checkedOutAudio = new List <CheckedOut>();
                List <CheckedOut> checkedOutVideo = new List <CheckedOut>();

                foreach (CheckedOut checkedOut in checkOuts)
                {
                    if (checkedOut.Copy.Medium is Book)
                    {
                        checkedOutBooks.Add(checkedOut);
                    }
                    else if (checkedOut.Copy.Medium is Audio)
                    {
                        checkedOutAudio.Add(checkedOut);
                    }
                    else if (checkedOut.Copy.Medium is Video)
                    {
                        checkedOutVideo.Add(checkedOut);
                    }
                }

                CheckedOutBooksGridView.DataSource = checkedOutBooks;
                CheckedOutBooksGridView.DataBind();

                CheckedOutAudioGridView.DataSource = checkedOutAudio;
                CheckedOutAudioGridView.DataBind();

                CheckedOutVideoGridView.DataSource = checkedOutVideo;
                CheckedOutVideoGridView.DataBind();

                List <Resevation> reservedBooks = new List <Resevation>();
                List <Resevation> reservedAudio = new List <Resevation>();
                List <Resevation> reservedVideo = new List <Resevation>();

                foreach (Resevation reserved in reservations)
                {
                    if (reserved.Copy.Medium is Book)
                    {
                        reservedBooks.Add(reserved);
                    }
                    else if (reserved.Copy.Medium is Audio)
                    {
                        reservedAudio.Add(reserved);
                    }
                    else if (reserved.Copy.Medium is Video)
                    {
                        reservedVideo.Add(reserved);
                    }
                }


                ReservedBooksGridView.DataSource = reservedBooks;
                ReservedBooksGridView.DataBind();

                ReservedAudioGridView.DataSource = reservedAudio;
                ReservedAudioGridView.DataBind();

                ReservedVideoGridView.DataSource = reservedVideo;
                ReservedVideoGridView.DataBind();
            }
        }