Example #1
0
        protected void ButtonSubmit_Click(object sender, System.EventArgs e)
        {
            string email = TextboxEmail.Text.Trim();
            string password = TextboxPassword.Text.Trim();

            var service = new Service();

            if (service.Login(email, password))
            {
                string redirectUrl = FormsAuthentication.GetRedirectUrl(email, false);
                if (redirectUrl != null && redirectUrl.IndexOf("admin") >= 0)
                    FormsAuthentication.RedirectFromLoginPage(email, false);
                else
                    Response.Redirect(UrlMaker.ToAdmin()); 
            }
            else
            {
                if (Tries >= 5)
                    Response.Redirect(UrlMaker.ToDefault());
                else
                {
                    Tries += 1;
                    this.LiteralError.Text = "Invalid Username or Password. Please try again.";
                }
            }
        }
Example #2
0
        protected void Application_Start()
        {
            // initializes the SimpleMembership system and creates the 4 membership tables if they do not already exist
            // Action is the connectionstring name. Member is user table name. MemberId is user Identity. Email is used as UserName.

            WebSecurity.InitializeDatabaseConnection("Action", "Member", "MemberId", "Email", autoCreateTables: true);

            // create the two roles in the app if they to not already exist

            if (!Roles.RoleExists("Admin")) Roles.CreateRole("Admin");
            if (!Roles.RoleExists("Member")) Roles.CreateRole("Member");
            
            // get member and create potentially first admin

            var member = new Service().GetMemberByEmail("*****@*****.**");
            if (WebSecurity.GetCreateDate(member.Email) == DateTime.MinValue) 
            {
                var email = "*****@*****.**";
                WebSecurity.CreateAccount(email, "secret123");
                Roles.AddUserToRole(email, "Admin");
            }

            // standard MVC 4.5 registrations

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
        }
Example #3
0
        static void Main()
        {
            var service = new Service();
            var member = service.GetMember(3);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());
        }
Example #4
0
        // saves data for new or edited member to database.
        
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            var service = new Service();

            var member  = (MemberId == 0) ? new BusinessObjects.Member() : service.GetMember(MemberId);

            // get email name from page

            var row = DetailsViewMember.Rows[1];
            var textBox = row.Cells[1].Controls[0] as TextBox;
            member.Email = textBox.Text.Trim();

            // get Company name from page.

            row = DetailsViewMember.Rows[2];
            textBox = row.Cells[1].Controls[0] as TextBox;
            member.CompanyName = textBox.Text.Trim();

            // get City from page

            row = DetailsViewMember.Rows[3];
            textBox = row.Cells[1].Controls[0] as TextBox;
            member.City = textBox.Text.Trim();

            // get Country from page

            row = DetailsViewMember.Rows[4];
            textBox = row.Cells[1].Controls[0] as TextBox;
            member.Country = textBox.Text.Trim();

            // validate using business rules engine

            if (member.IsValid())
            {
                if (MemberId == 0)
                {
                    service.InsertMember(member);
                    Session["message"] = "New member successfully added";
                }
                else
                {
                    service.UpdateMember(member);
                    Session["message"] = "Member successfully updated";
                }
            }
            else
            {
                LabelError.Text = member.Errors.Aggregate((current, next) => current + "</br>" + next);
                PanelError.Visible = true;
                return;
            }

            // return to list of members

            Response.Redirect(UrlMaker.ToMembers());
        }
Example #5
0
        // sets datasources and bind data. 
        
        private void Bind()
        {
            var service = new Service();
            GridViewMembers.DataSource = service.GetMembers(SortExpression);
            GridViewMembers.DataBind();

            // display potential add or update message
            if (Session["message"] != null)
            {
                LabelError.Text = Session["message"].ToString();
                Session["message"] = null;
            }
        }
Example #6
0
        // sets datasources and bind data to controls.
        
        private void Bind()
        {
            // validate selected CategoryId

            int categoryId;
            if (!int.TryParse(DropDownListCategories.SelectedValue, out categoryId))
                categoryId = 1;

            // gets list of products

            var service = new Service();
            GridViewProducts.DataSource = service.GetProductsByCategory(categoryId, SortExpression);
            GridViewProducts.DataBind();
        }
Example #7
0
        // sets datasources and bind data to controls.
        
        private void Bind()
        {
            // get member 

            var service = new Service();
            var member = service.GetMember(MemberId);

            // set company name

            LabelHeader.Text = "<font color='black'>Orders for:</font> "
                + member.CompanyName + " (" + member.Country + ")";

            GridViewOrders.DataSource = service.GetOrdersByMember(MemberId);
            GridViewOrders.DataBind();
        }
Example #8
0
        void Application_Start(object sender, EventArgs e)
        {
            // initializes the SimpleMembership system and creates the 4 membership tables if they do not already exist
            // Action is the connectionstring name. Member is user table name. MemberId is user Identity. Email is used as UserName.

            WebSecurity.InitializeDatabaseConnection("Action", "Member", "MemberId", "Email", autoCreateTables: true);

            // create the two roles in the app if they to not already exist

            if (!Roles.RoleExists("Admin")) Roles.CreateRole("Admin");
            if (!Roles.RoleExists("Member")) Roles.CreateRole("Member");

            // get member and create potentially first admin

            var member = new Service().GetMemberByEmail("*****@*****.**");
            if (WebSecurity.GetCreateDate(member.Email) == DateTime.MinValue)
            {
                var email = "*****@*****.**";
                WebSecurity.CreateAccount(email, "secret123");
                Roles.AddUserToRole(email, "Admin");
            }

            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();

            // initialize routing system

            RegisterRoutes(RouteTable.Routes);

            // initialize sitemap facility

            InitializeSiteMapResolver();

            // initialize logging facility

            InitializeLogger();
        }
Example #9
0
        // sets datasources and bind data to controls.
        
        private void Bind()
        {
            var service = new Service();
            var order = service.GetOrder(orderId);

            // sets the date

            LabelHeader.Text = "Order Line Items";
            LabelOrderDate.Text = "Order date: " + order.OrderDate.ToShortDateString();
            HyperLinkBack.Text = "< back to orders ";


            var orderDetails = service.GetOrderDetails(orderId);
            foreach (var detail in orderDetails)
            {
                // caching products would be more effective. however, # of details is usually fairly small.

                var product = service.GetProduct(detail.ProductId);
                detail.ProductName = product.ProductName;
            }

            GridViewOrderDetails.DataSource = orderDetails;
            GridViewOrderDetails.DataBind();
        }
Example #10
0
        // takes search criteria, sets datasource, and bind data to controls.

        private void Bind()
        {
            // validate price range

            int priceRangeId;
            if (!int.TryParse(DropDownListRange.SelectedValue, out priceRangeId))
                priceRangeId = 0;

            // get product name entered

            string productName = this.TextBoxProductName.Text.Trim();

            // retrieve list of products.

            var service = new Service();

            double priceFrom = new PriceRange().GetList()[priceRangeId].RangeFrom;
            double priceThru = new PriceRange().GetList()[priceRangeId].RangeThru;
            if (priceThru == 0) priceThru = 5000;  // in case no range is set
            GridViewProducts.DataSource = service.SearchProducts(productName, priceFrom, priceThru, SortExpression);
            GridViewProducts.DataBind();

            PanelSearchResults.Visible = true;
        }
Example #11
0
 // sets datasources and bind data to controls.
 
 private void Bind()
 {
     var service = new Service();
     GridViewOrders.DataSource = service.GetMembersWithOrderStatistics(SortExpression);
     GridViewOrders.DataBind();
 }
Example #12
0
 // performs logout operation.
 
 protected void Page_Load(object sender, EventArgs e)
 {
     var service = new Service();
     service.Logout();
 }
Example #13
0
        // deletes member record
        
        protected void GridViewMembers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var row = GridViewMembers.Rows[e.RowIndex];
            int memberId = int.Parse(row.Cells[0].Text);

            var service = new Service();

            // member with orders cannot be deleted

            var orders = service.GetOrdersByMember(memberId);
            if (orders.Count > 0)
            {
                string memberName = row.Cells[1].Text;
                LabelError.Text = "Cannot delete " + memberName + " because they have existing orders!";
            }
            else
            {
                var member = service.GetMember(memberId);
                service.DeleteMember(member);
                Session["message"] = "Member successfully deleted";

                Bind();
            }
        }