/// <summary> /// The method updates a Category in the Database. /// </summary> /// <param name="categoryCL">Details of Category to be updated in the database.</param> /// <returns>Updated Category Communication Layer Class.</returns> public CategoryCL updateCategory(CategoryCL categoryCL) { Category cat = (from x in dbcontext.Categories where x.Id == categoryCL.id select x).FirstOrDefault(); //Initialises the query of fetching the Category from the Data Base. cat.IsDeleted = categoryCL.isDeleted; cat.DateCreated = categoryCL.dateCreated; cat.DateModified = categoryCL.dateModified; cat.Description = categoryCL.description; cat.FeatureName = categoryCL.featureCategory; cat.Name = categoryCL.name; cat.ParentCategoryId = categoryCL.parentCategoryId; //Updating the instance of DataBase to a Inputed Communication Layer class instance by the user. dbcontext.SaveChanges(); //Updating the Database. categoryCL.dateCreated = cat.DateCreated; categoryCL.dateModified = cat.DateModified; categoryCL.description = cat.Description; categoryCL.featureCategory = cat.FeatureName; categoryCL.isDeleted = cat.IsDeleted; categoryCL.name = cat.Name; categoryCL.parentCategoryId = cat.ParentCategoryId; categoryCL.categoryCode = cat.CategoryCode; //Updating the Communication Layer class instance by the user data by the instance of DataBase. return(categoryCL); //Returning the Communication Layer Class with Updated Category data on it. }
protected void btnDeleteCat_Click(object sender, EventArgs e) { CategoryCL catCL = new CategoryCL(); CategoryBLL catBLL = new CategoryBLL(); catCL.id = id; catBLL.deleteCategory(catCL); Response.Redirect("ProductManagement.aspx"); }
private void bindCategories(int categoryID) { CategoryBLL catBLL = new CategoryBLL(); CategoryCL catCL = catBLL.getCategory(categoryID); txtCategoryName.Text = catCL.name; txtCDesc.Text = catCL.description; lstCParentCategory.SelectedValue = catCL.parentCategoryId.ToString(); ddlFeatureCategoryItems.Text = catCL.featureCategory; }
/// <summary> /// This method creates a Category in the Database. /// </summary> /// <param name="categoryCL">Details of Category to be created in database.</param> /// <returns>Class of Category created in this method.</returns> public CategoryCL createCategory(CategoryCL categoryCL) { Category category = dbcontext.Categories.Add(new Category { DateCreated = DateTime.Now, DateModified = DateTime.Now, Description = categoryCL.description, FeatureName = categoryCL.featureCategory, Name = categoryCL.name, ParentCategoryId = categoryCL.parentCategoryId, Id = 0, IsDeleted = categoryCL.isDeleted, CategoryCode = "", }); //Adding the data recieved in parameters to DB and to a temporary DataAccess Layer Class. dbcontext.SaveChanges(); string productCode = ""; if (category.Id.ToString().Length == 1) { productCode = "000" + category.Id; } if (category.Id.ToString().Length == 2) { productCode = "00" + category.Id; } if (category.Id.ToString().Length == 3) { productCode = "0" + category.Id; } if (category.Id.ToString().Length == 4) { productCode = category.Id.ToString(); } category.CategoryCode = category.Name.Substring(0, 3) + productCode; dbcontext.SaveChanges(); //Updating the Database. CategoryCL categoryCl = new CategoryCL() { dateCreated = category.DateCreated, dateModified = category.DateModified, description = category.Description, featureCategory = category.FeatureName, id = category.Id, isDeleted = category.IsDeleted, name = category.Name, categoryCode = category.CategoryCode, parentCategoryId = category.ParentCategoryId, }; //Adding the temporary DataAccess Layer Class data to Communication Layer class. return(categoryCl); //Returning the Communication Layer Class with Created Category data on it. }
protected void Page_Load(object sender, EventArgs e) { if (Session["UserId"] != null) { string userId = Session["UserId"].ToString(); } else { //If the session value for userid is not set, redirect the user to the loginpage //see the ReturnUrl querystring value, it will be the page, that the ASP.NEt //infrastructure will redirect to after successful validation of the user //See the <Authentication node in web.config FormsAuthentication.RedirectToLoginPage(); } productId = Convert.ToInt32(Request.QueryString["productId"]); CategoryBLL categoryBLL = new CategoryBLL(); int categoryId = Convert.ToInt32(Request.QueryString["categoryId"]); CategoryCL categorydata = categoryBLL.getCategory(categoryId); string[] abc = categorydata.featureCategory.Split(';'); if (!IsPostBack) { bindFeatures(); lblProductFeature1.Text = abc[0]; lblProductFeature2.Text = abc[1]; lblProductFeature3.Text = abc[2]; lblProductFeature4.Text = abc[3]; int count = abc.Count(); if (count == 1) { txtProductFeature2.Visible = false; txtProductFeature3.Visible = false; txtProductFeature4.Visible = false; } else if (count == 2) { txtProductFeature3.Visible = false; txtProductFeature4.Visible = false; } else if (count == 3) { txtProductFeature4.Visible = false; } } }
/// <summary> /// Fetching Data From Category table by Id from database /// </summary> /// <param name="brandID"></param> /// <returns></returns> public CategoryCL getCategory(int categoryId) { Category categoryDB = (from categoryInfo in dbcontext.Categories where categoryInfo.Id == categoryId && categoryInfo.IsDeleted == false select categoryInfo).FirstOrDefault(); CategoryCL categoryget = new CategoryCL() { id = categoryDB.Id, categoryCode = categoryDB.CategoryCode, name = categoryDB.Name, description = categoryDB.Description, parentCategoryId = categoryDB.ParentCategoryId, featureCategory = categoryDB.FeatureName, dateCreated = categoryDB.DateCreated, dateModified = categoryDB.DateModified, isDeleted = categoryDB.IsDeleted }; return(categoryget); //Returns a Communication Layer Class which is fetching data from Categories table. }
//Initialises Page Load. protected void btnCategory_Click(object sender, EventArgs e) { CategoryCL categoryCL = new CategoryCL(); //Instantiates the Category Communication Layer Class. CategoryBLL categoryBLL = new CategoryBLL(); //Instantiates the Category BusinessLogic Layer Class. categoryCL.dateCreated = DateTime.Now; categoryCL.dateModified = DateTime.Now; if (txtCDesc.Text == null) { categoryCL.description = string.Empty; } else { categoryCL.description = txtCDesc.Text; } if (txtFeatureCategoryItem2.Text == null) { categoryCL.featureCategory = txtFeatureCategoryItem1.Text; } else if (txtFeatureCategoryItem3.Text == null) { categoryCL.featureCategory = txtFeatureCategoryItem1.Text + ";" + txtFeatureCategoryItem2.Text; } else if (txtFeatureCategoryItem4.Text == null) { categoryCL.featureCategory = txtFeatureCategoryItem1.Text + ";" + txtFeatureCategoryItem2.Text + ";" + txtFeatureCategoryItem3.Text; } else { categoryCL.featureCategory = txtFeatureCategoryItem1.Text + ";" + txtFeatureCategoryItem2.Text + ";" + txtFeatureCategoryItem3.Text + ";" + txtFeatureCategoryItem4.Text + ";"; } categoryCL.isDeleted = false; categoryCL.name = txtCategoryName.Text; categoryCL.parentCategoryId = Convert.ToInt32(lstCParentCategory.SelectedValue); //Adds the data entered from the Inputs to the Communication Layer Class instance. categoryBLL.createCategory(categoryCL); //This method sends the data of the Communication Layer class instance to the Database. lblSuccessfulCategory.Text = "Category Created Successfully."; }
protected void btnCategory_Click(object sender, EventArgs e) { CategoryCL catCL = new CategoryCL(); CategoryBLL catBLL = new CategoryBLL(); catCL.id = id; catCL.name = txtCategoryName.Text; catCL.parentCategoryId = Convert.ToInt32(lstCParentCategory.SelectedValue); if (txtCDesc.Text == null) { catCL.description = string.Empty; } else { catCL.description = txtCDesc.Text; } if (txtFeatureCategoryItem2.Text == null) { catCL.featureCategory = txtFeatureCategoryItem1.Text; } else if (txtFeatureCategoryItem3.Text == null) { catCL.featureCategory = txtFeatureCategoryItem1.Text + ';' + txtFeatureCategoryItem2.Text; } else if (txtFeatureCategoryItem4.Text == null) { catCL.featureCategory = txtFeatureCategoryItem1.Text + ';' + txtFeatureCategoryItem2.Text + ';' + txtFeatureCategoryItem3.Text; } else { catCL.featureCategory = txtFeatureCategoryItem1.Text + ';' + txtFeatureCategoryItem2.Text + ';' + txtFeatureCategoryItem3.Text + ';' + txtFeatureCategoryItem4.Text; } catCL.description = txtCDesc.Text; catCL.parentCategoryId = Convert.ToInt32(lstCParentCategory.SelectedValue); catCL.dateCreated = DateTime.Now; catCL.dateModified = DateTime.Now; catCL.isDeleted = false; catBLL.updateCategory(catCL); lblSuccessfulCategory.Text = "Category Updated Successfully"; }