public async Task <IActionResult> Edit([FromRoute] Guid employeeId, [FromBody] EditEmployeeRequest request) { List <Employee> allEmployees = await _employeeService.GetAllEmployeesAsync(); for (int i = 0; i < allEmployees.Count; i++) { if (allEmployees[i].Email == request.Email && allEmployees[i].Id != employeeId) { return(StatusCode(StatusCodes.Status406NotAcceptable, "This Email is already in use, please choose a different Email!")); } } // NOTE: Ideally i would simply create a new Employee, and simply replace the existing Employee // in the database with the new one, however this causes a tracking error for the given Id, // which is only allowed 1 tracker, So as a patchwerk solution i instead change each individual value for that shift. Employee employee = await _employeeService.GetEmployeeByIdAsync(employeeId); employee.FirstName = request.FirstName; employee.LastName = request.LastName; employee.Email = request.Email; bool updated = await _employeeService.UpdateEmployeeAsync(employee); if (updated) { return(Ok(employee)); } return(NotFound()); }
public void Edit_Employee() { var origEmployee = _service.GetAllEmployees(new GetAllEmployeesRequest(), UnitOfWork).Employees .OrderBy(x => new Random().Next()).FirstOrDefault(); var editEmployee = new EditEmployeeRequest { Id = origEmployee.Id, Name = origEmployee.Name + "1", Patronymic = origEmployee.Patronymic + "1", Position = origEmployee.Position + "1", Surname = origEmployee.Surname + "1" }; _service.EditEmployee(editEmployee, UnitOfWork); TestUtil.AreEqual( new Employee { Id = editEmployee.Id, Name = editEmployee.Name, Patronymic = editEmployee.Patronymic, Position = editEmployee.Position, Surname = editEmployee.Surname }, _service.GetEmployee(new GetEmployeeRequest { Id = origEmployee.Id }, UnitOfWork).Employee); }
public ResultObject Edit(EditEmployeeRequest request) { var m = SimpleMapper.Map <SystemUser>(request); var flag = 0L; if (m.Id > 0) { flag = systemUserDao.Update(m, "Nickname", "Gender", "Status", "Avatar"); } else { if (systemUserDao.ExistsUsername(request.Username)) { return(new ResultObject("用户名已存在")); } m.Password = EncryptHelper.MD5Encrypt(request.Password); flag = systemUserDao.Insert(m); m.Id = (int)flag; } if (flag > 0) { // C_Employee.SetCacheOne(m.Id); } return(new ResultObject(flag > 0)); }
public async Task <IActionResult> EditEmployee(int id, EditEmployeeRequest request) { if (ModelState.IsValid && id == request.Id) { var response = await _editEmployeeRequestClient.GetResponse <EditEmployeeResponse>(new EditEmployeeRequest { Id = id, Name = request.Name }); return(Ok(response.Message)); } return(BadRequest(ModelState)); }
/// <summary> /// Edit /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override async Task <EditEmployeeReply> Edit(EditEmployeeRequest request, ServerCallContext context) { CheckRequestInvalid(request); var result = new EditEmployeeReply(); result.IsSuccess = _EmployeeBO.UpdateEntiy(new EmployeeDto { EmployeeID = request.EmployeeID , Title = request.Title , NationalIDNumber = request.NationalIDNumber }); return(await Task.FromResult(result)); }
private void ChangeEmployee(Employee employee, string action) { var emp_to_edit = employee as Employee; if (emp_to_edit != null) { var supervisors = Company.Employees.Where(emp => emp.RoleInCompany == Roles.QIQORoleOwner || emp.RoleInCompany == Roles.QIQORoleManager).ToList(); Tuple <object, object> needed_objects = new Tuple <object, object>(emp_to_edit, supervisors); ItemEditNotification notification = new ItemEditNotification(needed_objects); //ItemEditNotification notification = new ItemEditNotification(emp_to_edit); notification.Title = action + " Employee"; //+ emp_to_edit.PersonCode + " - " + emp_to_edit.PersonFullNameFML; EditEmployeeRequest.Raise(notification, r => { if (r != null && r.Confirmed && r.EditibleObject != null) // { Employee emp = r.EditibleObject as Employee; if (emp != null) { if (action == ApplicationStrings.NotificationEdit) { var emp_to_change = EmpSelectedItem as EmployeeWrapper; if (emp_to_change != null) { emp_to_change.Comment = emp.Comment; emp_to_change.CompanyRoleType = emp.CompanyRoleType; emp_to_change.EndDate = emp.EndDate; emp_to_change.StartDate = emp.StartDate; emp_to_change.PersonCode = emp.PersonCode; emp_to_change.PersonDOB = emp.PersonDOB; emp_to_change.PersonFirstName = emp.PersonFirstName; emp_to_change.PersonLastName = emp.PersonLastName; emp_to_change.PersonMI = emp.PersonMI; emp_to_change.RoleInCompany = emp.RoleInCompany; } } else { Company.Employees.Add(new EmployeeWrapper(emp)); } } } }); } }
public IActionResult DoEdit(EditEmployeeRequest request) { var ro = systemUserBusiness.Edit(request); return(Json(ro)); }
public GeneralResponse EditEmployee(EditEmployeeRequest request, Guid ModifiedEmployeeID) { GeneralResponse response = new GeneralResponse(); Employee employee = new Employee(); employee = _employeeRepository.FindBy(request.ID); if (employee != null) { try { employee.ModifiedDate = PersianDateTime.Now; employee.ModifiedEmployee = _employeeRepository.FindBy(ModifiedEmployeeID); if (request.BirthDate != null) { employee.BirthDate = request.BirthDate; } if (request.FirstName != null) { employee.FirstName = request.FirstName; } if (request.GroupID != employee.Group.ID) { employee.Group = this._groupRepository.FindBy(request.GroupID); } if (request.HireDate != null) { employee.HireDate = request.HireDate; } employee.InstallExpert = request.InstallExpert; if (request.LastName != null) { employee.LastName = request.LastName; } if (request.LoginName != null) { employee.LoginName = request.LoginName; } if (request.ParentEmployeeID != null) { employee.ParentEmployee = this._employeeRepository.FindBy(request.ParentEmployeeID); } if (request.Password != null) { employee.Password = request.Password; } if (request.Phone != null) { employee.Phone = request.Phone; } if (request.Mobile != null) { employee.Mobile = request.Mobile; } if (request.Address != null) { employee.Address = request.Address; } if (request.Note != null) { employee.Note = request.Note; } employee.Discontinued = request.Discontinued; if (employee.RowVersion != request.RowVersion) { response.ErrorMessages.Add("EditConcurrencyKey"); return(response); } else { employee.RowVersion += 1; } if (employee.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in employee.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } _employeeRepository.Save(employee); _uow.Commit(); ////response.success = true; } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } } else { response.ErrorMessages.Add("NoItemToEditKey"); } return(response); }
/// <summary> /// ویرایش یک کارمند /// </summary> /// <param name="request"></param> /// <returns></returns> public JsonResult Employee_Update(EditEmployeeRequest request, HttpPostedFileBase file) { GeneralResponse response = new GeneralResponse(); try { #region Check Access bool hasPermission = GetEmployee().IsGuaranteed("Employee_Update"); if (!hasPermission) { response.ErrorMessages.Add("AccessDenied"); return(Json(response, JsonRequestBehavior.AllowGet)); } #endregion #region Upload file // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract the extention var fileExtention = Path.GetExtension(file.FileName); // create filename //string fileName = response.ID + "." + fileExtention; // fileName = Path.GetFileName(file.FileName); // Create a unique file name string fileName = request.LoginName; // Gettin current Year and Month PersianCalendar pc = new PersianCalendar(); int year = pc.GetYear(DateTime.Now); int month = pc.GetMonth(DateTime.Now); // Create File Path string path = Path.Combine(Server.MapPath("~/data/EmployeePicture"), fileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } // Create reqired directried if not exist new FileInfo(path).Directory.Create(); // Uploading using (var fs = new FileStream(path, FileMode.Create)) { var buffer = new byte[file.InputStream.Length]; file.InputStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, buffer.Length); } request.Picture = path; } #endregion } catch (Exception ex) { //response.success = false; response.ErrorMessages.Add("در آپلود کردن فایل خطایی به وجود آمده است."); return(Json(response, JsonRequestBehavior.AllowGet)); } response = _employeeService.EditEmployee(request, GetEmployee().ID); return(Json(response, JsonRequestBehavior.AllowGet)); }