public async Task Init()
        {
            Model.Visitor r = null;
            r = await _service.GetById <Model.Visitor>(APIService._VisitorId);

            if (r != null)
            {
                _Name        = r.Name;
                _Surname     = r.Surname;
                _Address     = r.Address;
                _DateOfBirth = r.DateOfBirth;
                _PhoneNumber = r.PhoneNumber;
                _Username    = r.Username;
            }
        }
Exemple #2
0
        public async Task <IActionResult> Put(Model.Visitor newVisitor)
        {
            if (EnvController.Client == null)
            {
                return(BadRequest(new
                {
                    error = "SDK Client not initialized"
                }));
            }
            currentVisitor = newVisitor;
            var context = new Dictionary <string, object>();

            foreach (var item in newVisitor.Context)
            {
                context.Add(item.Key, ToObject(item.Value));
            }

            Visitor = EnvController.Client.NewVisitor(newVisitor.Id, context);
            await Visitor.SynchronizeModifications();

            var modifs = Visitor.GetAllModifications();

            return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(modifs), "application/json"));
        }
        public async Task UpdateData()
        {
            if (string.IsNullOrWhiteSpace(_Name) || string.IsNullOrWhiteSpace(_Surname) || string.IsNullOrWhiteSpace(_Address) ||
                string.IsNullOrWhiteSpace(_PhoneNumber) || string.IsNullOrWhiteSpace(_Username) ||
                _DateOfBirth == null)
            {
                await Application.Current.MainPage.DisplayAlert("Greška!", "Potrebno je unijeti sva polja osim polja za promjenu lozinke!", "Try again");

                return;
            }
            var users = await _service.Get <List <Model.User> >(null);

            foreach (var item in users)
            {
                if (item.Username.StartsWith(_Username) && item.Username != APIService._Username)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška!", "Ovo korisničko ime je zauzeto!", "Try again");

                    return;
                }
            }
            if (_Username.Length < 4)
            {
                await Application.Current.MainPage.DisplayAlert("Greška!", "Dužina korisničkog imena mora iznositi najmanje 4 karaktera", "Try again");

                return;
            }
            IsBusy = true;
            UserInsertRequest req = new UserInsertRequest
            {
                Name        = _Name,
                Surname     = _Surname,
                Address     = _Address,
                DateOfBirth = _DateOfBirth,
                PhoneNumber = _PhoneNumber,
                Username    = _Username
            };

            if (_showPW)
            {
                req.Password             = _Password;
                req.ConfirmationPassword = _ConfirmationPassword;
            }
            else
            {
                req.Password             = APIService._Password;
                req.ConfirmationPassword = APIService._Password;
            }
            APIService._Username = _Username;
            Model.Visitor r = null;
            r = await _service.Update <Model.Visitor>(APIService._VisitorId, req);

            if (r != null)
            {
                await Application.Current.MainPage.DisplayAlert("Izmjena podataka uspješna!", "Uspješno ste promijenili vaše podatke. Za nastavak korištenja aplikacije, ponovo se logirajte!", "Ok");

                await Application.Current.MainPage.Navigation.PushModalAsync(new LoginPage());

                return;
            }
        }