public JsonResult Create([Bind(Include = "Name,remark,isNecessary")] CertificateType certf) { ResultMessage msg = new ResultMessage(); try { msg = DoValidation(certf); if (!msg.Success) { return(Json(msg, JsonRequestBehavior.AllowGet)); } else { ICertificateTypeService cs = new CertificateTypeService(Settings.Default.db); //是否是系统(默认为false,用户建立的都是false,即在用户端不可见此字段) certf.isSystem = false; bool isSucceed = cs.Create(certf); msg.Success = isSucceed; msg.Content = isSucceed ? "" : "添加失败"; return(Json(msg, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new ResultMessage() { Success = false, Content = ex.Message }, JsonRequestBehavior.AllowGet)); } }
//bind CertificateType private void SetCertificateTypeList(int?type, bool allowBlank = true) { ICertificateTypeService cs = new CertificateTypeService(Settings.Default.db); CertificateTypeSearchModel csm = new CertificateTypeSearchModel(); List <CertificateType> certType = cs.Search(csm).ToList(); List <SelectListItem> select = new List <SelectListItem>(); if (allowBlank) { select.Add(new SelectListItem { Text = "", Value = "" }); } foreach (var certt in certType) { if (type.HasValue && type.ToString().Equals(certt.id)) { select.Add(new SelectListItem { Text = certt.name, Value = certt.id.ToString(), Selected = true }); } else { select.Add(new SelectListItem { Text = certt.name, Value = certt.id.ToString(), Selected = false }); } } ViewData["certificateTypeList"] = select; }
// GET: CertificateType/Delete/5 public ActionResult Delete(int id) { ICertificateTypeService cs = new CertificateTypeService(Settings.Default.db); CertificateType certf = cs.FindById(id); SetDropDownList(certf); return(View(certf)); }
//(列表(分页)、新建、删除(系统级别不可编辑删除)(存在员工时不可删除) //):名称(不可空),是否是系统(默认为false,用户建立的都是false,即在用户端不可见此字段),是否是必须(默认为false),备注(可空) // 系统自建系统级别类别:身份证(非必须)、健康证(非必须)、职业证书(非必须) public ResultMessage DoValidation(CertificateType model) { ResultMessage msg = new ResultMessage(); if (string.IsNullOrEmpty(model.name)) { msg.Success = false; msg.Content = "证照类别名称不能为空"; return(msg); } ICertificateTypeService cs = new CertificateTypeService(Settings.Default.db); List <CertificateType> shift = cs.GetAll(); if (model.id <= 0) { bool isRecordExists = shift.Where(p => p.name == model.name).ToList().Count() > 0; if (isRecordExists) { msg.Success = false; msg.Content = "数据已经存在!"; return(msg); } } else { bool isSystem = shift.Where(p => p.isSystem && p.id == model.id).ToList().Count() > 0; if (isSystem) { msg.Success = false; msg.Content = "系统级别不可编辑"; return(msg); } bool isRecordExists = shift.Where(p => p.name == model.name && p.id != model.id).ToList().Count() > 0; if (isRecordExists) { msg.Success = false; msg.Content = "数据已经存在!"; return(msg); } } return(new ResultMessage() { Success = true, Content = "" }); }
public JsonResult Delete(int id, FormCollection collection) { ResultMessage msg = new ResultMessage(); try { //存在员工时不可删除 ICertificateService shfSi = new CertificateService(Settings.Default.db); List <Certificate> shf = shfSi.FindByCertificateType(id); if (null != shf && shf.Count() > 0) { msg.Success = false; msg.Content = "证照类别正在使用,不能删除!"; return(Json(msg, JsonRequestBehavior.AllowGet)); } else { ICertificateTypeService cs = new CertificateTypeService(Settings.Default.db); //系统级别不可编辑删除 List <CertificateType> cers = cs.GetAll(); bool isSystem = cers.Where(p => p.isSystem && p.id == id).ToList().Count() > 0; if (isSystem) { msg.Success = false; msg.Content = "系统级别不可删除"; return(Json(msg, JsonRequestBehavior.AllowGet)); } else { bool isSucceed = cs.DeleteById(id); msg.Success = isSucceed; msg.Content = isSucceed ? "" : "删除失败"; return(Json(msg, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(new ResultMessage() { Success = false, Content = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Search([Bind(Include = "Name")] CertificateTypeSearchModel q) { int pageIndex = 0; int.TryParse(Request.QueryString.Get("page"), out pageIndex); pageIndex = PagingHelper.GetPageIndex(pageIndex); ICertificateTypeService ss = new CertificateTypeService(Settings.Default.db); IPagedList <CertificateType> certfs = ss.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize); ViewBag.Query = q; return(View("Index", certfs)); }
private void SetJobCertificateTypeList(List <JobCertificate> jobCertis, bool allowBlank = false) { ICertificateTypeService cs = new CertificateTypeService(Settings.Default.db); CertificateTypeSearchModel csm = new CertificateTypeSearchModel(); List <CertificateType> certType = cs.Search(csm).ToList(); List <SelectListItem> select = new List <SelectListItem>(); if (allowBlank) { select.Add(new SelectListItem { Text = "", Value = "" }); } foreach (var certt in certType) { if (jobCertis != null) { bool hasSelected = jobCertis.Where(k => k.certificateTypeId == certt.id).ToList().Count() > 0; if (hasSelected) { select.Add(new SelectListItem { Text = certt.name, Value = certt.id.ToString(), Selected = true }); } else { select.Add(new SelectListItem { Text = certt.name, Value = certt.id.ToString(), Selected = false }); } } else { select.Add(new SelectListItem { Text = certt.name, Value = certt.id.ToString(), Selected = false }); } } ViewData["jobCertificateTypeList"] = select; }
public ActionResult Index(int?page) { int pageIndex = PagingHelper.GetPageIndex(page); CertificateTypeSearchModel q = new CertificateTypeSearchModel(); ICertificateTypeService ss = new CertificateTypeService(Settings.Default.db); IPagedList <CertificateType> certfs = ss.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize); ViewBag.Query = q; CertificateTypeInfoModel info = ss.GetCertificateTypeInfo(q); ViewBag.Info = info; return(View(certfs)); }