protected void updateCurrentProductType_Click(object sender, EventArgs e) { int id = Int32.Parse(Request.QueryString["id"]); ProductType p = ProductTypeHandler.get(id); String Name = tbNameType.Text, Description = tbDescriptionType.Text, messageError = ""; int ID = p.ID; messageError = ProductTypeController.update(Name, Description); if (messageError != "") { lblErrorUpdateProductType.Text = messageError; } else { ProductTypeHandler.updateProductType(ID, Name, Description); lblErrorUpdateProductType.Text = "Your product type has been updated"; } }
public static async Task <ProductType> CreateValidProductType() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new SplurgeStopDbContext(connectionString); var repository = new ProductTypeRepository(context); var unitOfWork = new EfCoreUnitOfWork(context); var service = new ProductTypeService(repository, unitOfWork); var command = new Commands.Create { Name = "trousers", Id = null }; var productTypeController = new ProductTypeController(service); var productType = await productTypeController.Post(command); return(await repository.GetAsync(productType.Value.Id)); }
protected void deleteProductType(object sender, EventArgs e) { if (currProductType == null) { return; } string error = ProductTypeController.deleteProductType(currProductType); if (error == "") { currProductType = null; Response.Redirect(Request.RawUrl); } else { ErrorMessage.Text = error; } }
public async Task Get_All_ProductTypes() { List <ProductTypeDto> mockProductTypes = MockProductTypes(); var mockRepository = new Mock <IRepository <ProductType, ProductTypeDto, ProductTypeId> >(); mockRepository.Setup(repo => repo.GetAllDtoAsync()) .Returns(() => Task.FromResult(mockProductTypes.AsEnumerable())); var mockUnitOfWork = new Mock <IUnitOfWork>(); var productTypeService = new ProductTypeService(mockRepository.Object, mockUnitOfWork.Object); var productTypeController = new ProductTypeController(productTypeService); var result = await productTypeController.GetProductTypes(); Assert.Equal(10, result.Count()); mockRepository.Verify(mock => mock.GetAllDtoAsync(), Times.Once()); }
protected void Load_Types() { List <PSDAssignment.ProductType> productTypeList = ProductTypeController.getAllProductType(); for (int i = 0; i < productTypeList.Count; i++) { TableRow newRow = new TableRow(); ProductTable.Controls.Add(newRow); TableCell typeIDCell = new TableCell(); typeIDCell.Controls.Add(new Label() { Text = productTypeList.ElementAt(i).Id.ToString() }); newRow.Cells.Add(typeIDCell); TableCell typeNameCell = new TableCell(); typeNameCell.Controls.Add(new Label() { Text = productTypeList.ElementAt(i).Name.ToString() }); newRow.Cells.Add(typeNameCell); TableCell typeDescCell = new TableCell(); typeDescCell.Controls.Add(new Label() { Text = productTypeList.ElementAt(i).Description.ToString() }); newRow.Cells.Add(typeDescCell); TableCell ActionCell = new TableCell(); Button btnEdit = new Button { CssClass = "btn-primary", Text = "Edit", ID = productTypeList.ElementAt(i).Id.ToString() }; Button btnDelete = new Button { CssClass = "btn-danger", Text = "Delete", ID = productTypeList.ElementAt(i).Id.ToString() + "delete" }; int id = productTypeList.ElementAt(i).Id; btnDelete.Click += new EventHandler(DeleteProductType); btnEdit.Click += new EventHandler(Btn_Edit_Click); ActionCell.Controls.Add(btnEdit); ActionCell.Controls.Add(btnDelete); newRow.Cells.Add(ActionCell); } }
protected void doInsertProductType(object sender, EventArgs e) { String name = productTypeNameId.Text; String description = productTypeDescId.Text; ProductType pt = ProductTypeRepository.db.ProductTypes.Where(prodType => prodType.Name.Equals(name)).FirstOrDefault(); String nameIsExist; try { nameIsExist = pt.Name; } catch { nameIsExist = ""; } if (name.Length == 0) { errorMsgId.Text = "Please fill the product type name"; } else if (name.Length < 5) { errorMsgId.Text = "Product type name must be 5 character or more"; } else if (name.Equals(nameIsExist)) { errorMsgId.Text = "Product type name is already exist, please input different type of product"; } else if (description.Length == 0) { errorMsgId.Text = "Please fill the product type description"; } else { ProductTypeController.insertProductType(name, description); Response.Redirect("ViewProductType.aspx"); } }
protected void doUpdateProductType(object sender, EventArgs e) { int id = Int32.Parse(Request.QueryString["id"]); String name = updateProductTypeNameId.Text; String description = updateProductTypeDescId.Text; ProductType pt = ProductTypeRepository.db.ProductTypes.Where(prodType => prodType.Name.Equals(name)).FirstOrDefault(); String nameIsExist; try { nameIsExist = pt.Name; } catch { nameIsExist = ""; } if (name.Length == 0) { errorMsgId.Text = "Please fill the product type name"; } else if (name.Length < 5) { errorMsgId.Text = "Product type name must be 5 character or more"; } else if (name.Equals(nameIsExist)) { errorMsgId.Text = "Product type name is already exist, please input different type of product"; // mungkin perlu dire-validate } else if (description.Length == 0) { errorMsgId.Text = "Please fill the product type description"; } else { ProductTypeController.updateProductType(id, name, description); Response.Redirect("ViewProductType.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ProductTypeController pt = new ProductTypeController(); Uri myUri = new Uri(Request.Url.ToString()); string ProductTypeId = HttpUtility.ParseQueryString(myUri.Query).Get("ID"); if (ProductTypeId == null) { Response.Redirect("ListProductTypes.aspx"); } pt.GetProductType(int.Parse(ProductTypeId)); ProductType.Text = pt.ProductType; lblFileUploadProductTypePicturePath.Text = pt.ProductTypePicture; LanguageController lc = new LanguageController(); ddlLanguageId.DataSource = lc.GetLanguages(); ddlLanguageId.DataTextField = "LanguageTitle"; ddlLanguageId.DataValueField = "LanguageID"; ddlLanguageId.DataBind(); ddlLanguageId.SelectedValue = pt.LanguageID.ToString(); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Update") { int index = Convert.ToInt32(e.CommandArgument); Response.Redirect("UpdateProductType.aspx?id=" + index); } if (e.CommandName == "Delete_Type") { int index = Convert.ToInt32(e.CommandArgument); Response respond = ProductTypeController.DeleteProductType(index); if (respond.successStatus == false) { alert.Text = respond.message; } else { Response.Redirect("ViewProductType.aspx"); } } }
private void DeleteBtn_Click(object sender, EventArgs e) { Button currentButton = (Button)sender; int selectedIndex = 0; int.TryParse(currentButton.ID.Substring(0, currentButton.ID.Length - 3), out selectedIndex); int proTypeID = 0; proTypeID = int.Parse(((Label)ProductTypeTable.Rows[selectedIndex].Cells[1].Controls[0]).Text); Response response = ProductTypeController.DeleteProductType(proTypeID); if (response.successStatus) { Response.Redirect(Request.RawUrl); } else { ErrorLabel.Visible = true; ErrorLabel.Text = response.message; } }
protected void Load_ProductType() { List <ProductType> productTypeList = ProductTypeController.getAllProductType(); for (int i = 0; i < productTypeList.Count; i++) { TableRow newRow = new TableRow(); ProductTypeTable.Controls.Add(newRow); TableCell numberCell = new TableCell(); numberCell.Controls.Add(new Label() { Text = (i + 1) + "." }); newRow.Cells.Add(numberCell); TableCell productTypeIDCell = new TableCell(); productTypeIDCell.Controls.Add(new Label() { Text = productTypeList.ElementAt(i).ID.ToString() }); newRow.Cells.Add(productTypeIDCell); TableCell productTypeCell = new TableCell(); productTypeCell.Controls.Add(new Label() { Text = productTypeList.ElementAt(i).Name }); newRow.Cells.Add(productTypeCell); TableCell productTypeDescCell = new TableCell(); productTypeDescCell.Controls.Add(new Label() { Text = productTypeList.ElementAt(i).Description }); newRow.Cells.Add(productTypeDescCell); } }
public async Task Details_ReturnsNotFoundResult_WhenIdIsNull() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseSqlite(connection) .Options; using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); context.SaveChanges(); } using (var context = new ApplicationDbContext(options)) { var controller = new ProductTypeController(context); var result = await controller.Details(null); Assert.IsType <NotFoundResult>(result); } }
public async Task Index_CanLoadFromContext() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseSqlite(connection) .Options; using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); context.ProductType.AddRange( new ProductType { Nome = "Alimento" }, new ProductType { Nome = "Educação" }, new ProductType { Nome = "Bem-Estar" }); context.SaveChanges(); } using (var context = new ApplicationDbContext(options)) { var controller = new ProductTypeController(context); var result = await controller.Index(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <ProductType> >( viewResult.ViewData.Model); Assert.Equal(3, model.Count()); } }
protected void Page_Load(object sender, EventArgs e) { List <Product> productList = ProductController.getRandomProduct(); for (int i = 0; i < productList.Count; i++) { TableRow newRow = new TableRow(); ProductTable.Controls.Add(newRow); TableCell productIdCell = new TableCell(); productIdCell.Controls.Add(new Label() { Text = productList.ElementAt(i).Id.ToString() }); newRow.Cells.Add(productIdCell); TableCell productNameCell = new TableCell(); productNameCell.Controls.Add(new Label() { Text = productList.ElementAt(i).Name.ToString() }); newRow.Cells.Add(productNameCell); TableCell productPriceCell = new TableCell(); productPriceCell.Controls.Add(new Label() { Text = "Rp" + productList.ElementAt(i).Price.ToString() }); newRow.Cells.Add(productPriceCell); TableCell productStockCell = new TableCell(); productStockCell.Controls.Add(new Label() { Text = productList.ElementAt(i).Stock.ToString() }); newRow.Cells.Add(productStockCell); TableCell productTypeCell = new TableCell(); int productTypeID = Convert.ToInt32(productList.ElementAt(i).ProductTypeID); if (productTypeID != null) { if (ProductTypeController.getProductTypeByID(productTypeID) != null) { String productTypeName = ProductTypeController.getProductTypeByID(productTypeID).Name; productTypeCell.Controls.Add(new Label() { Text = productTypeName }); } } newRow.Cells.Add(productTypeCell); if (Session["auth_user"] != null) { if (UserHandler.findUserByID(Convert.ToInt32(Session["auth_user"])).RoleID == 2) { TableCell ActionCell = new TableCell(); int id = productList.ElementAt(i).Id; if (productList.ElementAt(i).Stock != 0) { Button text = new Button() { CssClass = "btn-primary", Text = "Add To Cart", ID = id.ToString() }; text.Click += new EventHandler(AddToCart); ActionCell.Controls.Add(text); newRow.Cells.Add(ActionCell); } else { ActionCell.Controls.Add(new Label() { Text = "Stock is empty" }); newRow.Cells.Add(ActionCell); } } } } }
protected void BindGridList() { GridView1.DataSource = ProductTypeController.GetAllProductTypes(); GridView1.DataBind(); }
private void btnList_Click(object sender, EventArgs e) { removeAllManagamentControls(); switch (this.Mantenimiento) { case "Users": ViewUsers viewUser = new ViewUsers(); UserCtrl userCtrl = new UserCtrl(); viewUser.Height = Parent.Height; viewUser.Width = Parent.Width; this.result = userCtrl.getAllUsers(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewUser.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewUser); } break; case "Clients": ClientsList clientsList = new ClientsList(); ClientsController cont = new ClientsController(); clientsList.Height = Parent.Height; clientsList.Width = Parent.Width; Dictionary <Object, dynamic> res = cont.getAllClients(); if (res["code"] == Result.Failed) { MessageBox.Show(res["msg"]); return; } if (res["code"] == Result.Processed) { clientsList.loadDataGrid(res["content"]); Parent.Controls.Add(clientsList); } break; case "States": ViewStates viewState = new ViewStates(); StateController controller = new StateController(); viewState.Height = Parent.Height; viewState.Width = Parent.Width; this.result = controller.getAllStates(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewState.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewState); } break; case "PaymentMethods": ViewPaymentMethods viewPayment = new ViewPaymentMethods(); PaymentMethodController cnt = new PaymentMethodController(); viewPayment.Height = Parent.Height; viewPayment.Width = Parent.Width; this.result = cnt.getAllPaymentMethods(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewPayment.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewPayment); } break; case "MaterialTypes": ViewMaterialTypes viewMaterials = new ViewMaterialTypes(); MaterialTypeController contr = new MaterialTypeController(); viewMaterials.Height = Parent.Height; viewMaterials.Width = Parent.Width; this.result = contr.getAllMaterialTypes(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewMaterials.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewMaterials); } break; case "Materials": MaterialsList listMaterials = new MaterialsList(); MaterialController ctrl = new MaterialController(); listMaterials.Height = Parent.Height; listMaterials.Width = Parent.Width; this.result = ctrl.getMaterialsToPopulate(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { listMaterials.loadDataGrid(this.result["content"]); Parent.Controls.Add(listMaterials); } break; case "ProductTypes": ViewProductTypes viewProductTypes = new ViewProductTypes(); ProductTypeController contr2 = new ProductTypeController(); viewProductTypes.Height = Parent.Height; viewProductTypes.Width = Parent.Width; this.result = contr2.getAllProductTypes(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewProductTypes.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewProductTypes); } break; case "Products": ViewProducts viewProducts = new ViewProducts(); ProductController contr3 = new ProductController(); viewProducts.Height = Parent.Height; viewProducts.Width = Parent.Width; this.result = contr3.getAllProducts(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewProducts.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewProducts); } break; case "Providers": ViewProviders viewProviders = new ViewProviders(); ProviderController providerCtrl = new ProviderController(); viewProviders.Height = Parent.Height; viewProviders.Width = Parent.Width; this.result = providerCtrl.getAllProviders(); if (this.result["code"] == Result.Failed) { MessageBox.Show(this.result["msg"]); return; } if (this.result["code"] == Result.Processed) { viewProviders.loadDataGrid(this.result["content"]); Parent.Controls.Add(viewProviders); } break; } }
public void LoadDataProductType() { productType = new ProductTypeController(); dataProductTypes.DataSource = productType.GetProductTypes(); dataProductTypes.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { ErrorLabel.Visible = false; if (Session["email"] != null) { User u = UserController.GetUser(Session["email"].ToString()); if (u.RoleID == 1) { List <Product_Type> proType = ProductTypeController.GetProductTypes(); for (int i = 0; i < proType.Count; i++) { TableRow newRow = new TableRow(); ProductTypeTable.Controls.Add(newRow); TableCell noCell = new TableCell(); noCell.Controls.Add(new Label() { Text = (i + 1) + "." }); newRow.Cells.Add(noCell); noCell.CssClass = "td"; TableCell idCell = new TableCell(); idCell.Controls.Add(new Label() { Text = proType[i].ID.ToString() }); newRow.Cells.Add(idCell); idCell.CssClass = "td"; TableCell nameCell = new TableCell(); nameCell.Controls.Add(new Label() { Text = proType[i].Name }); newRow.Cells.Add(nameCell); nameCell.CssClass = "td"; TableCell descCell = new TableCell(); descCell.Controls.Add(new Label() { Text = proType[i].Description }); newRow.Cells.Add(descCell); descCell.CssClass = "td"; TableCell updateCell = new TableCell(); Button UpdateBtn = new Button() { ID = (i + 1) + "_UB", Text = "Update" }; UpdateBtn.Click += UpdateBtn_Click; updateCell.Controls.Add(UpdateBtn); updateCell.CssClass = "td"; newRow.Cells.Add(updateCell); TableCell deleteCell = new TableCell(); Button deleteBtn = new Button() { ID = (i + 1) + "_DB", Text = "Delete" }; deleteBtn.Click += DeleteBtn_Click; deleteCell.Controls.Add(deleteBtn); deleteCell.CssClass = "td"; newRow.Cells.Add(deleteCell); } } else { CantAccessView(); } } else { CantAccessView(); } }
protected void Load_Products() { List <Product> productList = ProductController.getAllProducts(); for (int i = 0; i < productList.Count; i++) { TableRow newRow = new TableRow(); ProductTable.Controls.Add(newRow); TableCell productIdCell = new TableCell(); productIdCell.Controls.Add(new Label() { Text = productList.ElementAt(i).Id.ToString() }); newRow.Cells.Add(productIdCell); TableCell productNameCell = new TableCell(); productNameCell.Controls.Add(new Label() { Text = productList.ElementAt(i).Name.ToString() }); newRow.Cells.Add(productNameCell); TableCell productPriceCell = new TableCell(); productPriceCell.Controls.Add(new Label() { Text = "Rp." + productList.ElementAt(i).Price.ToString() }); newRow.Cells.Add(productPriceCell); TableCell productStockCell = new TableCell(); productStockCell.Controls.Add(new Label() { Text = productList.ElementAt(i).Stock.ToString() }); newRow.Cells.Add(productStockCell); TableCell productTypeCell = new TableCell(); int productID = Convert.ToInt32(productList.ElementAt(i).ProductTypeID); String productTypeName = ProductTypeController.getProductTypeByID(productID).Name; productTypeCell.Controls.Add(new Label() { Text = productTypeName }); newRow.Cells.Add(productTypeCell); User user = UserController.getUserByID(Convert.ToInt32(Session["auth_user"])); if (user != null) { TableCell ActionCell = new TableCell(); int id = productList.ElementAt(i).Id; if (user.RoleID == 3) { Button btnEdit = new Button { CssClass = "btn-primary", Text = "Edit", ID = id.ToString() }; Button btnDelete = new Button { CssClass = "btn-danger", Text = "Delete", ID = id.ToString() + "delete" }; btnEdit.Click += new EventHandler(Btn_Edit_Click); btnDelete.Click += new EventHandler(DeleteProduct); ActionCell.Controls.Add(btnEdit); ActionCell.Controls.Add(btnDelete); newRow.Cells.Add(ActionCell); } else { if (productList.ElementAt(i).Stock != 0) { Button text = new Button() { CssClass = "btn-primary", Text = "Add To Cart", ID = id.ToString() }; text.Click += new EventHandler(BtnBuy_Click); ActionCell.Controls.Add(text); newRow.Cells.Add(ActionCell); } else { ActionCell.Controls.Add(new Label() { Text = "Stock is empty" }); newRow.Cells.Add(ActionCell); } } } } }