123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using wispro.sp.entity;
- using wispro.sp.share;
- using System.Linq;
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using Microsoft.AspNetCore.Authorization;
- namespace wispro.sp.api.Controllers
- {
- //[Authorize]
- [Route("api/[controller]/[action]")]
- [ApiController]
- public class StaffController : ControllerBase
- {
- private static List<Staff> CacheList = new List<Staff>();
- spDbContext Context;
- public StaffController(spDbContext context)
- {
- Context = context;
- }
-
- public List<Staff> GetAll()
- {
- return Context.Staffs.ToList<Staff>();
- }
-
-
- public ListApiResponse<Staff> Query(int pageIndex,int pageSize)
- {
- ListApiResponse<Staff> ret = new ListApiResponse<Staff>();
- ret.TotalCount = Context.Staffs.Count<Staff>();
- List<Staff> retList = Context.Staffs.Skip<Staff>((pageIndex - 1) * pageSize).Take(pageSize).ToList<Staff>();
-
- ret.Results = retList;
- return ret;
- }
- [HttpPost]
- public ApiSaveResponse Save(Staff staff)
- {
- ApiSaveResponse ret = new ApiSaveResponse();
- try
- {
- if (staff.Id == 0)
- {
-
- Staff temStaff = Context.Staffs.Where<Staff>(x => x.Name == staff.Name).FirstOrDefault();
- if (temStaff != null)
- {
- temStaff.Account = staff.Account;
- temStaff.Department = staff.Department;
- temStaff.EntyDate = staff.EntyDate;
- temStaff.IsCalPerformsnce = staff.IsCalPerformsnce;
- temStaff.IsOnJob = staff.IsOnJob;
- temStaff.Mail = staff.Mail;
- temStaff.Memo = staff.Memo;
- temStaff.Mobile = staff.Mobile;
- temStaff.Name = staff.Name;
- temStaff.Password = staff.Password;
- temStaff.Sex = staff.Sex;
- temStaff.StaffGradeId = staff.StaffGradeId;
- temStaff.Status = staff.Status;
- temStaff.Tel = staff.Tel;
- temStaff.WorkPlace = staff.WorkPlace;
- Context.SaveChanges();
- ret.Success = false;
- ret.ErrorMessage = $"用户【{staff.Name}】已存在!";
- }
- else
- {
- Context.Staffs.Add(staff);
- }
- }
- else
- {
- Staff editObject = Context.Staffs.Where<Staff>(x => x.Id == staff.Id).FirstOrDefault();
- if (editObject != null)
- {
- editObject.Account = staff.Account;
- editObject.Department = staff.Department;
- editObject.EntyDate = staff.EntyDate;
- editObject.IsCalPerformsnce = staff.IsCalPerformsnce;
- editObject.IsOnJob = staff.IsOnJob;
- editObject.Mail = staff.Mail;
- editObject.Memo = staff.Memo;
- editObject.Mobile = staff.Mobile;
- editObject.Name = staff.Name;
- editObject.Password = staff.Password;
- editObject.Sex = staff.Sex;
- editObject.StaffGradeId = staff.StaffGradeId;
- editObject.Status = staff.Status;
- editObject.Tel = staff.Tel;
- editObject.WorkPlace = staff.WorkPlace;
- }
- else
- {
- ret.Success = false;
- ret.ErrorMessage = $"编号为【{staff.Id}】的用户不存在!";
- }
-
- }
- Context.SaveChanges();
- ret.Success = true;
- }
- catch (Exception ex)
- {
- ret.Success = false;
- ret.ErrorMessage = ex.Message;
- }
- return ret;
- }
- }
- }
|