public void CategoryDataAccess_CrudCategory() { var categoryDataAccess = new CategoryDataAccess(); const string firstName = "category"; const string secondName = "new category"; var category = new Category { Name = firstName }; categoryDataAccess.Save(category); categoryDataAccess.LoadList(); var list = categoryDataAccess.LoadList(); Assert.AreEqual(1, list.Count); Assert.AreEqual(firstName, list.First().Name); category.Name = secondName; categoryDataAccess.Save(category); list = categoryDataAccess.LoadList(); Assert.AreEqual(1, list.Count); Assert.AreEqual(secondName, list.First().Name); categoryDataAccess.Delete(category); list = categoryDataAccess.LoadList(); Assert.IsFalse(list.Any()); }
public void CategoryDataAccess_CrudCategory() { var categoryDataAccess = new CategoryDataAccess(new DbHelper(new SQLitePlatformWinRT(), new TestDatabasePath())); const string firstName = "category"; const string secondName = "new category"; var category = new Category { Name = firstName }; categoryDataAccess.Save(category); categoryDataAccess.LoadList(); var list = categoryDataAccess.LoadList(); Assert.AreEqual(1, list.Count); Assert.AreEqual(firstName, list.First().Name); category.Name = secondName; categoryDataAccess.Save(category); list = categoryDataAccess.LoadList(); Assert.AreEqual(1, list.Count); Assert.AreEqual(secondName, list.First().Name); categoryDataAccess.Delete(category); list = categoryDataAccess.LoadList(); Assert.IsFalse(list.Any()); }
/// <summary> /// Function to delete a CategoryEntity from database. /// </summary> /// <param name="categoryEntity">CategoryEntity to delete</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the CategoryEntity was deleted successfully, the same CategoryEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="categoryEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public CategoryEntity Delete(CategoryEntity categoryEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "delete", "Category"); if (!permited) { ExceptionDetail detail = new ExceptionDetail(new UtnEmall.Server.BusinessLogic.UtnEmallPermissionException("The user hasn't permissions to delete an entity")); throw new FaultException <ExceptionDetail>(detail); } if (categoryEntity == null) { throw new ArgumentException("The argument can not be null or be empty"); } try { // Delete categoryEntity using data access object categoryDataAccess.Delete(categoryEntity); // Delete related customers' preference PreferenceDataAccess preferenceDataAccess = new PreferenceDataAccess(); foreach (PreferenceEntity preferenceEntity in preferenceDataAccess.LoadWhere(PreferenceEntity.DBIdCategory, categoryEntity.Id, false, OperatorType.Equal)) { preferenceDataAccess.Delete(preferenceEntity); } return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
public ActionResult DeleteConfirm(int id) { if (CategoryDataAccess.Delete(id)) { return(Json(new { success = true, message = "Sukses" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = CategoryDataAccess.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Función para eliminar un CategoryEntity de la base de datos. /// </summary> /// <param name="categoryEntity">CategoryEntity a eliminar</param> /// <param name="session">Identificador de sesión.</param> /// <returns>null si el CategoryEntity fue eliminado con éxito, el mismo CategoryEntity en otro caso</returns> /// <exception cref="ArgumentNullException"> /// Si <paramref name="categoryEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// Si una excepción UtnEmallDataAccessException ocurre en el data model. /// </exception> public CategoryEntity Delete(CategoryEntity categoryEntity) { if (categoryEntity == null) { throw new ArgumentException("The argument can't be null", "categoryEntity"); } try { // Elimina un categoryEntity usando un objeto data access categoryDataAccess.Delete(categoryEntity); return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
private void btnDeleteCategory_Click(object sender, EventArgs e) { if (mlvCategories.FocusedItem != null) { if (!cda.Delete(cda.GetList().First(c => c.CategoryID == Convert.ToInt32(txtUpdateCategoryCategoryID.Text)))) { lblManageCategoryAlertSuccessfull.Visible = false; lblManageCategoryAlertFail.Visible = true; lblManageCategoryAlertFail.BringToFront(); } else { lblManageCategoryAlertFail.Visible = false; lblManageCategoryAlertSuccessfull.Visible = true; lblManageCategoryAlertSuccessfull.BringToFront(); } UpdateCategoryList(); } }
public ActionResult DeleteCategory(int id) { CATEGORY category = categoryDA.GetById(id); try { if (ModelState.IsValid) { categoryDA.Delete(id); return(RedirectToAction("Categories", "Admin")); } else { ViewBag.Error = "Try Again."; return(View("CategoryDelete", category)); } } catch (Exception ex) { ViewBag.Error = "Try Again."; return(View("CategoryDelete", category)); } }
public IActionResult DeleteCategory(Guid id) { _category.Delete(id); return(RedirectToAction("Index", "Category")); }