protected void DataGridForListOfProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
     DataGridForListOfProducts.PageIndex = e.NewPageIndex;
     AccessorToSessionForListOfProductsPage CurrentAccessorToSession = new AccessorToSessionForListOfProductsPage(Session);
     DataGridForListOfProducts.DataSource = CurrentAccessorToSession.GetManagerOfProductsForCurrentSession().LoadProductsForPages();
     DataGridForListOfProducts.DataBind();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         AccessorToSessionForListOfProductsPage CurrentAccessorToSession = new AccessorToSessionForListOfProductsPage(Session);
         CurrentAccessorToSession.AddManagerOfProductsToSession(new ManagerOfProducts(new FakeRepositoryForProducts()));
         DataGridForListOfProducts.DataSource = CurrentAccessorToSession.GetManagerOfProductsForCurrentSession().LoadProductsForPages();
         DataGridForListOfProducts.DataBind();
     }
 }
    protected void AddNewProductButtonOnClick(object sender, EventArgs e)
    {
        if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
        {
            if ((ProductNameTextBox.Text != null) && (ProductNameTextBox.Text != string.Empty))
            {
                AccessorToSessionForListOfProductsPage CurrentAccessorToSession = new AccessorToSessionForListOfProductsPage(Session);
                if (CurrentAccessorToSession.GetManagerOfProductsForCurrentSession().CheckProductNameForDuplicate(ProductNameTextBox.Text))
                {
                    throw new Exception(Texts.ErrorMessageForAddingNewProduct_IllegalName);
                }
            }
        }
        else
        {
            Validate();
            if (IsValid)
            {
                if (ProductImageFileUpload.HasFile)
                {
                    string ServerFullFileName = string.Empty;
                    ServerFullFileName = HttpContext.Current.Server.MapPath("/" + Texts.NameOfFolderForProductImages + "/" + ProductImageFileUpload.PostedFile.FileName);
                    lock (GatesForFileSaving)
                    {
                        if (!File.Exists(ServerFullFileName))
                        {
                            ProductImageFileUpload.PostedFile.SaveAs(ServerFullFileName);
                        }
                    }
                }
                AccessorToSessionForListOfProductsPage CurrentAccessorToSession = new AccessorToSessionForListOfProductsPage(Session);

                bool NewProductWasAdded = CurrentAccessorToSession.GetManagerOfProductsForCurrentSession().AddNewProduct(ProductNameTextBox.Text, ProductDescriptionTextBox.Text,
                    Int32.Parse(ProductPriceTextBox.Text), "~/" + Texts.NameOfFolderForProductImages + "/" + ProductImageFileUpload.PostedFile.FileName);
                CurrentListOfProducts.RefreshBinding();
            }
        }
    }
 public void RefreshBinding()
 {
     AccessorToSessionForListOfProductsPage CurrentAccessorToSession = new AccessorToSessionForListOfProductsPage(Session);
     DataGridForListOfProducts.DataSource = CurrentAccessorToSession.GetManagerOfProductsForCurrentSession().LoadProductsForPages();
     DataGridForListOfProducts.DataBind();
 }
 protected void DislikeButton_OnClick(object sender, EventArgs e)
 {
     AccessorToSessionForListOfProductsPage CurrentAccessorToSession = new AccessorToSessionForListOfProductsPage(Session);
     int NewAmountOfLikes = CurrentAccessorToSession.GetManagerOfProductsForCurrentSession().ChangeRating(CurrentProductID_Int, false);
     LabelForDislikes.Text = NewAmountOfLikes.ToString();
 }