public async Task UpdateItem(Expense item, string username) { var user = _accountRepository.FindByName(username); if (user == null) { return; } item.Owner = user; item.Date = DateTime.Now; if (item.Category == null) { return; } item.Category = await _categoryRepository.GetAll().FirstAsync(x => x.Id == item.Category.Id); if (GetAll().Select(x => x.Id).ToList().Contains(item.Id)) { item.SubCategory = GetSubCategory(item.Category.Id, item.SubCategory.Name); Update(item); } else { Add(item); } }
public IQueryable <ContactCategory> GetCategories(bool withManageData = false) { var list = _categoryRepository.GetAll().OrderBy(x => x.Name); if (!withManageData) { return(list); } foreach (var l in list) { l.IsEmpty = !GetItems(0, l.Id, string.Empty).Any(); } return(list); }
public JsonNetResult GetSubCategoryNames(int categoryId) { return(new JsonNetResult(_subCategoryRepository.GetAll() .Where(x => x.Category.Id == categoryId) .OrderBy(x => x.Name) .Select(x => x.Name))); }
private SubCategory GetSubCategory(int categoryId, string subCategoryName) { var subs = _subCategoryRepository.GetAll() .Where(x => x.Category.Id == categoryId && x.Name == subCategoryName); if (!subs.Any()) { _subCategoryRepository.Add(new SubCategory { Name = subCategoryName, Description = String.Empty, Category = _categoryRepository.GetAll().First(x => x.Id == categoryId), }); } return((subs.Any()) ? subs.First() : _subCategoryRepository.GetAll().First(x => x.Category.Id == categoryId && x.Name == subCategoryName)); }