private async Task<HttpResponseMessage> EditUserCommit(int id, dynamic targetObject)
        {
            try
            {
                var person = new UserModel((UserModel)targetObject)
                {
                    DOB = RepositoryUtils.JustifyDateTimeCulture(targetObject.DOB),
                };

                using (var ms = new MemoryStream())
                {
                    var djs = new DataContractJsonSerializer(typeof(UserModel));
                    djs.WriteObject(ms, person);
                    ms.Position = 0;
                    var sc = new StreamContent(ms);
                    sc.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                    var resp = id == -1
                                   ? await HttpClient.PostAsync(new Uri(ApiRoot), sc)
                                   : await HttpClient.PutAsync(new Uri(ApiRoot + @"/" + id), sc);

                    resp.EnsureSuccessStatusCode();

                    return resp;
                }

            }
            catch (Exception ex)
            {
                LogManager.Instance.LogException(ex.ToString());
                return new HttpResponseMessage(HttpStatusCode.NotModified);
            }
        }
Beispiel #2
0
 public UserModel(UserModel target)
 {
     UserID = target.UserID;
     Username = target.Username;
     Phone = target.Phone;
     Email = target.Email;
     DOB = target.DOB;
 }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            var temp = e.Parameter as ProjectMemberContrainModel;
            if (temp != null)
            {
                _contrain = new ProjectMemberContrainModel(temp);

                removeButton.IsEnabled = ProjectMemberRepository.Instance.IsManager(_contrain.ProjectID);
                favorButton.IsEnabled = removeButton.IsEnabled;
                unfavorButton.IsEnabled = removeButton.IsEnabled;

                if (string.IsNullOrEmpty(_contrain.Role))   // Validate PM
                {
                    // Validate number tasks.
                    var taskAll = await TaskRepository.Instance.GetAllTasksForProject(_contrain.ProjectID);

                    var query = from task in taskAll
                                where task.UserID == _contrain.UserID
                                select task;

                    if (query.Any())
                    {
                        if (_contrain.IsActive)
                        {
                            unfavorButton.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            favorButton.Visibility = Visibility.Visible;
                        }
                    }
                    else
                    {
                        removeButton.Visibility = Visibility.Visible;
                    }
                }

                _model = await UserInformationRepository.Instance.GetUser(_contrain.UserID);

                if (_model != null)
                {
                    Username.Text = _model.Username;

                    Birthday.Text = string.IsNullOrEmpty(_model.DOB)
                                        ? LanguageProvider.Resource["NotAvailable"]
                                        : Convert.ToDateTime(_model.DOB).ToString(
                                            CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);

                    Telephone.Text = string.IsNullOrEmpty(_model.Phone)
                                         ? LanguageProvider.Resource["NotAvailable"]
                                         : _model.Phone;

                    Email.Text = string.IsNullOrEmpty(_model.Email)
                                     ? LanguageProvider.Resource["NotAvailable"]
                                     : _model.Email;
                }
            }
        }
        protected async override void LoadState(object navigationParameter, Dictionary<string, object> pageState)
        {
            Navigator.Instance.MainProgressBar.Visibility = Visibility.Visible;

            MessageArea.Visibility = Visibility.Visible;
            DynamicArea.Visibility = Visibility.Collapsed;

            if (GlobalData.UserInformationModel != null)
            {
                _currentUser = await UserInformationRepository.Instance.GetUser(GlobalData.MyUserID);
                if (_currentUser == null)
                {
                    messageTxt.Text = "eSec can not retrieve live data now.";
                    MessageArea.Visibility = Visibility.Visible;
                    DynamicArea.Visibility = Visibility.Collapsed;
                    Navigator.Instance.MainProgressBar.Visibility = Visibility.Collapsed;
                    return;
                }

                MessageArea.Visibility = Visibility.Collapsed;
                DynamicArea.Visibility = Visibility.Visible;

                FullName.Text = GlobalData.UserInformationModel.FullName;
                Username.Text = _currentUser.Username + "";
                
                var ci = new CultureInfo(GlobalData.UserInformationModel.Locale.Replace("_", "-"));
                Locale.Text = ci.DisplayName;
                UserPic.Source = new BitmapImage(_unknownUserUri);
                UpdateUserPic(LiveConnection.Instance.GetUserAvatarUrl(), GlobalData.UserInformationModel.ID);
                if (_currentUser.DOB != null)
                {
                    Birthday.Value = System.Convert.ToDateTime(_currentUser.DOB);
                }

                PhoneNumber.Text = _currentUser.Phone + "";
                Email.Text = _currentUser.Email + "";
                ShowSaveBtn(false);
                Birthday.ValueChanged += Birthday_ValueChanged;
                PhoneNumber.TextChanged += PhoneNumber_TextChanged;
                Email.TextChanged += Email_TextChanged;
            }
            else
            {
                messageTxt.Text = "eSec can not retrieve live data now.";
                MessageArea.Visibility = Visibility.Visible;
                DynamicArea.Visibility = Visibility.Collapsed;
            }
          
            Navigator.Instance.MainProgressBar.Visibility = Visibility.Collapsed;
        }
        private async void SignIn()
        {
            messageTxt.Text = string.Empty;
            messageTxt.Visibility = Visibility.Collapsed;
            prgessBar.Visibility = Visibility.Visible;
            signInbtn.Visibility = Visibility.Collapsed;

            if (await LiveConnection.Instance.CreateConnectionAsync())
            {
                if (GlobalData.UserInformationModel == null)
                {
                    GlobalData.UserInformationModel = await LiveConnection.Instance.GetUserInformation();
                }

                if (GlobalData.UserInformationModel != null)
                {
                    ApplicationData.Current.LocalSettings.Values["UserFirstName"] = GlobalData.UserInformationModel.FirstName;

                    // Check existance of user on server
                    var cloudInfo = await UserInformationRepository.Instance.GetUser(GlobalData.UserInformationModel.Email);

                    // If null profile is returned, create blank one for newcommer.
                    if (cloudInfo == null)
                    {
                        var newBlankInfo = new UserModel
                        {
                            DOB = null,
                            Email = "",
                            Phone = "",
                            Username = GlobalData.UserInformationModel.Email
                        };

                        await UserInformationRepository.Instance.AddUser(newBlankInfo);
                    }
                    else
                    {
                        GlobalData.MyUserID = cloudInfo.UserID;
                    }

                }
                LoadBuffer();

                pageTitle.Text = (ApplicationData.Current.LocalSettings.Values["UserFirstName"] + string.Empty == string.Empty)
                    ? LanguageProvider.Resource["MainTitle_2"]
                    : LanguageProvider.Resource["MainTitle_1"].Replace("[abc]", ApplicationData.Current.LocalSettings.Values["UserFirstName"] + string.Empty);
                yearIndicator.Visibility = Visibility.Visible;
                //signOutbtn.Visibility = Visibility.Visible;
                DynamicContentGrid.Visibility = Visibility.Visible;
                MessageContent.Visibility = Visibility.Collapsed;
            }
            else
            {
                messageTxt.Text = LanguageProvider.Resource["Msg_LoginFailed"];
                messageTxt.Visibility = Visibility.Visible;
                prgessBar.Visibility = Visibility.Collapsed;
                signInbtn.Visibility = Visibility.Visible;
            }
        }
        public async Task<HttpResponseMessage> UpdateUserData(UserModel data)
        {
            var response = await UserInformationController.Instance.PushAsync(data.UserID, data);
            if (response.IsSuccessStatusCode)
            {
                var index = _cacheUsers.IndexOf(data);
                if (index >= 0)
                {
                    _cacheUsers[index] = data;
                }
            }

            return response;
        }
        public async Task<UserModel> AddUser(UserModel data)
        {
            var response = await UserInformationController.Instance.PostAsync(data);
            if (response.IsSuccessStatusCode)
            {
                using (var stream = await response.Content.ReadAsStreamAsync())
                {
                    var djs = new DataContractJsonSerializer(typeof(UserModel));
                    var user = (UserModel)djs.ReadObject(stream);
                    _cacheUsers.Add(user);
                    return user;
                }
            }

            return null;
        }