/// <summary>
        /// Диалоговое окно для редактирования работника
        /// </summary>
        public static Worker Show(Worker worker)
        {
            if (worker != null)
            {
                WindowAddWorker    addWorker          = new WindowAddWorker();
                AddWorkerViewModel addWorkerViewModel = new AddWorkerViewModel(worker.NameDepartment);

                addWorkerViewModel.Title                  = "Редактировать работника";
                addWorkerViewModel.AddText                = "Изменить";
                addWorkerViewModel.IdWorker               = worker.Id.ToString();
                addWorkerViewModel.FirstNameWorker        = worker.FirstName;
                addWorkerViewModel.LastNameWorker         = worker.LastName;
                addWorkerViewModel.AgeWorker              = worker.Age.ToString();
                addWorkerViewModel.EmployeePositionWorker = worker.EmployeePosition;
                addWorkerViewModel.SalaryWorker           = worker.Salary.ToString();
                addWorker.DataContext = addWorkerViewModel;

                addWorker.ShowDialog();

                if (addWorkerViewModel.Worker != null)
                {
                    worker.Id               = int.Parse(addWorkerViewModel.IdWorker);
                    worker.FirstName        = addWorkerViewModel.FirstNameWorker;
                    worker.LastName         = addWorkerViewModel.LastNameWorker;
                    worker.Age              = int.Parse(addWorkerViewModel.AgeWorker);
                    worker.EmployeePosition = addWorkerViewModel.EmployeePositionWorker;
                    worker.Salary           = int.Parse(addWorkerViewModel.SalaryWorker);
                }
            }

            return(worker);
        }
        /// <summary>
        /// Диалоговое окно для добавления сотрудника
        /// </summary>
        /// <param name="departament"> Название департамента </param>
        public static Worker Show(string department)
        {
            WindowAddWorker    addWorker          = new WindowAddWorker();
            AddWorkerViewModel addWorkerViewModel = new AddWorkerViewModel(department);

            addWorkerViewModel.Title   = "Добавить работника";
            addWorkerViewModel.AddText = "Добавить";
            addWorker.DataContext      = addWorkerViewModel;

            addWorker.ShowDialog();

            return(addWorkerViewModel.Worker);
        }
示例#3
0
        public IActionResult AddWorker()
        {
            var model = new AddWorkerViewModel
            {
                AddWorkerDto           = new AddWorkerDto(),
                GenderNamesSelectItems = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Cinsiyet", Value = "0"
                    }
                }
            };

            foreach (var gender in _genderDal.GetList())
            {
                model.GenderNamesSelectItems.Add(new SelectListItem
                {
                    Text  = gender.GenderName,
                    Value = gender.GenderId.ToString()
                });
            }

            return(View(model));
        }
示例#4
0
 /// <summary>
 /// Реализация метода Show из интерфейса IAddWorker
 /// </summary>
 /// <param name="selectDepartment"></param>
 public void Show(Department selectDepartment)
 {
     DataContext = new AddWorkerViewModel(new Worker("Имя", "Фамилия", 25, 0, "Рабочий"), selectDepartment);
     this.ShowDialog();
 }
示例#5
0
        public IActionResult AddWorker(AddWorkerDto addWorkerDto)
        {
            var model = new AddWorkerViewModel
            {
                AddWorkerDto           = addWorkerDto,
                GenderNamesSelectItems = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Cinsiyet", Value = "0"
                    }
                }
            };

            foreach (var gender in _genderDal.GetList())
            {
                model.GenderNamesSelectItems.Add(new SelectListItem
                {
                    Text  = gender.GenderName,
                    Value = gender.GenderId.ToString()
                });
            }
            if (addWorkerDto.GenderId == 0)
            {
                TempData.Add(TempDataTypes.GenderError, Messages.MustBeFilled);

                return(View(model));
            }

            if (addWorkerDto.BirthDateDay.Equals("0") || addWorkerDto.BirthDateMounth.Equals("0") || addWorkerDto.BirthDateYear.Equals("0"))
            {
                TempData.Add(TempDataTypes.BirthdayError, Messages.MustBeFilled);

                return(View(model));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userForRegister = new UserForRegisterDto
            {
                Email       = addWorkerDto.Email,
                GenderId    = addWorkerDto.GenderId,
                LastName    = addWorkerDto.LastName,
                FirstName   = addWorkerDto.FirstName,
                Password    = addWorkerDto.Password,
                PhoneNumber = addWorkerDto.PhoneNumber
            };

            var result = _authService.Register(userForRegister, userForRegister.Password);

            if (!result.Success)
            {
                return(RedirectToAction("InternalError", "Error", new { errorMessage = result.Message }));
            }

            var user   = _userService.GetByMail(addWorkerDto.Email).Data;
            var worker = new Worker
            {
                AddressNumber = addWorkerDto.AddressNumber,
                IdentityNo    = addWorkerDto.IdentityNo,
                Street        = addWorkerDto.Street,
                CityId        = addWorkerDto.CityId,
                DistrictId    = addWorkerDto.DistrictId,
                BirthDate     = new DateTime(Convert.ToInt32(addWorkerDto.BirthDateYear), Convert.ToInt32(addWorkerDto.BirthDateMounth), Convert.ToInt32(addWorkerDto.BirthDateDay), 0, 0, 0),
                WorkerId      = user.Id
            };

            var result2 = _workerService.AddWorker(worker);

            if (!result2.Success)
            {
                return(RedirectToAction("InternalError", "Error", new { errorMessage = result2.Message }));
            }

            TempData.Add(TempDataTypes.ManageInfo, Messages.WorkerAddedSuccessfully);
            return(RedirectToAction("Worker", "User"));
        }