Пример #1
0
		private void UpdateCurrentCategory2()
		{
			if (_categories != null && _currentCategoryId != null)
			{
				CurrentCategory = _categories.FirstOrDefault(cat => cat.Id == _currentCategoryId);
			}
			else
			{
				CurrentCategory = null;
			}
		}
Пример #2
0
		private static void UpdateFldDscs(Category target, IList<FieldDescription> allFldDscs)
		{
			if (target != null)
			{
				// populate FieldDescriptions
				List<FieldDescription> newFldDscs = new List<FieldDescription>();
				foreach (var fldDscId in target._fieldDescriptionIds)
				{
					var newFldDsc = allFldDscs.FirstOrDefault(fd => fd.Id == fldDscId);
					if (newFldDsc != null) newFldDscs.Add(newFldDsc);
				}
				//if (target.FieldDescriptions == null) target._fieldDescriptions = new SwitchableObservableCollection<FieldDescription>();
				target.FieldDescriptions.ReplaceAll(newFldDscs);
			}
		}
Пример #3
0
		internal static void Copy(Category source, ref Category target, IList<FieldDescription> allFldDscs)
		{
			if (source != null && target != null)
			{
				target._fieldDescriptionIds.ReplaceAll(source._fieldDescriptionIds);
				UpdateFldDscs(target, allFldDscs);
				//// populate FieldDescriptions
				//List<FieldDescription> newFldDscs = new List<FieldDescription>();
				//foreach (var fldDscId in source._fieldDescriptionIds)
				//{
				//	var newFldDsc = allFldDscs.FirstOrDefault(fd => fd.Id == fldDscId);
				//	if (newFldDsc != null) newFldDscs.Add(newFldDsc);
				//}
				//target.FieldDescriptions.ReplaceAll(newFldDscs);

				target.Id = source.Id;
				target.IsCustom = source.IsCustom;
				// target.IsJustAdded = source.IsJustAdded; // no!
				target.Name = source.Name;
			}
		}
Пример #4
0
		public Task SetCurrentCategoryAsync(Category newItem)
		{
			return RunFunctionIfOpenAsyncT(async delegate
			{
				var mbc = _briefcase?.MetaBriefcase;
				if (mbc == null) return;

				await mbc.SetCurrentCategoryAsync(newItem);
				await UpdateAssignedUnassignedFieldsAsync().ConfigureAwait(false);
			});
		}
Пример #5
0
		public async Task<bool> RemoveCategoryAsync(Category cat)
		{
			var mbc = _briefcase?.MetaBriefcase;
			if (mbc == null) return false;

			return await RunFunctionIfOpenAsyncTB(() => mbc.RemoveCategoryAsync(cat)).ConfigureAwait(false);
		}
Пример #6
0
		internal void RemoveFromJustAssignedToCats(Category cat)
		{
			if (cat?.Id != null && _justAssignedToCats != null && _justAssignedToCats.Contains(cat.Id))
			{
				_justAssignedToCats.Remove(cat.Id);
				RaisePropertyChanged_UI(nameof(JustAssignedToCats)); // in case someone wants to bind to it
			}
		}
Пример #7
0
		public Task<bool> RemoveCategoryAsync(Category cat)
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				if (cat != null && (cat.IsJustAdded || IsElevated))
				{
					bool isRemoved = false;
					await RunInUiThreadAsync(() => isRemoved = _categories.Remove(cat)).ConfigureAwait(false);
					await _rubbishBin.AddCategoryAsync(cat);
					if (CurrentCategoryId == cat.Id && _categories.Any()) CurrentCategoryId = _categories[0]?.Id;
					return isRemoved;
				}
				else
				{
					return false;
				}
			});
		}
Пример #8
0
		private async Task<bool> AddCategory2Async(Category newCat)
		{
			if (Category.Check(newCat) && !Categories.Any(cat => cat.Name == newCat.Name || cat.Id == newCat.Id))
			{
				await RunInUiThreadAsync(() => _categories.Add(newCat)).ConfigureAwait(false);
				return true;
			}
			return false;
		}
Пример #9
0
		public Task<bool> AddCategoryAsync(Category newCat)
		{
			return RunFunctionIfOpenAsyncTB(delegate
			{
				return AddCategory2Async(newCat);
			});
		}
Пример #10
0
		public Task<bool> AddNewCategoryAsync()
		{
			return RunFunctionIfOpenAsyncTB(delegate
			{
				string name = RuntimeData.GetText("NewCategory");
				var newCat = new Category(name, true, true);

				return AddCategory2Async(newCat);
			});
		}
Пример #11
0
		public Task SetCurrentCategoryAsync(Category cat)
		{
			return RunFunctionIfOpenAsyncA(delegate
			{
				if (cat != null)
				{
					CurrentCategoryId = cat.Id;
				}
			});
		}
Пример #12
0
		private List<Tuple<FieldDescription, FieldValue>> DeletedFieldValues { get { return _deletedFieldValues; } set { _deletedFieldValues = value; } } // the setter is only for the serialiser

		internal Task AddCategoryAsync(Category category)
		{
			if (category == null) return Task.CompletedTask;
			return RunFunctionIfOpenAsyncA(() =>
			{
				_deletedCategories.RemoveAll(cat => cat.Name == category.Name);
				_deletedCategories.Add(category);
			});
		}
Пример #13
0
		public static void Copy(SwitchableObservableCollection<Category> source, ref SwitchableObservableCollection<Category> target, IList<FieldDescription> allFldDscs)
		{
			if (source != null && target != null)
			{
				target.IsObserving = false;
				target.Clear();
				foreach (var sourceRecord in source)
				{
					var targetRecord = new Category();
					Copy(sourceRecord, ref targetRecord, allFldDscs);
					target.Add(targetRecord);
				}
				target.IsObserving = true;
			}
		}
Пример #14
0
		public static bool Check(Category cat)
		{
			return cat != null && cat.Id != DEFAULT_ID && cat.FieldDescriptions != null && cat.FieldDescriptionIds != null && !string.IsNullOrWhiteSpace(cat.Name);
		}
Пример #15
0
		public static void Copy(IList<Category> source, ref List<Category> target, IList<FieldDescription> allFldDscs)
		{
			if (source != null && target != null)
			{
				target.Clear();
				foreach (var sourceRecord in source)
				{
					var targetRecord = new Category();
					Copy(sourceRecord, ref targetRecord, allFldDscs);
					target.Add(targetRecord);
				}
			}
		}