static int rankForPawn(DispenseMode mode, ThingDef def) { FoodCategory pref = def.DetermineFoodCategory(); FoodCategory[] rank; if (mode == DispenseMode.Cannibal || mode == DispenseMode.CannibalClean) { rank = ranksForCannibals; } else { rank = ranksForOthers; } int num = Array.IndexOf(rank, pref); if (num == -1) { Log.Warning("Found unexpected food in hopper : " + def); num = rank.Count() - 1; } return(num); }
public void RedirectToActionIndex_WithTheCorrectModel__WhenModelStateIsValid() { //Arrange var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); var mappingServiceMock = new Mock <IMappingService>(); var controller = new FoodCategoriesController(foodCategoriesServiceMock.Object, mappingServiceMock.Object); Guid id = Guid.NewGuid(); string name = "Tomatos"; FoodType foodType = FoodType.Vegetable; MeasuringUnitType measuringUnit = MeasuringUnitType.Kg; var foodcategory = new FoodCategory() { Id = id, Name = name, FoodType = foodType, MeasuringUnit = measuringUnit }; foodCategoriesServiceMock.Setup(x => x.GetFoodCategoryById(id)).Returns(foodcategory); var model = new FoodCategoryViewModel(); model.Id = foodcategory.Id; model.Name = foodcategory.Name; model.FoodType = foodcategory.FoodType; model.MeasuringUnit = foodcategory.MeasuringUnit; mappingServiceMock.Setup(x => x.Map <FoodCategoryViewModel>(foodcategory)).Returns(model); //Act & Assert controller.WithCallTo(x => x.EditFoodCategory(model)) .ShouldRedirectTo(x => x.Index()); }
public void ReturnJsonResultWithIngredientsAndRightContent() { //Arrange var ingredientsServiceMock = new Mock <IIngredientsService>(); var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); var recipesServiceMock = new Mock <IRecipesService>(); var mappingServiceMock = new Mock <IMappingService>(); var controller = new RecipesController(recipesServiceMock.Object, ingredientsServiceMock.Object, foodCategoriesServiceMock.Object, mappingServiceMock.Object); var id = Guid.NewGuid(); var name = "Tomatos"; var foodType = FoodType.Vegetable; var measuringUnit = MeasuringUnitType.Kg; var foodcategory = new FoodCategory() { Id = id, Name = name, FoodType = foodType, MeasuringUnit = measuringUnit }; Guid ingredientId = Guid.NewGuid(); string ingredientName = "tomato"; decimal pricePerMeasuringUnit = 1.20m; double quantityInMeasuringUnit = 0.250; Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategory = foodcategory, PricePerMeasuringUnit = pricePerMeasuringUnit, QuantityInMeasuringUnit = quantityInMeasuringUnit }; IngredientViewModel ingredientModel = new IngredientViewModel() { Id = ingredientId, Name = ingredientName, FoodCategory = foodcategory, PricePerMeasuringUnit = pricePerMeasuringUnit, QuantityInMeasuringUnit = quantityInMeasuringUnit }; var ingredients = new List <IngredientViewModel>() { ingredientModel }; ingredientsServiceMock.Setup(x => x.GetAllIngredients()).Returns(new List <Ingredient> { ingredient }); string query = "tomato"; //Act & Assert controller.WithCallTo(x => x.AutoComplete(query)) .ShouldReturnJson(data => { Assert.That(ingredients[0].Name, Is.EqualTo(ingredientName)); }); }
#pragma warning disable RECS0082 // Parameter has the same name as a member and hides it static int rankForPawn(DispenseMode mode, ThingDef def) #pragma warning restore RECS0082 // Parameter has the same name as a member and hides it { FoodCategory pref = def.DetermineFoodCategory(); FoodCategory[] rank; if (mode == DispenseMode.Cannibal || mode == DispenseMode.CannibalClean) { rank = ranksForCannibals; } else { rank = ranksForOthers; } int num = Array.IndexOf(rank, pref); if (num == -1) { Log.Warning("Found unexpected food in hopper : " + def); num = rank.Count() - 1; } return(num); }
//DELETE FoodCategory public void DeleteCat(int id) { FoodCategory f = context.FoodCategories.FirstOrDefault(e => e.CatID == id); context.FoodCategories.Remove(f); context.SaveChanges(); }
public bool updateCate(int idCate, string nameCate, int other) { List <CategoryItem> listCate = loadCate(); try { using (DataBaseCoffeeDataContext db = new DataBaseCoffeeDataContext()) { foreach (CategoryItem item in listCate) { if (item.NameCate.Equals(nameCate)) { return(false); } } FoodCategory cate = db.FoodCategories.SingleOrDefault(x => x.idcategory == idCate); cate.namecategory = nameCate; cate.orther = other; db.SubmitChanges(); return(true); } } catch (Exception) { return(false); } }
public void EditFoodCategory(FoodCategory foodCategory) { Guard.WhenArgument(foodCategory, "foodCategory").IsNull().Throw(); this.data.FoodCategories.Update(foodCategory); this.data.SaveChanges(); }
public void RenderTheRightView_EditFoodCategory_WhenValidGuidIdIsPassed() { //Arrange var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); var mappingServiceMock = new Mock <IMappingService>(); var controller = new FoodCategoriesController(foodCategoriesServiceMock.Object, mappingServiceMock.Object); var id = Guid.NewGuid(); var name = "Tomatos"; var foodType = FoodType.Vegetable; var measuringUnit = MeasuringUnitType.Kg; var foodcategory = new FoodCategory() { Id = id, Name = name, FoodType = foodType, MeasuringUnit = measuringUnit }; foodCategoriesServiceMock.Setup(x => x.GetFoodCategoryById(id)).Returns(foodcategory); var model = new FoodCategoryViewModel(); model.Id = foodcategory.Id; model.Name = foodcategory.Name; model.FoodType = foodcategory.FoodType; model.MeasuringUnit = foodcategory.MeasuringUnit; mappingServiceMock.Setup(x => x.Map <FoodCategoryViewModel>(foodcategory)).Returns(model); //Act & Assert controller.WithCallTo(x => x.EditFoodCategory(id)) .ShouldRenderView("EditFoodCategory") .WithModel(model); }
public CreateFoodItem(string name, int weight, int quantity, int categoryId) { Name = name; Weight = weight; Quantity = quantity; CategoryId = (FoodCategory)categoryId; }
public void CallDataCommitMethodOnce_WhenParameterIngredientIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var ingredientPricePerMeasuringUnit = 1.5m; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, PricePerMeasuringUnit = ingredientPricePerMeasuringUnit }; var foodCategoryName = "Food Category Name"; var costOfAllCategoryIngredients = 0; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, CostOfAllCategoryIngredients = costOfAllCategoryIngredients }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); //Act foodCategoriesService.RemoveIngredientCostFromFoodCategory(ingredient); //Assert dataMock.Verify(x => x.SaveChanges(), Times.Once); }
public FoodCategory GetFoodCategory(int id) { FoodCategoryDTO foodCategoryDto = _repo.GetFoodCategory(id); FoodCategory foodCategory = _mapper.Map <FoodCategory>(foodCategoryDto); return(foodCategory); }
public async Task <ActionResult <FoodCategory> > PostFoodCategory(FoodCategory foodCategory) { if (string.IsNullOrEmpty(foodCategory.Name) || string.IsNullOrEmpty(foodCategory.Description) ) { return(BadRequest("Name and description are required.")); } string strMaxTblSize = _configuration["MaxTableSize"]; if (!string.IsNullOrEmpty(strMaxTblSize) && _context.FoodCategories.Count() > Convert.ToInt32(strMaxTblSize)) { return(BadRequest($"Number of records exceeded {strMaxTblSize}.")); } foodCategory.Name = System.Net.WebUtility.HtmlEncode(foodCategory.Name); foodCategory.Description = System.Net.WebUtility.HtmlEncode(foodCategory.Description); _context.FoodCategories.Add(foodCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFoodCategory", new { id = foodCategory.FoodCategoryId }, foodCategory)); }
public async Task <IActionResult> Edit(int id, [Bind("FoodCategoryId,FoodCategoryName")] FoodCategory foodCategory) { if (id != foodCategory.FoodCategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(foodCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FoodCategoryExists(foodCategory.FoodCategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(foodCategory)); }
public async Task updateFoodCategorizeFromServerAndUpdate( int foodCategorizeId, string name, Action <NetworkResponse> cbSuccessSent = null, Action <string> cbError = null ) { Action <NetworkResponse> newCBSuccessSent = delegate(NetworkResponse networkResponse) { if (networkResponse.Successful) { FoodCategory foodCategorizeCreated = JsonConvert.DeserializeObject <FoodCategory>(networkResponse.Data.ToString()); _foodCategorizeList[foodCategorizeCreated.FoodCategoryId] = foodCategorizeCreated; } cbSuccessSent?.Invoke(networkResponse); }; KeyValuePair <string, string>[] keys = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Name", name) }; await RequestManager.getInstance().putAsync( API_CONTROLLER + "/" + foodCategorizeId, keys, newCBSuccessSent, cbError ); }
private void txtFoodId_TextChanged(object sender, EventArgs e) { if (dgvFood.SelectedCells.Count > 0) { using var dbcontext = new QuanLyQuanCafeContext(); int?id = (int?)dgvFood.SelectedCells[0].OwningRow.Cells["IdCategory"].Value; if (id == null) { return; } FoodCategory category = dbcontext.FoodCategories.Where(x => id.Equals(x.Id)).SingleOrDefault(); cbFoodCategory.SelectedItem = category; int index = -1; int i = 0; foreach (FoodCategory item in cbFoodCategory.Items) { if (item.Id == category.Id) { index = i; break; } i++; } cbFoodCategory.SelectedIndex = index; } }
internal bool SaveFoodCategory(int FoodCategoryId, string FoodCategoryName, int?ParentCategoryId) { using (DataContext) { try { FoodCategory FoodCategory = DataContext.FoodCategories.SingleOrDefault(cat => cat.FoodCategoryId == FoodCategoryId); if (FoodCategory == null) { FoodCategory = new FoodCategory(); FoodCategory.FoodCategoryName = FoodCategoryName; FoodCategory.ParentCategoryId = ParentCategoryId; FoodCategory.CreatedDate = DateTime.Now; FoodCategory.ModifiedDate = DateTime.Now; FoodCategory.SortOrder = DataContext.FoodCategories.Max(cat => cat.SortOrder) + 1; DataContext.FoodCategories.Add(FoodCategory); //DataContext.FoodCategories.InsertOnSubmit(FoodCategory); } else { FoodCategory.FoodCategoryName = FoodCategoryName; FoodCategory.ParentCategoryId = ParentCategoryId; FoodCategory.ModifiedDate = DateTime.Now; } DataContext.SaveChanges(); //DataContext.SubmitChanges(); return(true); } catch { return(false); } } }
private void cboCategory_SelectedIndexChanged(object sender, EventArgs e) { string categoryID; ComboBox cbo = sender as ComboBox; if (cbo.SelectedItem == null) { return; } FoodCategory selected = cbo.SelectedItem as FoodCategory; categoryID = selected.ID; LoadMenu(agencyID); List <Control> list = new List <Control>(); foreach (Control control in flpMenu.Controls) { list.Add(control); } foreach (Control control in list) { if (String.Compare(((control.Tag) as DTO.Menu).CategoryID.ToString(), categoryID, true) != 0) { flpMenu.Controls.Remove(control); control.Dispose(); } } }
// PUT api/FoodCategory/5 public IHttpActionResult PutFoodCategory(int id, FoodCategory foodcategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != foodcategory.FoodCategoryId) { return(BadRequest()); } db.Entry(foodcategory).State = System.Data.Entity.EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FoodCategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
internal bool SaveFoodCategory(FoodCategory FoodCategory) { using (DataContext) { try { if (!DataContext.FoodCategories.Contains(FoodCategory)) { FoodCategory.CreatedDate = DateTime.Now; FoodCategory.SortOrder = DataContext.FoodCategories.Max(cat => cat.SortOrder) + 1; DataContext.FoodCategories.Add(FoodCategory); //DataContext.FoodCategories.InsertOnSubmit(FoodCategory); } else { string FoodCategoryName = FoodCategory.FoodCategoryName; int? ParentCategoryId = FoodCategory.ParentCategoryId; FoodCategory = DataContext.FoodCategories.Single(cat => cat.FoodCategoryId == FoodCategory.FoodCategoryId); FoodCategory.FoodCategoryName = FoodCategoryName; FoodCategory.ParentCategoryId = ParentCategoryId; } FoodCategory.ModifiedDate = DateTime.Now; DataContext.SaveChanges(); //DataContext.SubmitChanges(); return(true); } catch { return(false); } } }
public IActionResult SaveEntity(FoodCategory entity) { bool result = true; string message = string.Empty; var userEmail = User.GetSpecificClaim("Email"); if (ModelState.IsValid) { entity.UserModified = userEmail; if (entity.Id == 0) { entity.UserCreated = userEmail; _foodCategoryService.Add(entity, out result, out message); } else { _foodCategoryService.UpdateChangedProperties(entity, out result, out message); } return(new OkObjectResult(new GenericResult(result, message))); } else { List <string> listErrors = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage).ToList(); string errorString = String.Join("\n", listErrors.ToArray()); return(new OkObjectResult(new GenericResult(false, errorString))); } }
public void CallDataCommitMethodOnce_WhenParameterIngredientIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var quantityInMeasuringUnit = 1.5; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, QuantityInMeasuringUnit = quantityInMeasuringUnit }; var foodCategoryName = "Food Category Name"; var quantityOfAllIngredientsInTheCategory = 0; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, QuantityOfAllCategoryIngredients = quantityOfAllIngredientsInTheCategory }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); //Act foodCategoriesService.AddIngredientQuantityToFoodCategory(ingredient); //Assert dataMock.Verify(x => x.SaveChanges(), Times.Once); }
public int PostFoodCategory(FoodCategory foodCategory) { FoodCategoryDTO foodCategoryDto = Mapper.Map <FoodCategoryDTO>(foodCategory); int id = _repo.Post(foodCategoryDto); return(id); }
public ActionResult DeleteConfirmed(int id) { FoodCategory foodCategory = FoodCategoryService.Get(id); FoodCategoryService.Remove(foodCategory); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(FoodCategoryViewModel foodCategoryViewModel) { var userinfo = JsonConvert.DeserializeObject <Mess>(HttpContext.Session.GetString("sessionUser1234")); int id = userinfo.MessId; if (ModelState.IsValid) { FoodCategory fc = new FoodCategory { FoodCategoryName = foodCategoryViewModel.foodCategory.FoodCategoryName, MessId = id }; _context.Add(fc); await _context.SaveChangesAsync(); if (!String.IsNullOrEmpty(foodCategoryViewModel.Referer)) { return(Redirect(foodCategoryViewModel.Referer)); } // return RedirectToAction(nameof(Index)); } return(View(foodCategoryViewModel)); }
public FoodCategory getFoodCategoryByName(string name) { DataTable data = DataProvider.Instance.ExecuteQuery("EXEC dbo.USP_Get_FoodCategory_By_Name @name", new object[] { name }); FoodCategory foodCategory = new FoodCategory(data.Rows[0]); return(foodCategory); }
public void RemoveIngredientsPriceFromFoodCategory() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var ingredientPricePerMeasuringUnit = 1.5m; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, PricePerMeasuringUnit = ingredientPricePerMeasuringUnit }; var foodCategoryName = "Food Category Name"; var costOfAllCategoryIngredients = 1.5m; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, CostOfAllCategoryIngredients = costOfAllCategoryIngredients }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); var expectedResult = 0; //Act foodCategoriesService.RemoveIngredientCostFromFoodCategory(ingredient); //Assert Assert.AreEqual(expectedResult, foodCategory.CostOfAllCategoryIngredients); }
// check if a category with the same name already exists private Boolean isFoodCategoryPresent(String fcName) { Boolean result = true; FoodCategory fc; try { lblMessage.Text = ""; using (CCSEntities db = new CCSEntities()) { fc = (from category in db.FoodCategories where category.CategoryType.Equals(fcName) select category).FirstOrDefault(); } if (fc == null) result = false; else if (fc.FoodCategoryID == int.Parse(lblID.Text)) result = false; } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("../errorpages/error.aspx"); } return result; }
protected void btnDelete_Click(object sender, EventArgs e) { LinkButton btn = sender as LinkButton; if (!string.IsNullOrEmpty(btn.Attributes["depId"])) { int departmentId = int.Parse(btn.Attributes["depId"]); ShopDepartment sd = BusinessFacade.Instance.GetShopDepartment(departmentId); string name = string.Empty; if (sd != null) { name = sd.ShopDepartmentName; } if (BusinessFacade.Instance.DeleteShopDepartment(departmentId)) { FoodCategory f = BusinessFacade.Instance.GetFoodCategoryByName(name); if (f != null) { BusinessFacade.Instance.DeleteFoodCategory(f.FoodCategoryId); } this.Rebind(); } } }
public IActionResult AddFoodCategory2(FoodCategory fc) { var restaurant = _db.Restaurants.Where(r => r.Id == fc.RestaurantId).Include(r => r.FoodCategories).ThenInclude(fc => fc.Foods).FirstOrDefault(); if (restaurant.FoodCategories.Any(sfc => sfc.Name == fc.Name)) { var savedFc = restaurant.FoodCategories.Where(sfc => sfc.Name == fc.Name).FirstOrDefault(); fc.Foods.ForEach(food => { Food _food = new Food() { Name = food.Name, Price = food.Price, Allergenes = food.Allergenes, PreparationTime = food.PreparationTime }; savedFc.Foods.Add(_food); }); } else { restaurant.FoodCategories.Add(fc); _db.Add(fc); } _db.SaveChanges(); return(Ok()); }
public void RemoveIngredientsQuantityFromFoodCategory() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var quantityInMeasuringUnit = 1.5; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, QuantityInMeasuringUnit = quantityInMeasuringUnit }; var foodCategoryName = "Food Category Name"; var quantityOfAllIngredientsInTheCategory = 1.5; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, QuantityOfAllCategoryIngredients = quantityOfAllIngredientsInTheCategory }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); //Act foodCategoriesService.RemoveIngredientQuantityFromFoodCategory(ingredient); //Assert Assert.AreEqual(foodCategory.QuantityOfAllCategoryIngredients, 0); }
public void ReturnTheCostOfTheFoodCategoriesPasses_WhenThePassedParameter_FoodCategoriesOfActiveDailyMenus_IsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); var recipesServiceMock = new Mock <IRecipesService>(); DailyMenuService dailyMenuService = new DailyMenuService(dataMock.Object, recipesServiceMock.Object); var foodCategories = new List <FoodCategory>(); var firstFoodCategory = new FoodCategory() { Id = Guid.NewGuid(), Name = "First Food Category", CostOfAllCategoryIngredients = 9.99m, QuantityOfAllCategoryIngredients = 1.234 }; var secondFoodCategory = new FoodCategory() { Id = Guid.NewGuid(), Name = "Second Food Category", CostOfAllCategoryIngredients = 1m, QuantityOfAllCategoryIngredients = 1 }; foodCategories.Add(firstFoodCategory); foodCategories.Add(secondFoodCategory); var expectedResult = firstFoodCategory.CostOfAllCategoryIngredients + secondFoodCategory.CostOfAllCategoryIngredients; //Act var actualResult = dailyMenuService.CalculateShoppingListCostForActiveDailyMenus(foodCategories); Assert.AreEqual(expectedResult, actualResult); }
private void addFoodCategory() { try { lblMessage.Text = ""; Decimal caseWeight; using (CCSEntities db = new CCSEntities()) { FoodCategory fc = new FoodCategory(); // create a new food category with the specified name if (txtAddFoodType.Text == "") lblMessage.Text = "You must specify a Food Category name to add."; else if (txtAddFoodType.Text.Length > 30) lblMessage.Text = "The Food Category name cannot exceed 30 characters."; else if (isFoodCategoryPresent(txtAddFoodType.Text)) lblMessage.Text = "A Food Category with that name already exists."; else if (txtCaseWeight.Text.Length != 0 && !Decimal.TryParse(txtCaseWeight.Text, out caseWeight)) // If CaseWeight isn't empty, it must be a decimal lblMessage.Text = "You must enter a valid weight per case."; else if(txtCaseWeight.Text.Length != 0 && Decimal.Parse(txtCaseWeight.Text) < 0) // if used, cannot be negative lblMessage.Text = "Weight per case cannot be negative."; else { fc.CategoryType = txtAddFoodType.Text; if (txtCaseWeight.Text.Length != 0) fc.CaseWeight = Decimal.Parse(txtCaseWeight.Text); if (cbPerishable.Checked) fc.Perishable = true; else fc.Perishable = false; if (cbNonFood.Checked) fc.NonFood = true; else fc.NonFood = false; db.FoodCategories.Add(fc); // add the new food category record db.SaveChanges(); LogChange.logChange("Added food category called " + fc.CategoryType + ".", DateTime.Now, short.Parse(Session["UserID"].ToString())); if (pageTarget != null) { if (passedfoodInInfo != null) { Session["PassedFoodInInfo"] = passedfoodInInfo; } Response.Redirect(pageTarget); } else { Response.Redirect("default.aspx"); } } } } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("../errorpages/error.aspx"); } }
private void updateFoodCategory() { try { lblMessage.Text = ""; id = Int16.Parse(lblID.Text); Decimal caseWeight; using (CCSEntities db = new CCSEntities()) { // ensure that the record is selected fc = (from category in db.FoodCategories where category.FoodCategoryID == id select category).FirstOrDefault(); if (fc != null) { if (txtName.Text == "") // check if name is empty lblMessage.Text = "You must enter a Food Category Name"; else if (txtName.Text.Length > 30) lblMessage.Text = "The Food Category Name cannot be longer that 30 characters."; else if (isFoodCategoryPresent(txtName.Text)) lblMessage.Text = "A Food Category with that name already exists"; else if (txtCaseWeight.Text.Length != 0 && !Decimal.TryParse(txtCaseWeight.Text, out caseWeight)) // If CaseWeight isn't empty, it must be a decimal lblMessage.Text = "You must enter a valid weight per case."; else if (txtCaseWeight.Text.Length != 0 && Decimal.Parse(txtCaseWeight.Text) < 0) // if used, cannot be negative lblMessage.Text = "Weight per case cannot be negative."; else { fc.CategoryType = txtName.Text; // update name fc.Perishable = cbPerishable.Checked; // update perishable status fc.NonFood = cbNonFood.Checked; // update non food status if (txtCaseWeight.Text.Length == 0) // if empty, make it blank fc.CaseWeight = null; else // else, use whatever is in the text field fc.CaseWeight = Decimal.Parse(txtCaseWeight.Text); db.SaveChanges(); // commit LogChange.logChange("Edited food category called " + fc.CategoryType + ".", DateTime.Now, short.Parse(Session["UserID"].ToString())); Response.Redirect("default.aspx"); } } else lblMessage.Text = "An unexpected problem occurred: Please try again later."; } } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("../errorpages/error.aspx"); } }
private void removeFoodCategory() { try { lblMessage.Text = ""; id = Int16.Parse(lblID.Text); using (CCSEntities db = new CCSEntities()) { // ensure that the record is selected fc = (from category in db.FoodCategories where category.FoodCategoryID == id select category).FirstOrDefault(); if (fc != null) { String categoryName = fc.CategoryType; // saved for logging purposes db.FoodCategories.Remove(fc); // remove specified record db.SaveChanges(); // commit changes LogChange.logChange("Removed food category called " + categoryName + ".", DateTime.Now, short.Parse(Session["UserID"].ToString())); Response.Redirect("default.aspx"); } else lblMessage.Text = "An unexpected problem occurred: Please try again later."; } } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("../errorpages/error.aspx"); } }
private void loadFoodCategory() { try { lblMessage.Text = ""; if (Request.QueryString["id"] != null) id = int.Parse(Request.QueryString["id"]); else Response.Redirect("default.aspx"); using (CCSEntities db = new CCSEntities()) { fc = (from category in db.FoodCategories where category.FoodCategoryID == id select category).FirstOrDefault(); } if (fc != null) { lblID.Text = id.ToString(); txtName.Text = fc.CategoryType; cbPerishable.Checked = fc.Perishable; cbNonFood.Checked = fc.NonFood; txtCaseWeight.Text = fc.CaseWeight == null ? "" : fc.CaseWeight.ToString(); } else lblMessage.Text = "The Food Category with ID " + id + " could not be found."; } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("../errorpages/error.aspx"); } }
public Food(FoodCategory category) { _category = category; }