Ejemplo n.º 1
0
        //(列表(分页)、新建、删除(系统级别不可编辑删除)(存在员工时不可删除)
        //):名称(不可空),是否是系统(默认为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 = ""
            });
        }
Ejemplo n.º 2
0
        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));
            }
        }