public async Task <ActionResult <InfoResult <AcStaffDtos> > > AddStaff(AcStaffDtos acStaffDtos) { var NewDepartment = (await _IAcDepartmentService.Search(u => u.Name == acStaffDtos.DeparmentName)).FirstOrDefault(); acStaffDtos.DepartmentId = NewDepartment.Id; var staffList = await _IAcStaffService.Search(t => true); int max = 0; foreach (var item in staffList) { if (item.Id > max) { max = item.Id; } } acStaffDtos.Id = max + 1; InfoResult <AcStaffDtos> messageModel = new InfoResult <AcStaffDtos>(); var data = await _IAcStaffService.Add(_mapper.Map <AcStaff>(acStaffDtos)); if (data > 0) { messageModel.Msg = "添加成功!"; messageModel.Code = 200; messageModel.Success = true; } else { messageModel.Msg = "添加失败!"; messageModel.Code = 400; messageModel.Success = false; } return(Ok(messageModel)); }
public async Task <ActionResult <InfoResult <string> > > DeleteStaff(AcStaffDtos acStaffDtos) { var NewStaff = (await _IAcStaffService.Search(u => u.Id == acStaffDtos.Id)).FirstOrDefault(); InfoResult <AcStaffDtos> messageModel = new InfoResult <AcStaffDtos>(); if (NewStaff != null) { if (NewStaff.Status == 0) { messageModel.Msg = "该员工已处于离职状态"; return(Ok(messageModel)); } else { //将员工状态修改为离职 NewStaff.Status = 0; var data = (await _IAcStaffService.Search(t => true)).ToList(); var data2 = _mapper.Map <List <AcStaffDtos> >(data); foreach (var item in data2) { if (item.Status == 0) { item.StatusStr = "离职"; } } return(await _IAcStaffService.Edit(NewStaff) > 0 ? new InfoResult <string>("修改成功!") : new InfoResult <string>("修改失败!")); } } return(Ok(messageModel)); }
public async Task <ActionResult <InfoResult <string> > > UpdateStaff(AcStaffDtos acStaffDtos) { var NewStaff = (await _IAcStaffService.Search(u => u.Id == acStaffDtos.Id)).FirstOrDefault(); InfoResult <AcStaffDtos> messageModel = new InfoResult <AcStaffDtos>(); if (NewStaff != null) { NewStaff.Id = acStaffDtos.Id; NewStaff.Name = acStaffDtos.Name; NewStaff.Sex = (sbyte)acStaffDtos.Sex; NewStaff.No = acStaffDtos.No; NewStaff.Address = acStaffDtos.Address; NewStaff.Tel = acStaffDtos.Tel; NewStaff.DepartmentId = acStaffDtos.DepartmentId; NewStaff.Status = (sbyte)acStaffDtos.Status; return(await _IAcStaffService.Edit(NewStaff) > 0 ? new InfoResult <string>("修改成功!") : new InfoResult <string>("修改失败!")); } return(Ok(messageModel)); }