示例#1
0
        private void OnSaveMethod(bool IsAlive)
        {
            string nameTemp        = ContentPanel.GetFormControlFromPanel <TextBox>(NameTextBox).Text;
            string descriptionTemp = ContentPanel.GetFormControlFromPanel <TextBox>(DescriptionTextBox).Text;

            PositionModel NewModel = new PositionModel
            {
                Name        = nameTemp,
                Description = descriptionTemp
            };

            PositionDataContract changes = new PositionDataContract();
            int selectedModel            = baseControl.Models.IndexOf(OldModel);

            if (OldModel.IsNull())
            {
                NewModel.ID = Guid.NewGuid();
                changes     = PositionsService.InsertPosition(mapper.Map <PositionModel, PositionDataContract>(NewModel)).Result;
                baseControl.Models.Add(mapper.Map <PositionDataContract, PositionModel>(changes));
            }
            else
            {
                NewModel.ID = baseControl.Models[selectedModel].ID;
                changes     = PositionsService.UpdatePosition(mapper.Map <PositionModel, PositionDataContract>(NewModel)).Result;
                baseControl.Models[selectedModel] = mapper.Map <PositionDataContract, PositionModel>(changes);

                baseControl.CollectionView.Items[selectedModel].Selected = true;
            }

            if (IsAlive)
            {
                OldModel = selectedModel.Equals(-1) ? baseControl.Models[baseControl.Models.Count - 1] : baseControl.Models[selectedModel];
            }
            else
            {
                CloseViewButton.PerformClick();
            }
        }
示例#2
0
        private void UpdatePositionsSource(UserModel model)
        {
            ComboBoxEdit positionCombo = ContentPanel.GetFormControlFromPanel <ComboBoxEdit>(PositionComboBox);

            positionCombo.Properties.Items.Clear();
            if (!model.IsNull() && model.Login.Equals("admin"))
            {
                PositionModel position = mapper.Map <PositionDataContract, PositionModel>(
                    PositionsService.GetFirstPositionByName("Администратор").Result);
                positions.Add(position);
            }
            else
            {
                positions = mapper.Map <List <PositionDataContract>, List <PositionModel> >(
                    PositionsService.GetPositionsCollection().Result
                    .Where(p => !p.Name.Equals("Администратор")).ToList()
                    );
            }
            foreach (PositionModel item in positions)
            {
                positionCombo.Properties.Items.Add(item);
            }
        }
示例#3
0
        private void OnSaveMethod(bool IsAlive)
        {
            string fnameTemp   = ContentPanel.GetFormControlFromPanel <TextBox>(FirstNameTextBox).Text;
            string snameTemp   = ContentPanel.GetFormControlFromPanel <TextBox>(SecondNameTextBox).Text;
            string lnameTemp   = ContentPanel.GetFormControlFromPanel <TextBox>(LastNameTextBox).Text;
            string contNumTemp = ContentPanel.GetFormControlFromPanel <MaskedTextBox>(ContactNumberMaskBox).Text;

            UserModel NewModel = new UserModel
            {
                UserInfo = new UserInfoModel()
                {
                    FirstName     = fnameTemp,
                    SecondName    = snameTemp,
                    LastName      = lnameTemp,
                    ContactNumber = contNumTemp,
                }
            };

            if (OldModel.IsNull())
            {
                NewModel.UserInfo.ID = Guid.NewGuid();
            }
            else
            {
                NewModel.UserInfo.ID = OldModel.UserInfo.ID;
            }

            NewModel.Position = positions
                                .FirstOrDefault(p => p.Name.Equals(ContentPanel.GetFormControlFromPanel <ComboBoxEdit>(PositionComboBox).Text));

            UserDataContract changes = new UserDataContract();
            int selectedModel        = baseControl.Models.IndexOf(OldModel);

            if (OldModel.IsNull())
            {
                NewModel.ID       = Guid.NewGuid();
                NewModel.Login    = ContentPanel.GetFormControlFromPanel <TextBox>(LoginTextBox).Text;
                NewModel.Password = ContentPanel.GetFormControlFromPanel <TextBox>(PasswordTextBox).Text;

                changes = UsersService.InsertUser(mapper.Map <UserModel, UserDataContract>(NewModel)).Result;
                baseControl.Models.Add(mapper.Map <UserDataContract, UserModel>(changes));
            }
            else
            {
                NewModel.ID       = baseControl.Models[selectedModel].ID;
                NewModel.Login    = OldModel.Login;
                NewModel.Password = OldModel.Password;

                changes = UsersService.UpdateUser(mapper.Map <UserModel, UserDataContract>(NewModel)).Result;
                baseControl.Models[selectedModel] = mapper.Map <UserDataContract, UserModel>(changes);

                baseControl.CollectionView.Items[selectedModel].Selected = true;
            }

            if (IsAlive)
            {
                OldModel = selectedModel.Equals(-1) ? baseControl.Models[baseControl.Models.Count - 1] : baseControl.Models[selectedModel];
            }
            else
            {
                CloseViewButton.PerformClick();
            }
        }