public ActionResult UserRole(string uid) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Tapp_User appUser = ctx.Tapp_User.FirstOrDefault(c => c.UserName == uid); if (appUser == null) { return(Content(this.GetJSON(new { Result = false, Msg = "员工不存在" }), this.JsonContentType())); } List <Tapp_Role> Roles = ctx.Tapp_Role.ToList(); List <Tapp_User_Role> appUserRole = ctx.Tapp_User_Role.Where(c => c.UserId == appUser.Id).ToList(); List <UserRoleDto> dtos = new List <UserRoleDto>(); foreach (var item in Roles) { dtos.Add(new UserRoleDto { UserId = appUser.Id, RoleId = item.Id, RoleName = item.RoleName, IsRight = appUserRole.Exists(c => c.UserId == appUser.Id && c.RoleId == item.Id) }); } return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dtos = dtos }), this.JsonContentType())); }
public ActionResult UpdatePwd(UpdatePwdModel model) { if (model.NewPwd != model.ConfigPwd) { return(Content(this.GetJSON(new { Result = false, Msg = "两次新密码不一致" }))); } HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); int userId = HttpContext.AppUserId(); Tapp_User appUser = ctx.Tapp_User.FirstOrDefault(c => c.Id == userId && c.State == 1); if (appUser == null) { return(Content(this.GetJSON(new { Result = false, Msg = "用户不存在" }))); } string oldPwdDb = Md5.Encrypt(appUser.UserName + model.OldPwd); if (oldPwdDb != appUser.UserPwd) { return(Content(this.GetJSON(new { Result = false, Msg = "旧密码错误" }))); } appUser.UserPwd = Md5.Encrypt(appUser.UserName + model.NewPwd); if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "修改密码成功" }))); } return(Content(this.GetJSON(new { Result = false, Msg = "修改密码失败" }))); }
public ActionResult DeleteMulti(string Id) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string[] arrId = Id.Split(new char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries); int counter = 0; foreach (var item in arrId) { int tid = Convert.ToInt32(item); HR_Employee model = ctx.HR_Employee.FirstOrDefault(c => c.ID == tid); Tapp_User appUser = ctx.Tapp_User.FirstOrDefault(c => c.UserName == model.uid); if (model != null) { model.isDelete = 1; model.Delete_time = DateTime.Now; counter++; } if (appUser != null) { appUser.State = 0; } } if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Id = counter }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", id = counter }), this.JsonContentType())); }
public ActionResult DeleteMulti(string Id) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string[] arrId = Id.Split(new char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries); int counter = 0; Tapp_User user = this.AppUser(); foreach (var item in arrId) { int tid = Convert.ToInt32(item); TErp_Position model = ctx.TErp_Position.FirstOrDefault(c => c.Id == tid); if (model != null) { int postId = model.Id; if (ctx.THR_Needs.Count(c => c.PostId == postId) > 0 || ctx.THR_Recruit.Count(c => c.PostId == postId) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位[" + model.PositionName + "]已被引用,不能删除", Id = counter }), this.JsonContentType())); } model.IsDelete = 1; model.DeleteBy = user.UserName; model.DeleteTime = DateTime.Now; counter++; } } if (ctx.SaveChanges() > 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Id = counter }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", id = counter }), this.JsonContentType())); }
public ActionResult Edit(TErp_Position dto) { if (dto.Id > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string positionName = dto.PositionName; int id = dto.Id; if (ctx.TErp_Position.Count(c => c.PositionName == positionName && c.Id != id && c.IsDelete == 0) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位名称[" + positionName + "]重复" }), this.JsonContentType())); } TErp_Position model = ctx.TErp_Position.FirstOrDefault(c => c.Id == dto.Id); this.CopyObject <TErp_Position>(model, dto); Tapp_User user = this.AppUser(); model.EditBy = user.UserName; model.EditTime = DateTime.Now; if (ctx.SaveChanges() > 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = dto }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败,未找到要修改的数据", Dto = dto }), this.JsonContentType())); } }
public ActionResult Edit(THR_Needs dto) { if (dto.Id > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); //THR_Needs needmodel = ctx.THR_Needs.FirstOrDefault(c => c.DeptId == dto.DeptId && c.PostId == dto.PostId && c.IsDelete == 0 && c.Id != dto.Id); //if (needmodel != null) //{ return Content(this.GetJSON(new { Result = false, Msg = "部门和职位已存在,不能重复添加" }), this.JsonContentType()); } THR_Needs model = ctx.THR_Needs.FirstOrDefault(c => c.Id == dto.Id); if (dto.NeedQuantity < model.HaveBeenQuantity) { return(Content(this.GetJSON(new { Result = false, Msg = "招聘人数不能小于已招聘人数" }), this.JsonContentType())); } this.CopyObject <THR_Needs>(model, dto); Tapp_User user = this.AppUser(); model.EditBy = user.UserName; model.EditTime = DateTime.Now; if (ctx.SaveChanges() >= 0) { var m = ctx.THR_Needs.Where(c => c.Id == dto.Id).Select(c => new Hr_NeedDto { Id = c.Id, DeptId = c.DeptId, DeptName = c.TErp_Department.DeptName, PostId = c.PostId, PostName = c.TErp_Position.PositionName, CutTime = c.CutTime, Demander = c.Demander, NeedQuantity = c.NeedQuantity, Remarks = c.Remarks, CreateBy = c.CreateBy, CreateTime = c.CreateTime, IsDelete = c.IsDelete, DeleteBy = c.DeleteBy, DeleteTime = c.DeleteTime, EditBy = c.EditBy, EditTime = c.EditTime, HaveBeenQuantity = c.HaveBeenQuantity, FileWord = c.FileWord, JobResponsibility = c.JobResponsibility, PostRequest = c.PostRequest, IsHaveBeen = c.IsHaveBeen.Value, InterviewAddress = c.InterviewAddress, Principal = c.Principal }).FirstOrDefault(); HR_Employee emp = ctx.HR_Employee.FirstOrDefault(c => c.uid == model.CreateBy); if (emp != null) { m.CreateBy = emp.name; } return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = m }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败,未找到要修改的数据", Dto = dto }), this.JsonContentType())); } }
public ActionResult ResetUserPwd(string uid) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Tapp_User appUser = ctx.Tapp_User.FirstOrDefault(c => c.UserName == uid); string defaultPwd = Md5.Encrypt(appUser.UserName + "123456"); appUser.UserPwd = defaultPwd; if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功" }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败" }), this.JsonContentType())); } }
public ActionResult UserRight(string userids, string roleids) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string[] arrRoleId = roleids.Split(new char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries); foreach (var username in userids.Split(new char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries)) { Tapp_User appUser = ctx.Tapp_User.FirstOrDefault(c => c.UserName == username); if (appUser == null) { return(Content(this.GetJSON(new { Result = false, Msg = "员工[" + username + "]不存在" }), this.JsonContentType())); } string[] arrDbRoleId = ctx.Tapp_User_Role.Where(c => c.UserId == appUser.Id).Select(c => c.RoleId.ToString()).ToArray(); foreach (var item in arrDbRoleId.Except(arrRoleId)) { //删除 int roleId = Convert.ToInt32(item); Tapp_User_Role right = ctx.Tapp_User_Role.FirstOrDefault(c => c.RoleId == roleId && c.UserId == appUser.Id); if (right != null) { ctx.Tapp_User_Role.Remove(right); } } foreach (var item in arrRoleId.Except(arrDbRoleId)) { //新增 int roleId = Convert.ToInt32(item); Tapp_Role role = ctx.Tapp_Role.FirstOrDefault(c => c.Id == roleId); if (role != null) { ctx.Tapp_User_Role.Add(new Tapp_User_Role { RoleId = roleId, UserId = appUser.Id }); } } } if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功" }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败" }), this.JsonContentType())); } }
public ActionResult Add(HR_Employee dto) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string uid = dto.uid; if (ctx.Tapp_User.Count(c => c.UserName == uid) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "账号[" + uid + "]已使用", Dto = dto }), this.JsonContentType())); } if (!dto.dptid.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "请选择部门", Dto = dto }), this.JsonContentType())); } if (!dto.postid.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "请选择职位", Dto = dto }), this.JsonContentType())); } int deptId = dto.dptid.Value; int postId = dto.postid.Value; if (ctx.TErp_Department.Count(c => c.Id == deptId && c.IsDelete == 0) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "部门不存在", Dto = dto }), this.JsonContentType())); } if (ctx.TErp_Position.Count(c => c.Id == postId && c.IsDelete == 0) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在", Dto = dto }), this.JsonContentType())); } ctx.HR_Employee.Add(dto); Tapp_User use = new Tapp_User(); use.UserName = dto.uid; use.UserPwd = "123456"; use.State = 1; use.UserPwd = Md5.Encrypt(dto.uid + "123456"); ctx.Tapp_User.Add(use); if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = dto }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); }
/// <summary> /// 获取Tapp_User /// </summary> /// <param name="controller"></param> /// <returns></returns> public static Tapp_User AppUser(this Controller controller) { HKSJRecruitmentContext ctx = new HKSJRecruitmentContext(); int userId = HttpContext.Current.AppUserId(); Tapp_User u = ctx.Tapp_User.FirstOrDefault(c => c.Id == userId); if (u != null) { u.UserPwd = string.Empty; u.Tapp_User_Role = null; //HttpContext.Current.Session[UserHelper.SystemUserSessionKey] = u; } return(u); //if (HttpContext.Current.Session[UserHelper.SystemUserSessionKey] == null) //{ //} //return HttpContext.Current.Session[UserHelper.SystemUserSessionKey] as Tapp_User; }
public ActionResult Edit(TErp_Post dto) { if (dto.Id > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); int deptId = dto.DeptId; int positionId = dto.PositionId; if (ctx.TErp_Department.Count(c => c.Id == deptId && c.IsDelete == 0) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "请选择部门" }), this.JsonContentType())); } if (ctx.TErp_Position.Count(c => c.Id == positionId && c.IsDelete == 0) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在,请在职位管理中维护" }), this.JsonContentType())); } TErp_Post model = ctx.TErp_Post.FirstOrDefault(c => c.Id == dto.Id); this.CopyObject <TErp_Post>(model, dto); Tapp_User user = this.AppUser(); model.EditBy = user.UserName; model.EditTime = DateTime.Now; if (ctx.SaveChanges() >= 0) { var m = ctx.TErp_Post.Where(c => c.Id == dto.Id).Select(c => new PostDto { DeptId = c.DeptId, DeptName = c.TErp_Department.DeptName, PositionId = c.PositionId, PositionLevel = c.TErp_Position.PositionLevel, PostDesc = c.PostDesc, PostName = c.PostName, Id = c.Id, PositionName = c.TErp_Position.PositionName }).FirstOrDefault(); return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = m }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败,未找到要修改的数据", Dto = dto }), this.JsonContentType())); } }
public ActionResult Add(TErp_Department dto) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string deptName = dto.DeptName; if (ctx.TErp_Department.Count(c => c.DeptName == deptName && c.IsDelete == 0) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "部门名称[" + deptName + "]重复", Dto = dto }), this.JsonContentType())); } Tapp_User user = this.AppUser(); dto.CreateBy = user.UserName; dto.CreateTime = DateTime.Now; ctx.TErp_Department.Add(dto); if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = dto }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); }
public ActionResult Login(LoginModel model) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); if (Session["ValidateCode"] == null || !string.Equals(model.VerifyCode, Session["ValidateCode"].ToString(), StringComparison.OrdinalIgnoreCase)) { return(Content(this.GetJSON(new { Result = false, Msg = "验证码错误" }))); } Tapp_User appUser = ctx.Tapp_User.FirstOrDefault(c => c.UserName == model.UserName && c.State == 1); if (appUser == null) { return(Content(this.GetJSON(new { Result = false, Msg = "用户名不存在" }))); } string pwdDb = Md5.Encrypt(appUser.UserName + model.UserPwd); if (pwdDb != appUser.UserPwd) { return(Content(this.GetJSON(new { Result = false, Msg = "密码错误" }))); } UserHelper.Login(appUser.Id, appUser.UserName); return(Content(this.GetJSON(new { Result = true, Msg = "成功" }))); }
public ActionResult ImportData() { HttpPostedFileBase postFile = HttpContext.Request.Files[0]; string extension = Path.GetExtension(postFile.FileName).ToLower(); if (extension != ".xls" && extension != ".xlsx") { return(Content(this.GetJSON(new { Result = false, Msg = "文件格式错误" }), this.JsonContentType())); } HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Tapp_User user = this.AppUser(); Workbook workbook = new Workbook(postFile.InputStream); Cells cells = workbook.Worksheets[0].Cells; int rows = cells.MaxDataRow; int cols = cells.MaxDataColumn; if (rows > 0) { List <DepartmentDto> depts = ctx.TErp_Department.Where(c => c.IsDelete == 0).Select(c => new DepartmentDto { Id = c.Id, DeptName = c.DeptName, ParentId = c.ParentId, SeqNo = c.SeqNo, DeptIcon = c.DeptIcon }).ToList(); List <TErp_Position> positions = ctx.TErp_Position.Where(c => c.IsDelete == 0).ToList(); int deptId = 0; int postId = 0; int needQuantity = 0; DateTime cutTime; for (int i = 1; i <= rows; i++) { THR_Needs model = new THR_Needs(); model.CreateBy = user.UserName; model.CreateTime = DateTime.Now; model.IsHaveBeen = 0; model.IsDelete = 0; for (int j = 0; j <= cols; j++) { string itemValue = cells[i, j].StringValue; #region InitModel switch (j) { case 0: deptId = GetDeptId(depts, itemValue); if (deptId == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "导入失败,第" + i + "行,需求部门名称[" + itemValue + "]不存在" }), this.JsonContentType())); } model.DeptId = deptId; break; case 1: postId = GetPositionId(positions, itemValue); if (postId == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "导入失败,第" + i + "行,需求职位名称[" + itemValue + "]不存在" }), this.JsonContentType())); } model.PostId = postId; break; case 2: if (!int.TryParse(itemValue, out needQuantity)) { return(Content(this.GetJSON(new { Result = false, Msg = "导入失败,第" + i + "行,招聘人数[" + itemValue + "]格式错误" }), this.JsonContentType())); } model.NeedQuantity = needQuantity; break; case 3: if (string.IsNullOrEmpty(itemValue)) { return(Content(this.GetJSON(new { Result = false, Msg = "导入失败,第" + i + "行,需求人不能为空" }), this.JsonContentType())); } model.Demander = itemValue; break; case 4: if (!DateTime.TryParse(itemValue, out cutTime)) { return(Content(this.GetJSON(new { Result = false, Msg = "导入失败,第" + i + "行,截止时间格式错误" }), this.JsonContentType())); } model.CutTime = cutTime; break; case 5: model.Principal = itemValue; break; case 6: model.InterviewAddress = itemValue; break; case 7: model.JobResponsibility = itemValue; break; case 8: model.PostRequest = itemValue; break; case 9: model.Remarks = itemValue; break; default: break; } #endregion } ctx.THR_Needs.Add(model); } //List<THR_Needs> needslist = ctx.THR_Needs.ToList(); if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "导入数据成功" }), this.JsonContentType())); } } return(Content(this.GetJSON(new { Result = false, Msg = "数据文件中无数据" }), this.JsonContentType())); }
public ActionResult Edit(HR_Employee dto) { if (dto.ID > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); int id = dto.ID; HR_Employee model = ctx.HR_Employee.FirstOrDefault(c => c.ID == id); if (model == null) { return(Content(this.GetJSON(new { Result = false, Msg = "找不到要修改的员工信息" }), this.JsonContentType())); } if (!dto.dptid.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "部门不能为空" }), this.JsonContentType())); } if (!dto.postid.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不能为空" }), this.JsonContentType())); } int deptId = dto.dptid.Value; int postId = dto.postid.Value; if (ctx.TErp_Department.Count(c => c.Id == deptId && c.IsDelete == 0) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "部门不存在" }), this.JsonContentType())); } if (ctx.TErp_Position.Count(c => c.Id == postId && c.IsDelete == 0) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在" }), this.JsonContentType())); } model.sex = dto.sex; model.idcard = dto.idcard; model.tel = dto.tel; model.EntryDate = dto.EntryDate; model.birthday = dto.birthday; model.dptid = dto.dptid.Value; model.dptname = dto.dptname; model.postid = dto.postid.Value; model.post = dto.post; model.schools = dto.schools; model.education = dto.education; model.status = dto.status; model.address = dto.address; if (dto.status == "离职") { string uid = model.uid; Tapp_User use = ctx.Tapp_User.FirstOrDefault(c => c.UserName == uid); if (use != null) { use.State = 0; } } if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = model }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败" }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败,未找到要修改的数据" }), this.JsonContentType())); } }
public ActionResult Add(THR_Needs dto) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); int deptId = dto.DeptId; int postId = dto.PostId; if (ctx.TErp_Department.Count(c => c.Id == deptId) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "部门不存在,请在组织架构中维护" }), this.JsonContentType())); } if (dto.NeedsPostId > 0) { if (ctx.TErp_Position.Count(c => c.Id == dto.NeedsPostId) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在,请在职位管理中维护" }), this.JsonContentType())); } dto.PostId = dto.NeedsPostId; } else { if (ctx.TErp_Position.Count(c => c.Id == postId) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在,请在职位管理中维护" }), this.JsonContentType())); } dto.NeedsPostId = 0; } if (string.IsNullOrEmpty(dto.CutTime.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "截止时间不能为空" }), this.JsonContentType())); } DateTime cuttime; if (!DateTime.TryParse(dto.CutTime.ToString(), out cuttime) && !string.IsNullOrEmpty(dto.CutTime.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "截止时间格式不正确" }), this.JsonContentType())); } //THR_Needs needmodel = ctx.THR_Needs.FirstOrDefault(c => c.DeptId == dto.DeptId && c.PostId == dto.PostId && c.IsDelete == 0 && c.IsHaveBeen == 0); //if (needmodel != null) //{ return Content(this.GetJSON(new { Result = false, Msg = "部门和职位已存在,不能重复添加" }), this.JsonContentType()); } Tapp_User user = this.AppUser(); dto.CreateBy = user.UserName; dto.CreateTime = DateTime.Now; dto.IsHaveBeen = 0; ctx.THR_Needs.Add(dto); if (ctx.SaveChanges() >= 0) { var model = ctx.THR_Needs.Where(c => c.Id == dto.Id).Select(c => new Hr_NeedDto { Id = c.Id, DeptId = c.DeptId, DeptName = c.TErp_Department.DeptName, PostId = c.PostId, PostName = c.TErp_Position.PositionName, CutTime = c.CutTime, Demander = c.Demander, NeedQuantity = c.NeedQuantity, Remarks = c.Remarks, CreateBy = c.CreateBy, CreateTime = c.CreateTime, IsDelete = c.IsDelete, DeleteBy = c.DeleteBy, DeleteTime = c.DeleteTime, EditBy = c.EditBy, EditTime = c.EditTime, HaveBeenQuantity = c.HaveBeenQuantity, FileWord = c.FileWord, JobResponsibility = c.JobResponsibility, PostRequest = c.PostRequest, IsHaveBeen = c.IsHaveBeen.Value, InterviewAddress = c.InterviewAddress, Principal = c.Principal }).FirstOrDefault(); HR_Employee emp = ctx.HR_Employee.FirstOrDefault(c => c.uid == model.CreateBy); if (emp != null) { model.CreateBy = emp.name; } return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = model }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); }
/// <summary> /// 导入Excel /// </summary> /// <returns></returns> public ActionResult ImportData() { HttpPostedFileBase postFile = HttpContext.Request.Files[0]; string extension = Path.GetExtension(postFile.FileName).ToLower(); if (extension != ".xls" && extension != ".xlsx") { return(Content(this.GetJSON(new { Result = false, Msg = "文件格式错误" }), this.JsonContentType())); } HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Tapp_User user = this.AppUser(); Workbook workbook = new Workbook(postFile.InputStream); Cells cells = workbook.Worksheets[0].Cells; int rows = cells.MaxDataRow; int cols = cells.MaxDataColumn; if (rows > 0) { int dptId = 0; int postId = 0; int status = 0; DateTime interview; DateTime hireTime; for (int i = 1; i <= rows; i++) { THR_Recruit model = new THR_Recruit(); model.CreateBy = user.UserName; model.CreateTime = DateTime.Now; model.IsDelete = 0; model.EntryType = 1; for (int j = 0; j <= cols; j++) { string itemValue = cells[i, j].StringValue; #region InitModel switch (j) { case 0: if (string.IsNullOrEmpty(itemValue)) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,姓名不能为空" }), this.JsonContentType())); } model.Name = itemValue; break; case 1: if (string.IsNullOrEmpty(itemValue)) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,电话不能为空" }), this.JsonContentType())); } if (!Regex.IsMatch(itemValue, @"^-?\d+$")) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,电话格式不合法" }), this.JsonContentType())); } if (IsTel(itemValue) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,电话已存在" }), this.JsonContentType())); } model.Tel = itemValue; break; case 2: dptId = GetDeptId(itemValue); if (dptId == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,部门名称[" + itemValue + "]不存在" }), this.JsonContentType())); } model.DptId = dptId; break; case 3: postId = GetPostId(itemValue); if (postId == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,职位名称[" + itemValue + "]不存在" }), this.JsonContentType())); } model.PostId = postId; break; case 4: status = GetStatus(itemValue); if (status == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,状态名称[" + itemValue + "]不存在" }), this.JsonContentType())); } model.Status = status; break; case 5: if (!DateTime.TryParse(itemValue, out interview) && !string.IsNullOrEmpty(itemValue)) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,面试时间格式不正确" }), this.JsonContentType())); } if (string.IsNullOrEmpty(itemValue)) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,面试时间格式不能为空" }), this.JsonContentType())); } model.Interview = interview; break; case 6: model.Interviewer = itemValue; break; case 7: model.Remark = itemValue; break; case 8: model.Userurl = itemValue; break; case 9: if (!DateTime.TryParse(itemValue, out hireTime) && !string.IsNullOrEmpty(itemValue)) { return(Content(this.GetJSON(new { Result = false, Msg = "第" + i + "行,报到时间格式不正确" }), this.JsonContentType())); } if (string.IsNullOrEmpty(itemValue)) { model.HireTime = null; } else { model.HireTime = hireTime; } break; case 10: model.Email = itemValue; break; default: break; } #endregion } ctx.THR_Recruit.Add(model); } if (ctx.SaveChanges() > 0) { //RecruitModel m = GetRecruitModel(model.Id, ctx); return(Content(this.GetJSON(new { Result = true, Msg = "导入数据成功" }), this.JsonContentType())); } } return(Content(this.GetJSON(new { Result = false, Msg = "数据文件中无数据" }), this.JsonContentType())); }