private void deleteAccountBtn_Click(object sender, EventArgs e) { Food aa = new Food(); aa.FoodId = this.textBox1.Text; //aa.FoodName = this.textBox2.Text; // aa.FoodPrice = Convert.ToDouble(this.textBox4.Text); FoodRepository re = new FoodRepository(); if (re.Delete(aa.FoodId)) { // List<Account> accList = accRepo.GetAllAccounts(); // this.accountGridView.DataSource = accList MessageBox.Show("Delete Complete"); textBox1.Text = " "; textBox2.Text = " "; textBox4.Text = " "; } else { MessageBox.Show("Delete Not Complete", "Error"); } }
protected void Food_RowCommand(object sender, GridViewCommandEventArgs e) { fm = new FoodModel(); int index = Convert.ToInt32(e.CommandArgument); fm.Id = Convert.ToInt32(FoodList.Rows[index].Cells[3].Text); if (e.CommandName == "DeleteRow") { //re.Id = Convert.ToInt32(RealEstateList.Rows[index].Cells[3].Text); bool res = fr.Delete(fm); if (res) { string message = "Deleting info was successfully"; string script = "window.onload = function(){ alert('"; script += message; script += "')};"; ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true); } else { string message = "Deleting info was not successfully"; string script = "window.onload = function(){ alert('"; script += message; script += "')};"; ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); } GetData(); } if (e.CommandName == "EditRow") { btnSave.Visible = false; btnUpdate.Visible = true; addNew.Visible = true; showList.Visible = false; FoodId.Text = FoodList.Rows[index].Cells[3].Text.ToString(); Name.Text = FoodList.Rows[index].Cells[4].Text.ToString(); Calorie.Text = FoodList.Rows[index].Cells[5].Text.ToString(); Materials.Text = FoodList.Rows[index].Cells[9].Text.ToString(); Recipe.Text = FoodList.Rows[index].Cells[10].Text.ToString(); var d = FoodList.Rows[index].Cells[6].Text.ToString(); FoodGroupDropDown.SelectedValue = FoodGroupDropDown.Items.FindByValue(d).Value; var LID = FoodList.Rows[index].Cells[8].Text.ToString(); CookingLevelDropDown.SelectedValue = CookingLevelDropDown.Items.FindByValue(LID).Value; Servings.Text = FoodList.Rows[index].Cells[11].Text.ToString(); var dr = FoodList.Rows[index].Cells[13].Text.ToString(); // CheckBox1.Checked = (FoodList.Rows[index].Cells[13]) as CheckBox; CheckBox cbox1 = (CheckBox)FoodList.Rows[index].Cells[12].Controls[0]; CheckBox1.Checked = cbox1.Checked; CheckBox cbox2 = (CheckBox)FoodList.Rows[index].Cells[13].Controls[0]; CheckBox2.Checked = cbox2.Checked; //NotFriendlyForDropDown.SelectedValue = NotFriendlyForDropDown.Items.FindByValue(dr).Value; } }
public void TestDeleteFood() { using (var context = new FoodContext(ContextOptions)) { var repo = new FoodRepository(context); repo.CreateFood(new Food { Calories = 300, Carbohydrates = 34, Fats = 33, Name = "Chocolate", Protein = 5 }); repo.CreateFood(new Food { Calories = 200, Carbohydrates = 22, Fats = 11, Name = "Orange", Protein = 13 }); repo.Delete(new FoodRequest { Name = "Orange", Id = 2 }); Assert.Single(repo.GetAllFoods()); repo.Dispose(); } }
public void FoodRepository() { Mock <IDbSetFactory> factory = new Mock <IDbSetFactory>(); Mock <DbSet <Food> > dbSet = new Mock <DbSet <Food> >(); factory.Setup(m => m.CreateDbSet <Food>()).Returns(dbSet.Object); FoodRepository repo = new FoodRepository(factory.Object); var Food = new Food(); var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(Food)); dbSet.InSequence(sequence).Setup(e => e.Find(Food.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Food.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Food.Id)); repo.Create(Food); repo.Get(Food.Id); repo.Update(Food); repo.Delete(Food.Id); }
public void FoodRepository() { Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>(); Mock<DbSet<Food>> dbSet = new Mock<DbSet<Food>>(); factory.Setup(m => m.CreateDbSet<Food>()).Returns(dbSet.Object); FoodRepository repo = new FoodRepository(factory.Object); var Food = new Food(); var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(Food)); dbSet.InSequence(sequence).Setup(e => e.Find(Food.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Food.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Food.Id)); repo.Create(Food); repo.Get(Food.Id); repo.Update(Food); repo.Delete(Food.Id); }
public IActionResult Delete(int id) { FoodRepository.Delete(id); return(RedirectToAction("Drax")); }