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); THR_Needs model = ctx.THR_Needs.FirstOrDefault(c => c.Id == tid); if (model != null) { if (model.HaveBeenQuantity > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "该招聘需求在招聘信息中已被引用不能删除!" }), 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 FileWordData(string pid) { int id = 0; if (!string.IsNullOrEmpty(pid)) { id = int.Parse(pid); } if (id > 0) { HttpPostedFileBase postFile = HttpContext.Request.Files[0]; string extension = Path.GetExtension(postFile.FileName).ToLower(); if (extension != ".doc" && extension != ".docx") { return(Content(this.GetJSON(new { Result = false, Msg = "文件格式错误,支持.doc或.docx" }), this.JsonContentType())); } string filename = postFile.FileName.Substring(postFile.FileName.LastIndexOf("\\") + 1); string houzhui = postFile.FileName.Substring(postFile.FileName.LastIndexOf(".") + 1); string name = DateTime.Now.ToString("yyyyMMddHHmmss");//重新命名 postFile.SaveAs(Server.MapPath(@"/UploadFiles/" + name + filename)); HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); THR_Needs model = ctx.THR_Needs.FirstOrDefault(c => c.Id == id); model.FileWord = name + filename; if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "上传试题成功" }), 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 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 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 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())); }
public ActionResult Edit(THR_Recruit dto) { if (dto.Id > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); if (ctx.THR_Recruit.Count(c => c.Tel == dto.Tel && c.IsDelete == 0 && c.Id != dto.Id) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "电话已存在" }), this.JsonContentType())); } if (!dto.DptId.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "部门不存在,请在组织架构中维护" }), this.JsonContentType())); } int dptId = dto.DptId.Value; if (ctx.TErp_Department.Count(c => c.Id == dptId) == 0) { 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 postId = dto.PostId.Value; if (ctx.TErp_Position.Count(c => c.Id == postId) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在,请在职位管理中维护" }), this.JsonContentType())); } if (!dto.Status.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "状态不存在,请在参数配置中维护" }), this.JsonContentType())); } int status = dto.Status.Value; if (ctx.Tapp_Param.Count(c => c.Id == status) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "状态不存在,请在参数配置中维护" }), this.JsonContentType())); } if (string.IsNullOrEmpty(dto.Interview.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "面试时间不能为空" }), this.JsonContentType())); } DateTime interview; if (!DateTime.TryParse(dto.Interview.ToString(), out interview) && !string.IsNullOrEmpty(dto.Interview.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "面试时间格式不正确" }), this.JsonContentType())); } DateTime hireTime; if (!DateTime.TryParse(dto.HireTime.ToString(), out hireTime) && !string.IsNullOrEmpty(dto.HireTime.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "报道时间格式不正确" }), this.JsonContentType())); } if (dto.NeedsId == 0 || dto.NeedsId == null) { return(Content(this.GetJSON(new { Result = false, Msg = "招聘需求不能为空" }), this.JsonContentType())); } //THR_Recruit model = ctx.THR_Recruit.Include("THR_Needs").FirstOrDefault(c => c.Id == dto.Id); THR_Recruit model = ctx.THR_Recruit.FirstOrDefault(c => c.Id == dto.Id); //if (model.Status == 82) //{ // return Content(this.GetJSON(new { Result = false, Msg = "已录用的招聘信息不能修改" }), this.JsonContentType()); //} if (dto.Status == 82 && dto.Status != model.Status)//已录用 { THR_Needs needsmodel = ctx.THR_Needs.FirstOrDefault(c => c.Id == dto.NeedsId); int Quantity = ctx.THR_Recruit .Where(c => c.IsDelete == 0 && c.NeedsId == dto.NeedsId && c.Status == dto.Status).ToList().Count;//已录用 if (needsmodel.NeedQuantity <= Quantity) { return(Content(this.GetJSON(new { Result = false, Msg = "招聘人数已达到招聘需求数,请新增或变更招聘需求!" }), this.JsonContentType())); } } this.CopyObject <THR_Recruit>(model, dto); model.EditTime = DateTime.Now; model.EditBy = this.AppUser().UserName; if (ctx.SaveChanges() >= 0) { RecruitModel m = GetRecruitModel(dto.Id, ctx); 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(THR_Recruit dto) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); if (!dto.DptId.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "部门不存在,请在组织架构中维护" }), this.JsonContentType())); } int dptId = dto.DptId.Value; if (ctx.TErp_Department.Count(c => c.Id == dptId) == 0) { 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 postId = dto.PostId.Value; if (ctx.TErp_Position.Count(c => c.Id == postId) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "职位不存在,请在职位管理中维护" }), this.JsonContentType())); } if (!dto.Status.HasValue) { return(Content(this.GetJSON(new { Result = false, Msg = "状态不存在,请在参数配置中维护" }), this.JsonContentType())); } int status = dto.Status.Value; if (ctx.Tapp_Param.Count(c => c.Id == status) == 0) { return(Content(this.GetJSON(new { Result = false, Msg = "状态不存在,请在参数配置中维护" }), this.JsonContentType())); } if (string.IsNullOrEmpty(dto.Interview.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "面试时间不能为空" }), this.JsonContentType())); } DateTime interview; if (!DateTime.TryParse(dto.Interview.ToString(), out interview) && !string.IsNullOrEmpty(dto.Interview.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "面试时间格式不正确" }), this.JsonContentType())); } DateTime hireTime; if (!DateTime.TryParse(dto.HireTime.ToString(), out hireTime) && !string.IsNullOrEmpty(dto.HireTime.ToString())) { return(Content(this.GetJSON(new { Result = false, Msg = "报道时间格式不正确" }), this.JsonContentType())); } if (dto.NeedsId == 0 || dto.NeedsId == null) { return(Content(this.GetJSON(new { Result = false, Msg = "招聘需求不能为空" }), this.JsonContentType())); } if (dto.Status == 82)//已录用 { THR_Needs needmodel = ctx.THR_Needs.FirstOrDefault(c => c.Id == dto.NeedsId); int Quantity = ctx.THR_Recruit .Where(c => c.IsDelete == 0 && c.NeedsId == dto.NeedsId && c.Status == dto.Status).ToList().Count;//已录用 if (needmodel.NeedQuantity <= Quantity) { return(Content(this.GetJSON(new { Result = false, Msg = "招聘人数已达到招聘需求数,请新增或变更招聘需求!" }), this.JsonContentType())); } //needmodel.HaveBeenQuantity = Quantity + 1; //if (needmodel.HaveBeenQuantity == needmodel.NeedQuantity) //{ needmodel.IsHaveBeen = 1; } } TErp_Department dept = ctx.TErp_Department.FirstOrDefault(c => c.Id == dto.DptId.Value); dept.SeqNo = dept.SeqNo + 1; if (ctx.THR_Recruit.Count(c => c.Tel == dto.Tel && c.IsDelete == 0) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "电话已存在" }), this.JsonContentType())); } dto.CreateTime = DateTime.Now; dto.CreateBy = this.AppUser().UserName; dto.IsDelete = 0; dto.EntryType = 1; ctx.THR_Recruit.Add(dto); if (ctx.SaveChanges() > 0) { RecruitModel model = GetRecruitModel(dto.Id, ctx); return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = model }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); }