Esempio n. 1
0
        public JsonResult AddUser()
        {
            JsonUserAddUserEntity json = new JsonUserAddUserEntity();
            string name         = CommonHelper.GetPostValue("username");
            string password     = CommonHelper.GetPostValue("password");
            string realname     = CommonHelper.GetPostValue("realname");
            string phone        = CommonHelper.GetPostValue("phone");
            string email        = CommonHelper.GetPostValue("email");
            int    roleid       = CommonHelper.GetPostValue("roleid").ToInt(-1);
            int    areaid       = CommonHelper.GetPostValue("areaid").ToInt(-1);
            int    shopid       = CommonHelper.GetPostValue("shopid").ToInt(-1);
            int    departmentId = CommonHelper.GetPostValue("departmentId").ToInt(-1);

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password) || roleid < 0 || areaid < 0 || shopid < 0 || departmentId < 0)
            {
                json.ErrorCode    = "E001";
                json.ErrorMessage = "参数不全!";
                return(Json(json));
            }

            name     = HttpUtility.UrlDecode(name);
            realname = HttpUtility.UrlDecode(realname);

            T_BG_User user = new T_BG_User();

            user.Phone        = phone;
            user.Name         = name;
            user.RealName     = realname;
            user.PassWord     = password;
            user.Email        = email;
            user.RoleID       = roleid;
            user.ShopID       = shopid;
            user.Status       = 0;
            user.AddTime      = DateTime.Now;
            user.IsDel        = 0;
            user.DepartmentId = departmentId;
            user.AreaId       = areaid;

            bool result = _bgUserService.Add(user);

            if (result)
            {
                json.ErrorCode    = "E000";
                json.ErrorMessage = "添加成功!";
            }
            else
            {
                json.ErrorCode    = "E002";
                json.ErrorMessage = "添加失败!";
            }
            return(Json(json));
        }
Esempio n. 2
0
        /// <summary>
        /// 添加或者修改用户
        /// </summary>
        /// <returns></returns>
        public JsonResult AddOrUpdateUser()
        {
            JsonUserAddUserEntity json = new JsonUserAddUserEntity();
            string   realname          = CommonHelper.GetPostValue("realname");
            int      gender            = CommonHelper.GetPostValue("gender").ToInt(-1);
            long     positionId        = CommonHelper.GetPostValue("positionId").ToLong(-1);
            DateTime entryDate         = CommonHelper.GetPostValue("entryDate").ToDateTime(DateTime.MaxValue);
            string   identity          = CommonHelper.GetPostValue("identity");
            string   phone             = CommonHelper.GetPostValue("phone");
            long     educationId       = CommonHelper.GetPostValue("educationId").ToLong(-1);
            long     householdId       = CommonHelper.GetPostValue("householdId").ToLong(-1);
            string   school            = CommonHelper.GetPostValue("school");
            string   email             = CommonHelper.GetPostValue("email");
            string   emergency         = CommonHelper.GetPostValue("emergency");
            string   address           = CommonHelper.GetPostValue("address");
            string   remark            = CommonHelper.GetPostValue("remark");
            int      add = CommonHelper.GetPostValue("add").ToInt(0);      //0=添加 1=修改
            long     id  = CommonHelper.GetPostValue("id").ToLong(-1);

            if ((string.IsNullOrEmpty(realname) || gender == -1 || positionId == -1 || entryDate == DateTime.MaxValue || string.IsNullOrEmpty(identity) || householdId == -1 || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(emergency) || string.IsNullOrEmpty(address)) || (add == 1 && id < 0))
            {
                json.ErrorCode    = "E001";
                json.ErrorMessage = "参数不全!";
                return(Json(json));
            }

            realname  = HttpUtility.UrlDecode(realname);
            school    = HttpUtility.UrlDecode(school);
            emergency = HttpUtility.UrlDecode(emergency);
            address   = HttpUtility.UrlDecode(address);
            remark    = HttpUtility.UrlDecode(remark);

            T_BG_User user = null;

            if (add == 0)
            {
                user = new T_BG_User();
            }
            else
            {
                user = _bgUserService.GetUserById(id);
                if (user == null)
                {
                    json.ErrorCode    = "E003";
                    json.ErrorMessage = "未获得该修改对象!";
                    return(Json(json));
                }
            }

            T_BG_Position p = _bgPositionService.GetByPositionId(positionId);

            if (p == null)
            {
                json.ErrorCode    = "E003";
                json.ErrorMessage = "未获得该修改员工职位信息!";
                return(Json(json));
            }

            user.RealName    = realname;
            user.Gender      = gender;
            user.PositionId  = positionId;
            user.EntryDate   = entryDate;
            user.IP          = identity;
            user.Phone       = phone;
            user.EducationId = educationId;
            user.HouseholdId = householdId;
            user.School      = school;
            user.Email       = email;
            user.Emergency   = emergency;
            user.Address     = address;
            user.Remark      = remark;
            user.Lvl         = p.Lvl;

            bool result = false;

            if (add == 0)
            {
                user.DepartmentId = LoginHelper.DepartmentId;
                user.Status       = 0;
                user.AddTime      = DateTime.Now;
                user.IsDel        = 0;
                user.AreaId       = LoginHelper.AreaId;
                user.ShopID       = LoginHelper.ShopID;        //这个后期可能需要修改
                user.RoleID       = 2;
                result            = _bgUserService.Add(user);
            }
            else
            {
                result = _bgUserService.Update(user);
            }

            if (result)
            {
                json.ErrorCode    = "E000";
                json.ErrorMessage = "成功!";
            }
            else
            {
                json.ErrorCode    = "E002";
                json.ErrorMessage = "数据库操作失败!";
            }
            return(Json(json));
        }