Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var edit = Convert.ToBoolean(Request.QueryString["Edit"]);
        var id   = Convert.ToInt32(Request.QueryString["Id"]);

        if (!IsPostBack)
        {
            foreach (var images in imageRepository.ReadImages())
            {
                ddlImages.Items.Add(new ListItem(images.Filename, images.Id.ToString()));
            }

            foreach (var product in productsRepository.Read())
            {
                var image = imageRepository.ReadImages().FirstOrDefault(i => i.Id == product.Images);
                litProductTable.Text += "<tr><td><a href='products.aspx?Delete=true&Id=" + product.Id + "'>Remove</a></td><td><a href='products.aspx?Edit=true&Id=" + product.Id + "'>Edit</a></td><td>" + product.Title + "</td><td>" + product.Price + "</td><td>" + Bootstrap.Image(image.Filename, 200, 200, "crop", true) + "</td></tr>";
            }

            if (edit)
            {
                var productToEdit = productsRepository.Read().FirstOrDefault(p => p.Id == id);
                txtTitle.Text            = productToEdit.Title;
                txtComment.Text          = productToEdit.Comment;
                txtPrice.Text            = productToEdit.Price.ToString();
                ddlImages.SelectedValue  = productToEdit.Images.ToString();
                btnSubmitProduct.Visible = false;
                btnEditProduct.Visible   = true;
            }
        }
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var settingRepo   = new SettingsModel.Repository();
        var uploadRepo    = new UploadModel.Repository();
        var productRepo   = new ProductsModel.Repository();
        var openhoursRepo = new HoursModel.Repository();
        var openhours     = openhoursRepo.Read().First();

        var settings       = settingRepo.Read().First();
        var firstOrDefault = uploadRepo.ReadImages().FirstOrDefault(i => i.Id == settings.Image);

        var settingImage = firstOrDefault.Filename;

        litFrontpageImage.Text = Bootstrap.Image(settingImage, 400, 600, "stretch", false);
        litPageInfo.Text       = settings.PageInfo;



        bool firstitem = true;

        foreach (var product in productRepo.Read().Take(10))
        {
            var orDefault = uploadRepo.ReadImages().FirstOrDefault(i => i.Id == product.Images);
            if (orDefault != null)
            {
                var    productImage = orDefault.Filename;
                string active       = "";
                if (firstitem)
                {
                    firstitem = false;
                    active    = "active";
                }

                litProducts.Text += "<div class='item " + active + "'> " + "<h3 class='text-center'>" + product.Title + "</h3>" + "<p class='text-center'>" + product.Price + ",-<p>" + Bootstrap.Image(productImage, 700, 900, "crop", true) + "</div>";
            }
        }

        litOpeningHoursMonday.Text    = openhours.Monday;
        litOpeningHoursTuesday.Text   = openhours.Tuesday;
        litOpeningHoursWednesday.Text = openhours.Wednesday;
        litOpeningHoursThursday.Text  = openhours.Thursday;
        litOpeningHoursFriday.Text    = openhours.Friday;
        litOpeningHoursSaturday.Text  = openhours.Saturday;
        litOpeningHoursSunday.Text    = openhours.Sunday;
        litComment.Text = openhours.Comment;

        var prices = new PriceModel.Repository();

        foreach (var price in prices.ReadPrices().Take(8))
        {
            litPriceList10.Text += "<li class='list-group-item'>" + price.Product + "<span class='badge'>" + price.Amount + ",- DKK</span></li>";
        }
    }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        UserModel.Repository     userRepository    = new UserModel.Repository();
        UploadModel.Repository   uploadRepository  = new UploadModel.Repository();
        PageModel.Repository     pageRepository    = new PageModel.Repository();
        ProductsModel.Repository productRepository = new ProductsModel.Repository();

        litUserCount.Text  = userRepository.ShowUsers().Count().ToString();
        litImageCount.Text = uploadRepository.ReadImages().Count().ToString();
        litPageCount.Text  = pageRepository.ReadPages().Count().ToString();


        foreach (var user in userRepository.ShowUsers().Take(5))
        {
            litUserTop10.Text += "<a href='Users.aspx?Id=" + user.Id + "&Edit=true&Skip=0&Take=10' class='list-group-item'>" + user.UserName + "</a>";
        }

        bool firstitem = true;

        foreach (var image in uploadRepository.ReadImages().Take(5))
        {
            string active = "";
            if (firstitem)
            {
                firstitem = false;
                active    = "active";
            }

            litImagesLatest.Text += "<div class='item " + active + "'> " + Bootstrap.Image(image.Filename, 200, 400, "crop", true) + "</div>";
        }

        foreach (var pages in pageRepository.ReadPages().Take(5))
        {
            litPageLatest.Text += "<a href='#' class='list-group-item'>" + pages.Title + " - " + Bootstrap.ShortenContent(pages.Content, 150) + "...</a>";
        }

        foreach (var product in productRepository.Read().Take(5))
        {
            var productImage = uploadRepository.ReadImages().FirstOrDefault(i => i.Id == product.Images);
            litProductsOverview.Text += "<li class='media well'><div class='media-left'><a href='#'>" + Bootstrap.MediaObject(productImage.Filename, 100, 100, "crop", true) + "</div></a><div class='media-body'><h4 class='media-heading'>" + product.Title + "</h4><p>" + product.Comment + "</p><p>" + product.Price + "</p></div>" + "</li>";
        }
    }
Ejemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var repo        = new UploadModel.Repository();
        var productRepo = new ProductsModel.Repository();
        var id          = Convert.ToInt32(Request.QueryString["Id"]);
        var delete      = Convert.ToBoolean(Request.QueryString["Delete"]);

        if (delete)
        {
            var imageToDelete     = repo.ReadImages().FirstOrDefault(i => i.Id == id);
            var productImageCount = productRepo.Read().Count(pi => imageToDelete != null && pi.Images == imageToDelete.Id);
            if (imageToDelete != null)
            {
                if (productImageCount == 0)
                {
                    var fileOnServer = new FileInfo(Server.MapPath(@"~/upload/" + imageToDelete.Filename));
                    repo.DeleteImage(imageToDelete);
                    fileOnServer.Delete();
                    Response.Redirect(redirectUrl);
                }
                else
                {
                    litWarning.Text = Bootstrap.Alert("Please delete products associated with the image.", 4);
                }
            }
            else
            {
                litWarning.Text = Bootstrap.Alert("Error occured, the image does not exist. try refreshing the page.", 4);
            }
        }



        foreach (var image in repo.ReadImages())
        {
            litTableImages.Text += "<tr><td>" + Bootstrap.Image(image.Filename, 200, 200, "crop", true) + "</td><td>" + image.Id + "</td><td>" + image.Filename + "</td><td><a href='images.aspx?id=" + image.Id + "&Delete=true'><span class='glyphicon glyphicon-remove-sign icon-lg'></span></a></td></tr>";
        }
    }