Exemplo n.º 1
0
        public bool AddExpress(base_exp_comp proclassfy, out int isexit, out int id)
        {
            using (var db = SugarDao.GetInstance(LoginUser.GetConstr()))
            {
                try
                {
                    //1.先判断是否存在
                    var singleOrDefault = db.Queryable <base_exp_comp>().SingleOrDefault(c => c.express_name == proclassfy.express_name);
                    if (singleOrDefault != null && singleOrDefault.del_flag == false)//代表已存在数据库且被删除
                    {
                        isexit = 1;
                        id     = singleOrDefault.express_id;
                        return(false);
                    }
                    if (singleOrDefault != null && singleOrDefault.del_flag == true)//代表已存在数据库未被删除
                    {
                        isexit = 2;
                        id     = singleOrDefault.express_id;
                        return(false);
                    }
                    //2.不存在再添加
                    db.DisableInsertColumns = new string[] { "edit_time" };//edit_time列将不会插入值
                    var myid = db.Insert <base_exp_comp>(proclassfy);

                    if (myid.ObjToInt() > 0)
                    {
                        isexit = 0;
                        id     = myid.ObjToInt();
                        return(true);
                    }
                    else
                    {
                        isexit = 0;
                        id     = myid.ObjToInt();
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult AddExpress(string expressname)
        {
            DBModel.Common.ComResult res = new DBModel.Common.ComResult();
            try
            {
                if (!Regex.IsMatch(expressname, @"(?i)^[0-9a-z\u4e00-\u9fa5]+$") && !string.IsNullOrEmpty(expressname))
                {
                    res.Msg   = "分类名称不能有非法字符";
                    res.State = 0;
                    return(Json(res));
                }
                if (string.IsNullOrEmpty(expressname))
                {
                    res.Msg   = "分类名称不能为空";
                    res.State = 0;
                    return(Json(res));
                }
                base_exp_comp pro = new base_exp_comp();
                pro.country_id      = 0;;
                pro.create_time     = DateTime.Now;
                pro.create_user_id  = LoginUser.Current.user_id;
                pro.del_flag        = true;
                pro.del_time        = DateTime.Now;
                pro.del_user_id     = 0;
                pro.edit_time       = DateTime.Now;
                pro.edit_user_id    = 0;
                pro.express_descrip = "";
                pro.express_name    = expressname;
                pro.express_status  = true;
                pro.remark          = "";

                int  isexit = 0;
                int  id     = 0;
                bool isok   = _service.AddExpress(pro, out isexit, out id);
                if (1 == isexit)
                {
                    res.Msg   = "此快递类型已存在且被删除是否恢复?";
                    res.URL   = id.ToString();
                    res.State = 2;
                    return(Json(res));
                }
                if (2 == isexit)
                {
                    res.Msg   = "已存在此快递类型";
                    res.State = 0;
                    return(Json(res));
                }
                if (isok)
                {
                    res.Msg   = "添加成功";
                    res.State = 1;
                    res.URL   = "/Express/Index";
                    return(Json(res));
                }
                else
                {
                    res.Msg   = "添加失败";
                    res.State = 0;
                    return(Json(res));
                }
            }
            catch (Exception ex)
            {
                res.Msg   = ex.ToString();
                res.State = 0;
                return(Json(res));
            }
        }