/// <summary>
 /// I will check if attachments and role changed and update them
 /// </summary>
 /// <param name="workerInDb"></param>
 /// <param name="editworker"></param>
 /// <param name="role"></param>
 private void CheckAndUpdateEverything(ApplicationUser workerInDb, EditWorker editworker, IdentityRole role)
 {
     if (!workerInDb.Roles.Any(r => r.RoleId == role.Id))
     {
         workerInDb.Roles.Remove(workerInDb.Roles.First());
         workerInDb.Roles.Add(new IdentityUserRole()
         {
             RoleId = role.Id,
             UserId = workerInDb.Id
         });
     }
     if (workerInDb.Worker.Department.ID != editworker.IdOfDepartment)
     {
         workerInDb.Worker.Department   = _db.Departments.Find(editworker.IdOfDepartment);
         workerInDb.Worker.DepartmentID = editworker.IdOfDepartment;
     }
     if (editworker.ProfilePicture != null)
     {
         DeleteProfPicOfWorker(workerInDb.Worker.Pic);
         workerInDb.Worker.Pic = ConventionsOfHttpPostedFileBase.ForPostedPicture(editworker.ProfilePicture);
     }
     if (editworker.CV != null)
     {
         DeleteCVOfWorker(workerInDb.Worker.CV);
         workerInDb.Worker.Pic = ConventionsOfHttpPostedFileBase.ForCV(editworker.CV);
     }
     if (editworker.ContractOfEmployment != null)
     {
         DeleteContractOfEmployementOfWorker(workerInDb.Worker.ContractOfEmployment);
         workerInDb.Worker.Pic = ConventionsOfHttpPostedFileBase.ForContractOfEmployments(editworker.ContractOfEmployment);
     }
 }
コード例 #2
0
        private void ListBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Delete)
            {// удаление по клавише delete
                if (listBox.SelectedIndex > -1)
                {
                    int             si              = cBoxWork.SelectedIndex;
                    WorkViewModel   workViewModel   = cBoxWork.SelectedItem as WorkViewModel;
                    WorkerViewModel workerViewModel = listBox.SelectedItem as WorkerViewModel;

                    workService.RemoveWorkerFromWork(workViewModel.WorkId, workerViewModel.WorkerId);
                    works = workService.GetAll();
                    cBoxWork.DataContext   = works;
                    cBoxWork.SelectedIndex = si;
                }
            }
            if (e.Key == System.Windows.Input.Key.Insert)
            {// обновление по клавише Insert
                if (listBox.SelectedIndex > -1)
                {
                    WorkerViewModel workerViewModel = listBox.SelectedItem as WorkerViewModel;
                    var             dialog          = new EditWorker(workerViewModel);
                    var             result          = dialog.ShowDialog();
                    if (result == true)
                    {
                        workService.UpdateWorker(workerViewModel);
                        dialog.Close();
                    }
                }
            }
        }
コード例 #3
0
        private void Edit_button_Click(object sender, EventArgs e)
        {
            dataSet            = BusinessLogic.ReadWorkers();
            LastSelectionIndex = Workers_dataGridView.SelectedRows[0].Index;
            string            Post = Workers_dataGridView.SelectedRows[0].Cells["PostColumn"].Value.ToString();
            AddEditWorkerForm EditWorker;

            if (Post == "преподаватель теории")
            {
                EditWorker = new AddEditWorkerForm(Post, dataSet.TheoryTeachers.Rows.Find(Workers_dataGridView.SelectedRows[0].Cells["ID"].Value), dataSet.WorkStatuses, dataSet);
            }
            else if (Post == "инструктор")
            {
                EditWorker = new AddEditWorkerForm(Post, dataSet.Instructors.Rows.Find(Workers_dataGridView.SelectedRows[0].Cells["ID"].Value), dataSet.WorkStatuses, dataSet);
            }
            else if (Post == "мастер сервиса")
            {
                EditWorker = new AddEditWorkerForm(Post, dataSet.ServiceMasters.Rows.Find(Workers_dataGridView.SelectedRows[0].Cells["ID"].Value), dataSet.WorkStatuses, dataSet);
            }
            else
            {
                EditWorker = null;
                MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка редактирования");
                return;
            }
            EditWorker.Text = "Редактирование сотрудника";
            this.Enabled    = false;
            EditWorker.ShowDialog();
            if (EditWorker.DialogResult == DialogResult.OK)
            {
                dataSet = BusinessLogic.WriteWorkers(dataSet);
                ReloadWorkers();
            }
            this.Enabled = true;
        }
コード例 #4
0
 public EditWorkerViewModel(EditWorker editWorkerOpen, vwWorker workerEdit)
 {
     _editWorker  = editWorkerOpen;
     _worker      = workerEdit;
     _location    = new vwLocation();
     _gender      = new tblGender();
     _sector      = new tblSector();
     _manager     = new vwManager();
     LocationList = _dbService.GetAllLocations();
     WorkerList   = _dbService.GetAllWorkerRecords();
     GenderList   = _dbService.GetAllGenders();
     SectorList   = _dbService.GetAllSectors();
     ManagerList  = new List <vwManager>();
     foreach (var item in _dbService.GetAllManagers())
     {
         if (item.WorkerID != _worker.WorkerID)
         {
             ManagerList.Add(item);
         }
     }
     FirstNameBeforeEdit = _worker.FirstName;
     LastNameBeforeEdit  = _worker.LastName;
     JMBGBeforeEdit      = _worker.JMBG;
     actionEventObject   = new ActionEvent();
     actionEventObject.ActionPerformed += ActionPerformed;
 }
 /// <summary>
 /// Update the Properties that needs to be updated
 /// </summary>
 /// <param name="workerInDb"></param>
 /// <param name="editworker"></param>
 private void UpdatePropertiesOfEditedWorker(ApplicationUser workerInDb, EditWorker editworker)
 {
     workerInDb.UserName           = editworker.Username;
     workerInDb.Email              = editworker.Email;
     workerInDb.Worker.FirstName   = editworker.FirstName;
     workerInDb.Worker.LastName    = editworker.LastName;
     workerInDb.Worker.DateOfBirth = editworker.DateOfBirth;
     workerInDb.Worker.Gender      = editworker.Gender;
     workerInDb.Worker.Address     = editworker.Address;
     workerInDb.Worker.BankAccount = editworker.BankAccount;
     workerInDb.Worker.Salary      = editworker.Salary;
 }
コード例 #6
0
        public ActionResult EditWorker(EditWorker f2)
        {
            if (ModelState.IsValid)
            {
                _external.EditWorker(f2);

                return(RedirectToAction("ViewAllWorkers", "Display"));
            }
            else
            {
                f2 = _external.FillEditWorkerViewModel(_data.ApplicationUser.FindUserByID(f2.UserID));
                return(View(f2));
            }
        }
コード例 #7
0
        /// <summary>
        /// Metoda UserControl_IsVisibleChanged(object sender, TextChangedEventArgs e) podczas wywolania edytuje wybranego pracownika do listy i bazy danych
        /// </summary>
        /// <param name="sender">Argument typu object, ktory przekazuje obiekt</param>
        /// <param name="e">Argument typu MouseButtonEventArgs, ktory przekazuje wszystkie informacje o zdarzeniu </param>
        private void EditWorker(object sender, MouseButtonEventArgs e) //double click -> edit worker
        {
            Worker     selectedWorker = WorkersList.SelectedItem as Worker;
            EditWorker editWorker     = new EditWorker(selectedWorker);

            if (editWorker.ShowDialog() == true)
            {
                using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
                {
                    connection.CreateTable <Worker>();
                    connection.InsertOrReplace(editWorker.newWorker);
                }
                UpdateList();
            }
        }
コード例 #8
0
 private void EditWorkerExecute()
 {
     try
     {
         if (Worker != null)
         {
             EditWorker editWorker = new EditWorker(Worker);
             editWorker.ShowDialog();
             WorkerList = _dataBaseService.GetAllWorkerRecords().ToList();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        public void EditWorker(EditWorker editworker)
        {
            var workerInDb = _db.Users.Find(editworker.UserID);

            var role = _db.Roles.Find(editworker.SelectedRole);

            CheckAndUpdateEverything(workerInDb, editworker, role);

            UpdatePropertiesOfEditedWorker(workerInDb, editworker);

            EditWorkersApplicationUser(workerInDb.Id);

            _db.Entry(workerInDb.Worker).State = EntityState.Modified;

            _db.SaveChanges();
        }
コード例 #10
0
        private void ButtonAddWorker_Click(object sender, RoutedEventArgs e)
        {
            var worker = new WorkerViewModel();

            worker.DateOfBirth = new DateTime(1990, 01, 01);
            var dialog = new EditWorker(worker);
            var result = dialog.ShowDialog();

            if (result == true)
            {
                var work = (WorkViewModel)cBoxWork.SelectedItem;
                work.Workers.Add(worker);
                workService.AddWorkerToWork(work.WorkId, worker);
                dialog.Close();
            }
        }
コード例 #11
0
        public ActionResult EditWorker(string userID)
        {
            if (string.IsNullOrEmpty(userID))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var user = _data.ApplicationUser.FindUserByID(userID);

            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            EditWorker f2 = _external.FillEditWorkerViewModel(user);

            return(View(f2));
        }
        /// <summary>
        /// Fill ViewModel of EditWorker of Edit
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public EditWorker FillEditWorkerViewModel(ApplicationUser user)
        {
            EditWorker f2 = new EditWorker()
            {
                UserID         = user.Id,
                Username       = user.UserName,
                Email          = user.Email,
                FirstName      = user.Worker.FirstName,
                LastName       = user.Worker.LastName,
                DateOfBirth    = user.Worker.DateOfBirth,
                Gender         = user.Worker.Gender,
                Address        = user.Worker.Address,
                BankAccount    = user.Worker.BankAccount,
                Salary         = user.Worker.Salary,
                IdOfDepartment = user.Worker.DepartmentID,
                SelectedRole   = _db.Roles.Find(user.Roles.First().RoleId).Name,
                AllDepartments = _db.Departments.ToList(),
                Roles          = _db.Roles.Where(s => s.Name != "Admin").ToList()
            };

            return(f2);
        }
コード例 #13
0
        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            EditWorker editWorkerWindow = new EditWorker(worker);

            editWorkerWindow.Show();
        }