/// <summary> /// Archive Category /// </summary> /// <param name="category">Category to Archive</param> /// <returns>Count of affected rows</returns> public static int ArchiveCategory(Category category) { try { category.Archived = DateTime.Now; category.ArchiverId = LoggedUser.Id; var subCategories = DBCategories.GetList(LoggedUser, category.Id); int c = 0; foreach (var subCategory in subCategories) { subCategory.Archived = category.Archived; subCategory.ArchiverId = LoggedUser.Id; c += DBCategories.Update(subCategory); } c += DBCategories.Update(category); return(c); } catch (Exception ex) { throw ex; } }
/// <summary> /// Delete Category /// </summary> /// <param name="category">Category to Delete</param> /// <returns>Count of affected rows</returns> public static int DeleteCategory(Category category) { try { int c = DBCategories.Delete(category); if (c > 0) { category.Status = Status.Unchanged; } return(c); } catch (Exception) { throw; } }
/// <summary> /// Refresh Categories List /// </summary> /// <param name="loggedUser">Logged User</param> /// <param name="parentId">Parent Id (default Empty Guid)</param> /// <param name="includeArchived">If true archived users will be listed too (default false)</param> public static void RefreshCategories(User loggedUser, Guid parentId = default(Guid), bool includeArchived = false) { try { categories = new ObservableCollection <Category>(); var list = DBCategories.GetList(loggedUser, parentId, includeArchived); foreach (var item in list) { categories.Add(item); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Update Category /// </summary> /// <param name="category">Category to Update</param> /// <returns>Count of affected rows</returns> public static int UpdateCategory(Category category) { try { category.Modified = DateTime.Now; category.ModifierId = LoggedUser.Id; int c = DBCategories.Update(category); if (c > 0) { category.Status = Status.Unchanged; } return(c); } catch (Exception) { throw; } }
/// <summary> /// Create Category /// </summary> /// <param name="category">Category to Create</param> /// <returns>Count of affected rows</returns> public static int CreateCategory(Category category) { try { if (category.Id == Guid.Empty) { category.Id = Guid.NewGuid(); } category.Created = DateTime.Now; category.CreatorId = LoggedUser.Id; int c = DBCategories.Create(category); if (c > 0) { category.Status = Status.Unchanged; } return(c); } catch (Exception) { throw; } }