Beispiel #1
0
        /// <summary>
        /// The method updates a Brand in the Database.
        /// </summary>
        /// <param name="productCL">Details of Brand to be updated in the database.</param>
        /// <returns>Updated Brand Communication Layer Class.</returns>
        public BrandCL updateBrand(BrandCL brandCL)
        {
            Brand brand = (from x in dbcontext.Brands where x.Id == brandCL.id select x).FirstOrDefault();

            //Initialises the query of fetching the Brand from the Data Base.
            brand.IsDeleted    = brandCL.isDeleted;
            brand.DateCreated  = brandCL.dateCreated;
            brand.DateModified = brandCL.dateModified;
            brand.Name         = brandCL.name;
            brand.Promotions   = brandCL.promotions;
            brand.BrandRating  = brandCL.brandRating;
            brand.ImageURL     = brandCL.imageURL;
            //Updating the instance of DataBase to a Inputed Communication Layer class instance by the user.
            dbcontext.SaveChanges();
            //Updating the Database.
            brandCL.dateCreated  = brand.DateCreated;
            brandCL.brandCode    = brand.BrandCode;
            brandCL.imageURL     = brand.ImageURL;
            brandCL.dateModified = brand.DateModified;
            brandCL.promotions   = brand.Promotions;
            brandCL.brandRating  = Convert.ToInt32(brand.BrandRating);
            brandCL.isDeleted    = brand.IsDeleted;
            brandCL.name         = brand.Name;
            brandCL.id           = brand.Id;
            //Updating the Communication Layer class instance by the user data by the instance of DataBase.
            return(brandCL);
            //Returning the Communication Layer Class with Updated Brand data on it.
        }
        protected void btnDelBrand_Click(object sender, EventArgs e)
        {
            BrandCL  brandCL  = new BrandCL();
            BrandBLL brandBLL = new BrandBLL();

            brandCL.id = id;
            brandBLL.deleteBrand(brandCL);
            Response.Redirect("ProductManagement.aspx");
        }
        private void bindBrands(int brandId)
        {
            BrandCL  brandCL  = new BrandCL();
            BrandBLL brandBLL = new BrandBLL();

            brandCL           = brandBLL.getBrands(brandId);
            txtBName.Text     = brandCL.name;
            ddlBRating.Text   = brandCL.brandRating.ToString();
            txtBDiscount.Text = brandCL.promotions.ToString();
        }
Beispiel #4
0
        /// <summary>
        /// This method creates a Brand in the Database.
        /// </summary>
        /// <param name="brandCL">Details of Brand to be created in database.</param>
        /// <returns>Class of Brand created in this method.</returns>
        public BrandCL createBrand(BrandCL brandCL)
        {
            Brand brand = dbcontext.Brands.Add(new Brand
            {
                Id           = 0,
                Name         = brandCL.name,
                BrandCode    = "",
                BrandRating  = brandCL.brandRating,
                Promotions   = brandCL.promotions,
                DateCreated  = brandCL.dateCreated,
                DateModified = brandCL.dateModified,
                IsDeleted    = brandCL.isDeleted,
                ImageURL     = brandCL.imageURL,
            });

            //Adding the data recieved in parameters to DB and to a temporary DataAccess Layer Class.
            dbcontext.SaveChanges();
            string productCode = "";

            if (brand.Id.ToString().Length == 1)
            {
                productCode = "000" + brand.Id;
            }
            if (brand.Id.ToString().Length == 2)
            {
                productCode = "00" + brand.Id;
            }
            if (brand.Id.ToString().Length == 3)
            {
                productCode = "0" + brand.Id;
            }
            if (brand.Id.ToString().Length == 4)
            {
                productCode = brand.Id.ToString();
            }
            brand.BrandCode = brand.Name.Substring(0, 3) + productCode;
            dbcontext.SaveChanges();
            //Updating the Database.
            BrandCL brandCl = new BrandCL()
            {
                id           = brand.Id,
                brandRating  = brand.Id,
                name         = brand.Name,
                promotions   = brand.Promotions,
                dateCreated  = brand.DateCreated,
                dateModified = brand.DateModified,
                isDeleted    = brand.IsDeleted,
                brandCode    = brand.BrandCode,
                imageURL     = brand.ImageURL
            };

            //Adding the temporary DataAccess Layer Class data to Communication Layer class.
            return(brandCl);
            //Returning the Communication Layer Class with Created Brand data on it.
        }
Beispiel #5
0
        /// <summary>
        /// The method deletes a Brand in the Database.
        /// </summary>
        /// <param name="brandCL">Details of Brand to be deleted in the database.</param>
        /// <returns>Deleted Brand Communication Layer </returns>
        public BrandCL deleteBrand(BrandCL brandCL)
        {
            Brand brand = (from x in dbcontext.Brands where x.Id == brandCL.id select x).FirstOrDefault();

            //Initialises the query of fetching the Brand from the Data Base.
            brand.IsDeleted = true;
            //Updating the instance of DataBase to a Inputed Communication Layer class instance by the user.
            dbcontext.SaveChanges();
            //Updating the Database.
            brandCL.isDeleted = brand.IsDeleted;
            //Updating the Communication Layer class instance by the user data by the instance of DataBase.
            return(brandCL);
            //Returning the Communication Layer Class with Deleted Brand data on it.
        }
        protected void btnBrand_Click(object sender, EventArgs e)
        {
            BrandCL  brandCL  = new BrandCL();
            BrandBLL brandBLL = new BrandBLL();

            brandCL.id           = id;
            brandCL.name         = txtBName.Text;
            brandCL.dateCreated  = DateTime.Now;
            brandCL.dateModified = DateTime.Now;
            brandCL.brandRating  = Convert.ToInt32(ddlBRating.Text);
            brandCL.isDeleted    = false;
            brandCL.promotions   = Convert.ToDecimal(txtBDiscount.Text);
            brandBLL.updateBrand(brandCL);
            lblSuccessfulBrand.Text = "Brand Updated Successfully";
        }
Beispiel #7
0
        /// <summary>
        /// This method fetchs the values from Brand table By ID
        /// </summary>
        /// <param name="brandID"></param>
        /// <returns></returns>
        public BrandCL getBrands(int brandID)
        {
            Brand   brandDB  = (from brandInfo in dbcontext.Brands where brandInfo.Id == brandID && brandInfo.IsDeleted == false select brandInfo).FirstOrDefault();
            BrandCL brandget = new BrandCL()
            {
                id           = brandDB.Id,
                name         = brandDB.Name,
                promotions   = brandDB.Promotions,
                brandRating  = Convert.ToInt32(brandDB.BrandRating),
                dateCreated  = brandDB.DateCreated,
                dateModified = brandDB.DateModified,
                isDeleted    = brandDB.IsDeleted,
                brandCode    = brandDB.BrandCode,
                imageURL     = brandDB.ImageURL,
            };

            return(brandget);
        }
Beispiel #8
0
        //Initialises when the Create Category Button is clicked.
        protected void btnBrand_Click(object sender, EventArgs e)
        {
            BrandCL brandCL = new BrandCL();
            //Instantiates the Brand Communication Layer Class.
            BrandBLL brandBLL = new BrandBLL();

            //Instantiates the Brand BusinessLogic Layer Class.
            brandCL.brandRating  = Convert.ToInt32(ddlBRating.SelectedValue);
            brandCL.name         = txtBName.Text;
            brandCL.promotions   = Convert.ToDecimal(txtBDiscount.Text);
            brandCL.dateCreated  = DateTime.Now;
            brandCL.dateModified = DateTime.Now;
            brandCL.isDeleted    = false;
            //Adds the data entered from the Inputs to the Communication Layer Class instance.
            brandBLL.createBrand(brandCL);
            //This method sends the data of the Communication Layer class instance to the Database.
            lblSuccessfulBrand.Text = "Brand Created Successfully.";
        }