Ejemplo n.º 1
0
        public SimpUser Auth(User u)
        {
            try
            {
                string    api  = hostSettings.Address() + $"Auth/Login";
                WebClient wc   = new WebClient();
                var       json = JsonConvert.SerializeObject(new { validationName = u.ValidationName, password = u.Password.Password });
                wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                var       response  = wc.UploadString(api, "PUT", json);
                TokenData tokendata = JsonConvert.DeserializeObject <TokenData>(response);

                api = hostSettings.Address() + $"Auth/GetUser/{u.ValidationName}";
                wc  = new WebClient();
                wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {tokendata.Token}";
                response = wc.DownloadString(api);
                SimpUser simpUser = JsonConvert.DeserializeObject <SimpUser>(response);
                simpUser.Token = tokendata.Token;

                this.messengerService.Send($"Bejelentkeztél {simpUser.UserName} névvel.", "AuthResult");
                return(simpUser);
            }
            catch (Exception ex)
            {
                this.messengerService.Send("BEJELENTKEZÉS SIKERTELEN", "AuthResult");
                return(new SimpUser());
            }
        }
Ejemplo n.º 2
0
 private void GenerateSample()
 {
     if (knifeStores.Count > 0)
     {
         if (MessageBox.Show("Már van generált adatod!\nSzeretnél ismét generálni?", "Hoppá!", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
         {
             return;
         }
     }
     try
     {
         string     api     = hostSettings.Address() + "SampleDataGenerator";
         WebRequest request = WebRequest.Create(api);
         request.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}";
         request.Method = "POST";
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         RefreshKnifeStores();
         Knives  = new ObservableCollection <Knife>();
         Reviews = new ObservableCollection <Review>();
     }
     catch (Exception ex)
     {
         if (ex.Message.ToString().Contains("403"))
         {
             MessageBox.Show("NINCS ENGEDÉLYE EHHEZ");
             return;
         }
         return;
     }
 }
Ejemplo n.º 3
0
        /// <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 AddKnife(IList <Knife> list, string selectedKnifeStoreId, string token)
        {
            if (selectedKnifeStoreId == null)
            {
                this.messengerService.Send("HOZZÁADÁS SIKERTELEN", "LogicResult");
            }
            Knife newKnife = new Knife();

            if ((selectedKnifeStoreId != null && selectedKnifeStoreId != string.Empty) && this.editorService.EditKnife(newKnife) == true)
            {
                Kes kb = new Kes()
                {
                    Gyartasi_Cikkszam = string.Empty,
                    Raktar_Id         = selectedKnifeStoreId,
                    Gyarto            = newKnife.Maker == null ? string.Empty : newKnife.Maker,
                    Bevont_Penge      = newKnife.Coated,
                    Acel        = newKnife.Steel == null ? string.Empty : newKnife.Steel,
                    Penge_Hossz = newKnife.BladeLength,
                    Ar          = newKnife.Price,
                    Markolat    = newKnife.Handle == null ? string.Empty : newKnife.Handle,
                    Modell_nev  = newKnife.Model == null ? string.Empty : newKnife.Model,
                };
                string    api  = hostSettings.Address() + $"Knife";
                WebClient wc   = new WebClient();
                var       json = JsonConvert.SerializeObject(kb);
                wc.Headers[HttpRequestHeader.ContentType]   = "application/json";
                wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}";
                try
                {
                    wc.UploadString(api, "POST", json);
                }
                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("HOZZÁADÁS SIKERTELEN", "LogicResult");
                    return;
                }
                this.messengerService.Send("HOZZÁADÁS SIKERES", "LogicResult");
                return;
            }

            this.messengerService.Send("HOZZÁADÁS MEGSZAKÍTVA", "LogicResult");
        }
Ejemplo n.º 4
0
        /// <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");
        }
Ejemplo n.º 5
0
 /// <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 AddReview(IList <Review> list, string selectedKnifeId, string token)
 {
     try
     {
         Review newReview = new Review();
         if ((selectedKnifeId != null && selectedKnifeId != string.Empty) && this.editorService.EditReview(newReview) == true)
         {
             Velemeny kb = new Velemeny()
             {
                 Velemeny_Id       = string.Empty,
                 VelemenySzovege   = newReview.ReviewText == null ? string.Empty : newReview.ReviewText,
                 Elegedettseg      = newReview.Rating,
                 Szerzo            = newReview.Author == null ? string.Empty : newReview.Author,
                 Gyartasi_Cikkszam = selectedKnifeId,
             };
             string    api  = hostSettings.Address() + $"Review";
             WebClient wc   = new WebClient();
             var       json = JsonConvert.SerializeObject(kb);
             wc.Headers[HttpRequestHeader.ContentType]   = "application/json";
             wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {token}";
             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;
     }
 }