void SavePhotoClicked() { PhotoItemObject.PhotoLabel = PhotoLabel; PhotoLabel = null; if (NewCategory != null) { AllCategories.Add(new Category(NewCategory, true)); PickerSource.Add(NewCategory); MapCategorySource.Add(NewCategory); SaveCategoriesToJson(); } var selectedCategories = (from category in AllCategories where category.IsChecked select category.Name).ToList <string>(); // apply categories to most recent picture PhotoItemObject.Categories = selectedCategories; SaveToJson(); // reset category picker for (int i = 0; i < AllCategories.Count; i++) { AllCategories[i].IsChecked = false; } PreviewImage = null; IsPhotoSet = false; OnPropertyChanged("IsPhotoSet"); NewCategory = null; OnPropertyChanged("NewCategory"); }
// open category picker page async Task SwipedRightCategorize(object commandParameter) { // reset for (int i = 0; i < AllCategories.Count; i++) { AllCategories[i].IsChecked = false; } PhotoItemObject = (PhotoItem)commandParameter; for (int i = 0; i < AllCategories.Count; i++) { if (Array.IndexOf(PhotoItemObject.Categories.ToArray(), AllCategories[i].Name) != -1) { AllCategories[i].IsChecked = true; } } // show popup page var page = new PopupListView(); page.BindingContext = this; await PopupNavigation.Instance.PushAsync(page); if (NewCategory != null) { AllCategories.Add(new Category(NewCategory, true)); PickerSource.Add(NewCategory); MapCategorySource.Add(NewCategory); NewCategory = null; OnPropertyChanged("NewCategory"); SaveCategoriesToJson(); } }
public OrdersViewModel() { AllCategories = ComboBoxService.GetOptions(ComboBoxTargets.ProductCategories); AllCategories.Add(new NameID { Name = "All", ID = -1 }); CurrentCategory = AllCategories.Last(); }
internal void AddCategory(ModelCategory modelParentCategory, ModelCategory modelCategory) { AllCategories.Add(modelCategory); modelParentCategory.Childs.Add(modelCategory); modelCategory.Parent = modelParentCategory; DacFactory.Current.Category.AddCategory(modelCategory); if (OnCategoryAdded != null) { OnCategoryAdded(modelCategory); } }
private static List <string> takeCategories(StreamReader file) { string categoryHeader = file.ReadLine()?.Substring(9) ?? ""; List <string> result = categoryHeader.Split(" ").ToList(); foreach (string category in result) { if (AllCategories.Find(cat => cat == category) == null) { AllCategories.Add(category); } } return(result); }
private void InitData() { foreach (BuiltInCategory enumCat in Enum.GetValues(typeof(BuiltInCategory))) { try { FilteredElementCollector collector = new FilteredElementCollector(Rvt.Handler.Doc); ElementCollection elemC = new ElementCollection(collector.OfCategory(enumCat).ToList()); Category category = Category.GetCategory(Rvt.Handler.Doc, enumCat); if (elemC != null && elemC.Count > 0 && category != null && category.CategoryType == CategoryType.Model) { AllCategories.Add(new CategoryNode(category, elemC)); } } catch { continue; } } }
public void AddCategory() { try { using (var ctx = new ServerContext()) { this.CreatedCategory.name = this.CategoryName; ctx.Category.Add(this.CreatedCategory); ctx.SaveChanges(); } AllCategories.Add(CreatedCategory); this.CreatedCategory = new Category(); } catch (System.Data.DataException) { PopupService.PopupMessage(Application.Current.FindResource("CouldNotConnectToDatabase").ToString(), Application.Current.FindResource("Error").ToString()); } }
public static void AddNewCategory(Category category) { AllCategories.Add(category); }
// constructor public PhotoViewModel() { // path of the file in the phone that stores the photo objects JsonFilePath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData), "photos.json"); CategoryFilePath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData), "categories.json"); /* * * if (File.Exists(JsonFilePath)) * { * File.Delete(JsonFilePath); * } * if (File.Exists(CategoryFilePath)) * { * File.Delete(CategoryFilePath); * } * return; */ try { if (!File.Exists(JsonFilePath)) { // first time setup FileStream stream = new FileStream(JsonFilePath, FileMode.Create); StreamWriter writer = new StreamWriter(stream); writer.WriteLine("[]"); writer.Close(); } else { // already have photo objects FileStream stream = new FileStream(JsonFilePath, FileMode.Open); StreamReader reader = new StreamReader(stream); string fileContents = reader.ReadToEnd(); reader.Close(); AllPhotos = JsonConvert.DeserializeObject <List <PhotoItem> >(fileContents); PhotoSource = new ObservableCollection <PhotoItem>(AllPhotos); } // read categories file if (!File.Exists(CategoryFilePath)) { // first time setup FileStream stream = new FileStream(CategoryFilePath, FileMode.Create); StreamWriter writer = new StreamWriter(stream); writer.WriteLine("[]"); writer.Close(); } else { /* * List<string> s = new List<string> { "Foo", "Bar"}; * FileStream ss = new FileStream(CategoryFilePath, FileMode.Create); * StreamWriter writer = new StreamWriter(ss); * writer.WriteLine(JsonConvert.SerializeObject(s)); * writer.Close(); */ // already have categories FileStream stream = new FileStream(CategoryFilePath, FileMode.Open); StreamReader reader = new StreamReader(stream); string fileContents = reader.ReadToEnd(); Console.WriteLine("g" + fileContents); reader.Close(); List <string> fileCategories = JsonConvert.DeserializeObject <List <string> >(fileContents); var categoryObjects = from category in fileCategories select new Category(category); foreach (string x in fileCategories) { MapCategorySource.Add(x); PickerSource.Add(x); } PickerSource.Add("Location"); PickerSource.Add("Rating"); PickerSource.Add("Time"); foreach (var x in PickerSource) { Console.WriteLine(x); } AllCategories = new ObservableCollection <Category>(categoryObjects); } } catch (Exception ex) { Console.WriteLine("Exception " + ex.Message); } InitialCategorizeCommand = new Command( execute: async() => { await InitialCategorize(); }, canExecute: () => { return(true); }); PrintCommand = new Command( execute: () => { PrintJsonFile(); }, canExecute: () => { return(true); }); SaveLabelCommand = new Command( execute: (obj) => { PhotoItem temp = (PhotoItem)obj; }); PopupCommand = new Command( execute: async() => { // show popup to categorize photo await PopupNavigation.Instance.PopAsync(); if (NewCategory != null) { AllCategories.Add(new Category(NewCategory, true)); PickerSource.Add(NewCategory); MapCategorySource.Add(NewCategory); NewCategory = null; OnPropertyChanged("NewCategory"); SaveCategoriesToJson(); } PhotoItemObject.Categories = (from category in AllCategories where category.IsChecked select category.Name).ToList(); SaveToJson(); }, canExecute: () => { return(true); }); LoadPhotoCommand = new Command( execute: async() => { var photo = await Plugin.Media.CrossMedia.Current.PickPhotoAsync( new Plugin.Media.Abstractions.PickMediaOptions { CompressionQuality = 50, PhotoSize = Plugin.Media.Abstractions.PhotoSize.Large }); await SetNewPhoto(photo); }, canExecute: () => { return(true); }); TakePhotoCommand = new Command( execute: async() => { var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync( new Plugin.Media.Abstractions.StoreCameraMediaOptions { SaveToAlbum = true }); await SetNewPhoto(photo); }, canExecute: () => { return(true); }); SavePhotoCommand = new Command( execute: () => { SavePhotoClicked(); }, canExecute: () => { return(true); }); RatingCommand = new Command( execute: () => { IsRating = !IsRating; IsCategorize = false; }, canExecute: () => { return(true); }); CategorizeCommand = new Command( execute: () => { IsCategorize = !IsCategorize; IsRating = false; }, canExecute: () => { return(true); }); SwipeCommandLeft = new Command( execute: (obj) => { if (isRating) { SwipedLeftRating(obj); } else if (isCategorize) { SwipedLeftCategorize(obj); } }, canExecute: (obj) => { return(true); }); SwipeCommandRight = new Command( execute: (obj) => { if (isRating) { SwipedRightRating(obj); } else if (isCategorize) { SwipedRightCategorize(obj); } }, canExecute: (obj) => { return(true); }); }