Exemple #1
0
        public IQueryable GetBooks()
        {
            var        _db   = new BCM.DAL.ApplicationDbContext();
            IQueryable query = _db.Books;

            return(query);
        }
Exemple #2
0
        //protected void AddBookButton_Click(object sender, EventArgs e)
        //{
        //    Boolean fileOK = false;
        //    String path = Server.MapPath("~/Catalog/Images/");
        //    if (BookImage.HasFile)
        //    {
        //        String fileExtension = System.IO.Path.GetExtension(BookImage.FileName).ToLower();
        //        String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
        //        for (int i = 0; i < allowedExtensions.Length; i++)
        //        {
        //            if (fileExtension == allowedExtensions[i])
        //            {
        //                fileOK = true;
        //            }
        //        }
        //    }

        //    if (fileOK)
        //    {
        //        try
        //        {
        //            // Save to Images folder.
        //            BookImage.PostedFile.SaveAs(path + BookImage.FileName);
        //            // Save to Images/Thumbs folder.
        //            BookImage.PostedFile.SaveAs(path + "Thumbs/" + BookImage.FileName);
        //        }
        //        catch (Exception ex)
        //        {
        //            LabelAddStatus.Text = ex.Message;
        //        }

        //        // Add product data to DB.
        //        AddBooks books = new AddBooks();
        //        bool addSuccess = books.AddBook(AddBookTitle.Text, AddBookNotes.Text,
        //            AddBookPrice.Text, DropDownAddCategory.SelectedValue, BookImage.FileName);
        //        if (addSuccess)
        //        {
        //            // Reload the page.
        //            string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
        //            Response.Redirect(pageUrl + "?BookAction=add");
        //        }
        //        else
        //        {
        //            LabelAddStatus.Text = "Unable to add new book to database.";
        //        }
        //    }
        //    else
        //    {
        //        LabelAddStatus.Text = "Unable to accept file type.";
        //    }
        //}

        public IQueryable GetCategories()
        {
            var        _db   = new BCM.DAL.ApplicationDbContext();
            IQueryable query = _db.Categories;

            return(query);
        }
        public void Delete(int bookID)
        {
            var _db = new BCM.DAL.ApplicationDbContext();

            //var item = new Book { ID = bookID };
            //_db.Entry(item).State = EntityState.Deleted;
            //try
            //{
            //    _db.SaveChanges();
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    ModelState.AddModelError("",
            //      String.Format("Item with id {0} no longer exists in the database.", bookID));
            //}

            var item = (from c in _db.Books where c.ID == bookID select c).FirstOrDefault();

            if (item != null)
            {
                _db.Books.Remove(item);
                _db.SaveChanges();

                // Reload the page.
                string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                Response.Redirect(pageUrl + "?BookAction=remove");
            }
            else
            {
                LabelRemoveStatus.Text = "Unable to locate book.";
            }
        }
        public static void createAdmin(BCM.DAL.ApplicationDbContext context)
        {
            IdentityResult IdRoleResult;
            IdentityResult IdUserResult;

            // Create a RoleStore object by using the ApplicationDbContext object.
            // The RoleStore is only allowed to contain IdentityRole objects.
            var roleStore = new RoleStore <IdentityRole>(context);

            // Create a RoleManager object that is only allowed to contain IdentityRole objects.
            // When creating the RoleManager object, you pass in (as a parameter) a new RoleStore object.
            var roleMgr = new RoleManager <IdentityRole>(roleStore);

            // Then, you create the "Administrator" role if it doesn't already exist.
            if (!roleMgr.RoleExists("Administrator"))
            {
                IdRoleResult = roleMgr.Create(new IdentityRole("Administrator"));
                if (!IdRoleResult.Succeeded)
                {
                    // Handle the error condition if there's a problem creating the RoleManager object.
                }
            }

            // Create a UserManager object based on the UserStore object and the ApplicationDbContext
            // object. Note that you can create new objects and use them as parameters in
            // a single line of code, rather than using multiple lines of code, as you did
            // for the RoleManager object.

            //var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            var userMgr = new ApplicationUserManager();
            var appUser = new ApplicationUser()
            {
                UserName = "******",
            };

            IdUserResult = userMgr.Create(appUser, "Passw0rd1");

            // If the new "Admin" user was successfully created,
            // add the "Admin" user to the "Administrator" role.
            if (IdUserResult.Succeeded)
            {
                IdUserResult = userMgr.AddToRole(appUser.Id, "Administrator");
                if (!IdUserResult.Succeeded)
                {
                    // Handle the error condition if there's a problem adding the user to the role.
                }
            }
            else
            {
                // Handle the error condition if there's a problem creating the new user.
            }
        }
        public IQueryable <Book> GetBooks([QueryString("id")] int?categoryId)
        {
            var _db = new BCM.DAL.ApplicationDbContext();
            IQueryable <Category> query = _db.Categories.Include("Books");

            if (categoryId.HasValue && categoryId > 1)
            {
                query = query.Where(c => c.ID == categoryId);
            }
            IQueryable <Book> books = (IQueryable <Book>)query.SelectMany(c => c.Books);

            return(books);
        }
Exemple #6
0
        public void formViewBookCreate_InsertItem()
        {
            var item = new BCM.Model.Book();

            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                // Save changes
                using (BCM.DAL.ApplicationDbContext db = new BCM.DAL.ApplicationDbContext())
                {
                    db.Books.Add(item);
                    db.SaveChanges();
                }
            }
        }
        public IQueryable <Book> GetBook([QueryString("bookID")] int?bookID)
        {
            var _db = new BCM.DAL.ApplicationDbContext();
            IQueryable <Book> query = _db.Books;

            if (bookID.HasValue && bookID > 0)
            {
                query = query.Where(b => b.ID == bookID);
            }
            else
            {
                query = null;
            }
            return(query);
        }
Exemple #8
0
        public void Create(/*[Control("CategoryDropDown")]*/ int?categoryId)
        {
            if (categoryId == null || categoryId == 0)
            {
                //ErrorLabel.Text = "Select a category before iserting a new book!";
                return;
            }

            var book = new Book();

            TryUpdateModel(book);

            var _db = new BCM.DAL.ApplicationDbContext();

            //book.Categories == _db.Categories.Find(categoryId);
            //book.Title =

            if (ModelState.IsValid)
            {
            }
        }
        public static bool createUserAndRole(BCM.DAL.ApplicationDbContext context)
        {
            var rm = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            IdentityResult ir = rm.Create(new IdentityRole("canEdit"));
            //var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
            var um   = new ApplicationUserManager();
            var user = new ApplicationUser()
            {
                UserName = "******",
            };

            ir = um.Create(user, "Passw0rd1");
            if (ir.Succeeded == false)
            {
                return(ir.Succeeded);
            }

            ir = um.AddToRole(user.Id, "canEdit");

            return(ir.Succeeded);
        }
Exemple #10
0
 public GenericRepository(BCM.DAL.ApplicationDbContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
Exemple #11
0
 public BookRepository(BCM.DAL.ApplicationDbContext context)
     : base(context)
 {
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Verify user has completed the checkout process.
                if ((string)Session["userCheckoutCompleted"] != "true")
                {
                    Session["userCheckoutCompleted"] = string.Empty;
                    Response.Redirect("CheckoutError.aspx?" + "Desc=Unvalidated%20Checkout.");
                }

                NVPAPICaller payPalCaller = new NVPAPICaller();

                string   retMsg             = "";
                string   token              = "";
                string   finalPaymentAmount = "";
                string   PayerID            = "";
                NVPCodec decoder            = new NVPCodec();

                token              = Session["token"].ToString();
                PayerID            = Session["payerId"].ToString();
                finalPaymentAmount = Session["payment_amt"].ToString();

                bool ret = payPalCaller.DoCheckoutPayment(finalPaymentAmount, token, PayerID, ref decoder, ref retMsg);
                if (ret)
                {
                    // Retrieve PayPal confirmation value.
                    string PaymentConfirmation = decoder["PAYMENTINFO_0_TRANSACTIONID"].ToString();
                    TransactionId.Text = PaymentConfirmation;


                    BCM.DAL.ApplicationDbContext _db = new BCM.DAL.ApplicationDbContext();
                    // Get the current order id.
                    int currentOrderId = -1;
                    if (((string)Session["currentOrderId"]) != string.Empty)
                    {
                        currentOrderId = Convert.ToInt32(Session["currentOrderID"]);
                    }
                    Order myCurrentOrder;
                    if (currentOrderId >= 0)
                    {
                        // Get the order based on order id.
                        myCurrentOrder = _db.Orders.Single(o => o.ID == currentOrderId);
                        // Update the order to reflect payment has been completed.
                        myCurrentOrder.PaymentTransactionId = PaymentConfirmation;
                        // Save to DB.
                        _db.SaveChanges();
                    }

                    // Clear shopping cart.
                    using (BCM.WebFormsApplication.BLL.ShoppingCartActions usersShoppingCart =
                               new BCM.WebFormsApplication.BLL.ShoppingCartActions())
                    {
                        usersShoppingCart.EmptyCart();
                    }

                    // Clear order id.
                    Session["currentOrderId"] = string.Empty;
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
Exemple #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NVPAPICaller payPalCaller = new NVPAPICaller();

                string   retMsg  = "";
                string   token   = "";
                string   PayerID = "";
                NVPCodec decoder = new NVPCodec();
                token = Session["token"].ToString();

                bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg);
                if (ret)
                {
                    Session["payerId"] = PayerID;

                    var myOrder = new Order();
                    myOrder.OrderDate  = Convert.ToDateTime(decoder["TIMESTAMP"].ToString());
                    myOrder.UserName   = User.Identity.Name;
                    myOrder.FirstName  = decoder["FIRSTNAME"].ToString();
                    myOrder.LastName   = decoder["LASTNAME"].ToString();
                    myOrder.Address    = decoder["SHIPTOSTREET"].ToString();
                    myOrder.City       = decoder["SHIPTOCITY"].ToString();
                    myOrder.State      = decoder["SHIPTOSTATE"].ToString();
                    myOrder.PostalCode = decoder["SHIPTOZIP"].ToString();
                    myOrder.Country    = decoder["SHIPTOCOUNTRYCODE"].ToString();
                    myOrder.Email      = decoder["EMAIL"].ToString();
                    myOrder.Total      = Convert.ToDecimal(decoder["AMT"].ToString());

                    // Verify total payment amount as set on CheckoutStart.aspx.
                    try
                    {
                        decimal paymentAmountOnCheckout = Convert.ToDecimal(Session["payment_amt"].ToString());
                        decimal paymentAmoutFromPayPal  = Convert.ToDecimal(decoder["AMT"].ToString());
                        if (paymentAmountOnCheckout != paymentAmoutFromPayPal)
                        {
                            Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Redirect("CheckoutError.aspx?" + "Desc=Amount%20total%20mismatch.");
                    }

                    // Get DB context.
                    BCM.DAL.ApplicationDbContext _db = new BCM.DAL.ApplicationDbContext();

                    // Add order to DB.
                    _db.Orders.Add(myOrder);
                    _db.SaveChanges();

                    // Get the shopping cart items and process them.
                    using (BCM.WebFormsApplication.BLL.ShoppingCartActions usersShoppingCart = new BCM.WebFormsApplication.BLL.ShoppingCartActions())
                    {
                        List <CartItem> myOrderList = usersShoppingCart.GetCartItems();

                        // Add OrderDetail information to the DB for each product purchased.
                        for (int i = 0; i < myOrderList.Count; i++)
                        {
                            // Create a new OrderDetail object.
                            var myOrderDetail = new OrderDetail();
                            myOrderDetail.OrderId   = myOrder.ID;
                            myOrderDetail.UserName  = User.Identity.Name;
                            myOrderDetail.BookId    = myOrderList[i].BookId;
                            myOrderDetail.Quantity  = myOrderList[i].Quantity;
                            myOrderDetail.ListPrice = myOrderList[i].Book.ListPrice;

                            // Add OrderDetail to DB.
                            _db.OrderDetails.Add(myOrderDetail);
                            _db.SaveChanges();
                        }

                        // Set OrderId.
                        Session["currentOrderId"] = myOrder.ID;

                        // Display Order information.
                        List <Order> orderList = new List <Order>();
                        orderList.Add(myOrder);
                        ShipInfo.DataSource = orderList;
                        ShipInfo.DataBind();

                        // Display OrderDetails.
                        OrderItemList.DataSource = myOrderList;
                        OrderItemList.DataBind();
                    }
                }
                else
                {
                    Response.Redirect("CheckoutError.aspx?" + retMsg);
                }
            }
        }
Exemple #14
0
 public CategoryRepository(BCM.DAL.ApplicationDbContext context)
     : base(context)
 {
 }