public async Task <IActionResult> AddOrEditStaff(AddStaffDialogViewModel vm) { if (string.IsNullOrEmpty(vm.FirstName)) { return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, ErrorMessageAnchor)); } if (string.IsNullOrEmpty(vm.LastName)) { return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, ErrorMessageAnchor)); } if (!vm.Email?.IsValidEmail() ?? vm.IsNewStaff) { return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, ErrorMessageAnchor)); } if (vm.IsNewStaff && string.IsNullOrEmpty(vm.Password)) { return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, ErrorMessageAnchor)); } if (vm.IsNewStaff) { _cqrsEngine.SendCommand( _mapper.Map <RegisterEmployeeCommand>(vm), "lykkepay-employee-registration-ui", "lykkepay-employee-registration"); } else { EmployeeModel employee = await _payInvoiceClient.GetEmployeeAsync(vm.Id); var updateEmployeeCommand = _mapper.Map <UpdateEmployeeCommand>(vm); updateEmployeeCommand.Email = employee.Email; _cqrsEngine.SendCommand( updateEmployeeCommand, "lykkepay-employee-registration-ui", "lykkepay-employee-registration"); } return(this.JsonRequestResult("#staffList", Url.Action("StaffsList"), new StaffsPageViewModel { SelectedMerchant = vm.SelectedMerchant })); }
public async Task <ActionResult> AddOrEditStaffDialog(string id = null, string merchant = null) { var employee = new EmployeeModel(); if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(merchant)) { employee = await _payInvoiceClient.GetEmployeeAsync(id); } var merchants = await _payMerchantClient.Api.GetAllAsync(); var viewmodel = new AddStaffDialogViewModel() { SelectedMerchant = merchant, Merchants = merchants, FirstName = employee.FirstName, LastName = employee.LastName, Email = employee.Email, Id = employee.Id, IsNewStaff = id == null, IsBlocked = employee.IsBlocked }; return(View(viewmodel)); }