Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("EmployeeID,DepartmentID,Surname,Name,Patronymic,DateOfBirth")] Employee employee)
        {
            if (id != employee.EmployeeID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var command = new EditEmployeeCommand(employee);
                    var handler = CommandHandlerFactory.Build(command);
                    handler.Execute(_context);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.EmployeeID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentID"] = new SelectList(_context.Department, "DepartmentID", "DepartmentID", employee.DepartmentID);
            return(View(employee));
        }
        public async Task <ActionResult <Unit> > Edit(string id, EditEmployeeCommand command)
        {
            command.Id = id;

            var query = await _mediator.Send(command);

            return(query);
        }
 private void InvalidateCommands()
 {
     DeleteEmployeeCommand.RaiseCanExecuteChanged();
     EditEmployeeCommand.RaiseCanExecuteChanged();
     EditCOACommand.RaiseCanExecuteChanged();
     DeleteCOACommand.RaiseCanExecuteChanged();
     SaveCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
     EditAttributeCommand.RaiseCanExecuteChanged();
     DeleteAttributeCommand.RaiseCanExecuteChanged();
 }
 public void Edit(EditEmployeeCommand command)
 {
     FullName  = command.FullName;
     BirthDate = command.BirthDate;
     Email     = command.Email;
     Gender    = command.Gender;
     Skills    = new List <EmployeeSkill>();
     foreach (var item in command.Skills)
     {
         Skills.Add(new EmployeeSkill(Id, item));
     }
 }
Exemple #5
0
        public async Task <IActionResult> Edit(EditEmployeeCommand command)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Employee"] = (await Mediator.Send(new GetEmployeeQuery {
                    Id = command.Id
                })).Employee;
                return(View());
            }

            await Mediator.Send(command);

            return(Redirect(nameof(Index)));
        }
Exemple #6
0
        public async Task <IActionResult> UpdateEmployee([FromBody] Employee employee)
        {
            if (ModelState.IsValid)
            {
                var command = new EditEmployeeCommand(employee);
                var result  = await _mediator.Send(command);

                return(Ok(result));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemple #7
0
        public async Task <EmployeeDTO> Handle(EditEmployeeCommand request, CancellationToken cancellationToken)
        {
            var employee          = request.Employee;
            var exsistingEmployee = await _unitOfWork.GetRepository <Employee>().FindAsync(employee.Id);

            exsistingEmployee.FirstName         = employee.FirstName;
            exsistingEmployee.LastName          = employee.LastName;
            exsistingEmployee.SalaryCoefficient = employee.SalaryCoefficient;
            exsistingEmployee.SetSalary(exsistingEmployee.SalaryCoefficient);
            _unitOfWork.GetRepository <Employee>().Update(exsistingEmployee);
            await _unitOfWork.SaveChangesAsync();

            return(_mapper.Map <EmployeeDTO>(exsistingEmployee));
        }
 private void InvalidateCommands()
 {
     EditFeeScheuleCommand.RaiseCanExecuteChanged();
     SaveCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
     DeleteCommand.RaiseCanExecuteChanged();
     EditAttributeCommand.RaiseCanExecuteChanged();
     DeleteAttributeCommand.RaiseCanExecuteChanged();
     DeleteFeeScheuleCommand.RaiseCanExecuteChanged();
     NewOrderCommand.RaiseCanExecuteChanged();
     EditContactCommand.RaiseCanExecuteChanged();
     DeleteContactCommand.RaiseCanExecuteChanged();
     EditEmployeeCommand.RaiseCanExecuteChanged();
     DeleteEmployeeCommand.RaiseCanExecuteChanged();
 }
Exemple #9
0
        public Employee Update(EditEmployeeCommand command)
        {
            var employee = _repository.Get(command.Id);

            employee.UpdateData(command.FirstName, command.LastName, command.Email, command.DepartmentId, command.BirthDate, command.Active);

            if (employee.IsValid())
            {
                if (employee.Department.Id != command.DepartmentId)
                {
                    employee.Department = _repositoryDepart.Get(command.DepartmentId);
                }

                _repository.Update(employee);
            }
            return(employee);
        }
        public EmployeeListViewModel(IMessageBroker messageBroker, IEmployeeService employeeService,
                                     NewEmployeeCommand newEmployeeCommand, EditEmployeeCommand editEmployeeCommand,
                                     DeleteEmployeeCommand deleteEmployeeCommand)
        {
            this.messageBroker   = messageBroker;
            this.employeeService = employeeService;

            NewCommand    = newEmployeeCommand;
            EditCommand   = editEmployeeCommand;
            DeleteCommand = deleteEmployeeCommand;

            employees = new ObservableCollection <Employee>();

            NavigationCommands = new List <CommandBase>()
            {
                NewCommand, DeleteCommand
            };
            SubscribeMessages();
        }
        // constructor
        public EmployeeViewModel()
        {
            dbConnectionString = Properties.Settings.Default.DBConnectionString;
            // initialize button enable logic
            bCanDelete = false;
            bCanAdd    = true;
            bCanEdit   = false;
            bCanUpdate = false;
            bCanCancel = false;

            // initialize control commands
            AddEmployee    = new AddEmployeeCommand(this);
            EditEmployee   = new EditEmployeeCommand(this);
            UpdateEmployee = new UpdateEmployeeCommand(this);
            DeleteEmployee = new DeleteEmployeeCommand(this);
            CancelChanges  = new CancelChangesCommand(this);

            // retrieve employee list and populate DataGrid control
            FillDataGrid();
            SelectedItem = -1;
            OnPropertyChanged("SelectedItem");
        }
 public static ICommandHandler <EditEmployeeCommand> Build(EditEmployeeCommand command)
 {
     return(new EditEmployeeCommandHandler(command));
 }
        public async Task <IActionResult> Update([FromBody] EditEmployeeCommand command)
        {
            var result = _service.Update(command);

            return(await Response(result, result.Notifications));
        }
        public async Task <ActionResult> EditEmployeeAsync([FromBody] EditEmployeeCommand request)
        {
            await mediator.Send(request);

            return(Ok());
        }
Exemple #15
0
        public async Task <IActionResult> Put([FromServices] IHandler <EditEmployeeCommand> service, [FromBody] EditEmployeeCommand command)
        {
            var result = await service.HandleAsync(command);

            return(await CreateResponseAsync(result));
        }
        public ActionResult Edit(EmployeeViewModel employeeViewModel)
        {
            if (ModelState.IsValid)
            {
                var editEmployeeCommand = new EditEmployeeCommand();
                Mapper.CreateMap<EmployeeViewModel, EditEmployeeCommand>();
                Mapper.Map(employeeViewModel, editEmployeeCommand);
                CommandProcessor.Process<EditEmployeeCommand, CommandResult>(editEmployeeCommand, ModelState);

                if (!ModelState.IsValid)
                    return View();
                return this.RedirectToAction(c => c.Index(null, null));
            }

            return View();
        }