/// <summary> /// Deletes a KnifeStore from it's list and calls the database operation to syncronhize them. /// </summary> /// <param name="list">The entity list where the entity should be deleted from.</param> /// <param name="knifeStore">The entity which is intended to delete.</param> public void DelKnifeStore(IList <KnifeStore> list, KnifeStore knifeStore, string token) { try { if (knifeStore != null) { string api = hostSettings.Address() + $"KnifeStore" + $"/{knifeStore.StorageId}"; WebRequest request = WebRequest.Create(api); request.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}"; request.Method = "DELETE"; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); } catch (Exception ex) { if (ex.Message.ToString().Contains("403")) { this.messengerService.Send("TÖRLÉS SIKERTELEN\nNINCS ENGEDÉLYE EHHEZ", "LogicResult"); return; } this.messengerService.Send("TÖRLÉS SIKERTELEN", "LogicResult"); return; } list.Remove(knifeStore); this.messengerService.Send("TÖRLÉS SIKERES", "LogicResult"); return; } } catch { this.messengerService.Send("TÖRLÉS SIKERTELEN", "LogicResult"); return; } }
/// <summary> /// Modifies an element of the knifeStore list as intended. /// </summary> /// <param name="knifeStoreToModify">The KnifeStore entity which should be modified.</param> public void ModKnifeStore(KnifeStore knifeStoreToModify, string token) { if (knifeStoreToModify == null) { this.messengerService.Send("MÓDOSÍTÁS SIKERTELEN", "LogicResult"); return; } KnifeStore clone = new KnifeStore(); clone.CopyFrom(knifeStoreToModify); if (this.editorService.EditKnifeStore(clone) == true) { knifeStoreToModify.CopyFrom(clone); Kes_Bolt kb = new Kes_Bolt() { Raktar_Id = clone.StorageId, Bolt_Nev = clone.Name, Cim = clone.Address, Weboldal = clone.Website, }; string api = hostSettings.Address() + $"KnifeStore" + $"/{knifeStoreToModify.StorageId}"; try { WebClient wc = new WebClient(); var json = JsonConvert.SerializeObject(kb); wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}"; wc.Headers[HttpRequestHeader.ContentType] = "application/json"; wc.UploadString(api, "PUT", json); } catch (Exception ex) { if (ex.Message.ToString().Contains("403")) { this.messengerService.Send("MÓDOSÍTÁS SIKERTELEN\nNINCS ENGEDÉLYE EHHEZ", "LogicResult"); return; } this.messengerService.Send("MÓDOSÍTÁS SIKERTELEN", "LogicResult"); return; } //this.knifeStoreLogic.UpdateKes_Bolt(knifeStoreToModify.StorageId, kb); this.messengerService.Send("MÓDOSÍTÁS SIKERES", "LogicResult"); return; } this.messengerService.Send("MÓDOSÍTÁS MEGSZAKÍTVA", "LogicResult"); }
/// <summary> /// Initializes a new instance of the <see cref="EditorViewModel"/> class. /// Constructor which sets up a new entity fills it in designer mode. /// </summary> public EditorViewModel() { this.knifeStore = new KnifeStore(); this.knife = new Knife(); this.review = new Review(); if (this.IsInDesignMode) { // KnifeStore sample // knifeStore.StorageId = Guid.NewGuid(); //this is not needed for preview this.knifeStore.Name = "BladeHQ"; this.knifeStore.Address = "Random strt 8."; this.KnifeStore.Website = "www.bladehq.com"; // Knife sample this.knife.Steel = "S30V"; this.knife.Model = "Paramilitary 2"; this.knife.Maker = "Spyderco"; this.knife.Coated = false; this.Knife.Price = 65000; this.knife.BladeLength = 90; this.knife.Handle = "G10"; } }
/// <summary> /// Adds a new KnifeStore to it's list and calls the database operation to syncronhize them. /// </summary> /// <param name="list">The entity list where the entity should be added.</param> public void AddKnifeStore(IList <KnifeStore> list, string token) { try { KnifeStore newKnifeStore = new KnifeStore(); if (this.editorService.EditKnifeStore(newKnifeStore) == true) { Kes_Bolt kb = new Kes_Bolt() { Raktar_Id = string.Empty, Bolt_Nev = newKnifeStore.Name, Cim = newKnifeStore.Address, Weboldal = newKnifeStore.Website, }; string api = hostSettings.Address() + $"KnifeStore"; WebClient wc = new WebClient(); wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}"; var json = JsonConvert.SerializeObject(kb); wc.Headers[HttpRequestHeader.ContentType] = "application/json"; wc.UploadString(api, "POST", json); this.messengerService.Send("HOZZÁADÁS SIKERES", "LogicResult"); return; } } catch (Exception ex) { if (ex.Message.ToString().Contains("403")) { this.messengerService.Send("HOZZÁADÁS SIKERTELEN\nNINCS ENGEDÉLYE EHHEZ", "LogicResult"); return; } this.messengerService.Send("HOZZÁADÁS SIKERTELEN", "LogicResult"); return; } this.messengerService.Send("HOZZÁADÁS MEGSZAKÍTVA", "LogicResult"); }
/// <summary> /// Gets all the KesBolt elements from the database converts it to KnifeStore objects. /// </summary> /// <returns>All the KnifeStore entities from the database.</returns> public IList <KnifeStore> GetAllKnifeStore(string token) { ObservableCollection <KnifeStore> knifeStores = new ObservableCollection <KnifeStore>(); try { string api = hostSettings.Address() + $"KnifeStore"; WebClient wc = new WebClient(); wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}"; string jsonContent = wc.DownloadString(api); IQueryable <Kes_Bolt> kbs = JsonConvert.DeserializeObject <List <Kes_Bolt> >(jsonContent).AsQueryable(); //IQueryable<Kes_Bolt> kbs = this.knifeStoreLogic.GetAllKes_Bolt(); if (kbs == null) { return(knifeStores); } foreach (var item in kbs) { KnifeStore ks = new KnifeStore() { StorageId = item.Raktar_Id, Name = item.Bolt_Nev, Address = item.Cim, Website = item.Weboldal, }; knifeStores.Add(ks); } } catch { this.messengerService.Send("A SZERVER NEM TALÁLHATÓ", "LogicResult"); throw; } return(knifeStores); }
/// <summary> /// Initializes a new instance of the <see cref="KnifeStoreEditorWindow"/> class. /// Constructor needed to edit elements. /// </summary> /// <param name="oldKnifeStore">The item which is edited.</param> public KnifeStoreEditorWindow(KnifeStore oldKnifeStore) : this() { this.vM.KnifeStore = oldKnifeStore; }
/// <inheritdoc/> public bool EditKnifeStore(KnifeStore k) { KnifeStoreEditorWindow win = new KnifeStoreEditorWindow(k); return(win.ShowDialog() ?? false); }
public MainViewModel(IKnifeStoreLogic knifeStoreLogic, IKnifeLogic knifeLogic, IReviewLogic reviewLogic, IHostSettings hostSettings) { this.knifeStoreLogic = knifeStoreLogic; this.knifeLogic = knifeLogic; this.reviewLogic = reviewLogic; this.hostSettings = hostSettings; if (!this.IsInDesignMode) { } else { this.KnifeStores = new ObservableCollection <KnifeStore>(); KnifeStore ks1 = new KnifeStore() { Address = "Random Strt 8.", Name = "BladeHQ", Website = "www.bladehq.com" }; KnifeStore ks2 = new KnifeStore() { Address = "Random Strt 69.", Name = "KnifeCenter", Website = "www.knifecenter.com" }; KnifeStore ks3 = new KnifeStore() { Address = "Random Strt 12.", Name = "Boker", Website = "www.boker.de" }; KnifeStore ks4 = new KnifeStore() { Address = "Random Strt 9.", Name = "BladeShop", Website = "www.bladeshop.hu" }; KnifeStore ks5 = new KnifeStore() { Address = "Random Strt 617.", Name = "KnivesAndtools", Website = "www.knivesandtools.uk" }; this.KnifeStores.Add(ks1); this.KnifeStores.Add(ks2); this.KnifeStores.Add(ks3); this.KnifeStores.Add(ks4); this.KnifeStores.Add(ks5); } this.AddKnifeStoreCmd = new RelayCommand(() => { this.knifeStoreLogic.AddKnifeStore(this.KnifeStores, token); RefreshKnifeStores(); }, true); this.ModKnifeStoreCmd = new RelayCommand(() => this.knifeStoreLogic.ModKnifeStore(this.SelectedKnifeStore, token), true); this.DelKnifeStoreCmd = new RelayCommand(() => { this.knifeStoreLogic.DelKnifeStore(this.KnifeStores, this.SelectedKnifeStore, token); Knives = new ObservableCollection <Knife>(); Reviews = new ObservableCollection <Review>(); }, true); this.AddKnifeCmd = new RelayCommand(() => { this.knifeLogic.AddKnife(this.Knives, selectedKnifeStore == null ? string.Empty : selectedKnifeStore.StorageId, token); RefreshKnives(); }, true); this.ModKnifeCmd = new RelayCommand(() => this.knifeLogic.ModKnife(SelectedKnife, token), true); this.DelKnifeCmd = new RelayCommand(() => { this.knifeLogic.DelKnife(Knives, SelectedKnife, token); Reviews = new ObservableCollection <Review>(); }, true); this.AddReviewCmd = new RelayCommand(() => { this.reviewLogic.AddReview(this.Reviews, selectedKnife == null ? string.Empty : SelectedKnife.SerialNumber, token); RefreshReview(); }, true); this.ModReviewCmd = new RelayCommand(() => this.reviewLogic.ModReview(SelectedReview, token), true); this.DelReviewCmd = new RelayCommand(() => this.reviewLogic.DelReview(Reviews, SelectedReview, token), true); this.GenerateCmd = new RelayCommand(() => GenerateSample(), true); this.UpdateCmd = new RelayCommand(() => RefreshKnifeStores(), true); this.GetKnives = new RelayCommand(() => { RefreshKnives(); Reviews = new ObservableCollection <Review>(); selectedReview = null; }, true); this.GetReviews = new RelayCommand(() => RefreshReview(), true); this.UpdateToken = new RelayCommand(() => SetToken(), true); }