Example #1
0
        public JsonResult Add(AddPrivilegeModel model)
        {
            JsonResult json = new JsonResult();

            if (string.IsNullOrEmpty(model.privilegeName))
            {
                return(Json(new { success = false, msg = "权限名称不为空" }, "text/json"));
            }
            if (model.menuId == 0)
            {
                return(Json(new { success = false, msg = "请选择相应的菜单" }, "text/json"));
            }
            Privilege mPrivilege = db.Privilege.Where(m => m.privilegeName == model.privilegeName).FirstOrDefault();

            if (mPrivilege != null)
            {
                return(Json(new { success = false, msg = "该权限已经存在,请更换权限名称" }, "text/json"));
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    Privilege privilege = new Privilege
                    {
                        privilegeName = model.privilegeName,
                        privilegeNote = model.privilegeNote
                    };
                    db.Privilege.Add(privilege);
                    MenuPrivilege menuPrivilege = new MenuPrivilege
                    {
                        menuId      = model.menuId,
                        privilegeId = model.privilegeId
                    };
                    db.MenuPrivilege.Add(menuPrivilege);
                    if (db.SaveChanges() > 0)
                    {
                        json.Data = new { success = true, msg = "添加成功!" };
                    }
                    else
                    {
                        json.Data = new { success = false, msg = "添加失败!" };
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
                scope.Complete();
            }
            return(json);
        }
Example #2
0
        public JsonResult Add(AddMenuModel model)
        {
            JsonResult json = new JsonResult();

            if (string.IsNullOrEmpty(model.menuName))
            {
                return(Json(new { success = false, msg = "菜单名称不为空" }, "text/json"));
            }
            if (string.IsNullOrEmpty(model.menuUrl))
            {
                return(Json(new { success = false, msg = "菜单Url不为空" }, "text/json"));
            }
            Menu mMenu = db.Menu.Where(m => m.menuName == model.menuName).FirstOrDefault();

            if (mMenu != null)
            {
                return(Json(new { success = false, msg = "该菜单已经存在,请更换菜单名称" }, "text/json"));
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    Menu menu = new Menu
                    {
                        menuName     = model.menuName,
                        menuUrl      = model.menuUrl,
                        menuNote     = model.menuNote,
                        parentMenuId = model.menuId
                    };
                    db.Menu.Add(menu);
                    if (db.SaveChanges() > 0)
                    {
                        json.Data = new { success = true, msg = "添加成功!" };
                    }
                    else
                    {
                        json.Data = new { success = false, msg = "添加失败!" };
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
                scope.Complete();
            }
            return(json);
        }
Example #3
0
        public JsonResult Add(AddRoleModel model, string pIds)
        {
            JsonResult json = new JsonResult();

            if (string.IsNullOrEmpty(model.roleName))
            {
                return(Json(new { success = false, msg = "角色名称不为空" }, "text/json"));
            }
            Role mrRole = db.Role.Where(m => m.roleName == model.roleName).FirstOrDefault();

            if (mrRole != null)
            {
                return(Json(new { success = false, msg = "角色名称已经存在" }, "text/json"));
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    Role role = new Role
                    {
                        roleName = model.roleName,
                        roleNote = model.roleNote
                    };
                    db.Role.Add(role);
                    RolePrivilege rolePrivilege = new RolePrivilege
                    {
                        roleId       = model.roleId,
                        privilegeIds = pIds
                    };
                    db.RolePrivilege.Add(rolePrivilege);
                    if (db.SaveChanges() > 0)
                    {
                        json.Data = new { success = true, msg = "添加成功!" };
                    }
                    else
                    {
                        json.Data = new { success = false, msg = "添加失败!" };
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
                scope.Complete();
            }
            return(json);
        }
Example #4
0
        public JsonResult AddUser(AddUserModel model)
        {
            JsonResult json = new JsonResult();

            if (string.IsNullOrEmpty(model.userName))
            {
                return(Json(new { success = false, msg = "用户名不能为空" }, "text/json"));
            }
            if (string.IsNullOrEmpty(model.UserProfile.password))
            {
                return(Json(new { success = false, msg = "密码不能为空" }, "text/json"));
            }
            User mUser = db.User.Where(m => m.userName == model.userName).FirstOrDefault();

            if (mUser != null)
            {
                return(Json(new { success = false, msg = "该用户已经存在,请更换用户名" }, "text/json"));
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    User user = new User
                    {
                        userName = model.userName
                    };
                    db.User.Add(user);
                    string      msalt       = Utils.GetCheckCode(6);
                    UserProfile userProfile = new UserProfile
                    {
                        //获得6位的salt加密字符串
                        salt       = msalt,
                        userId     = user.userId,
                        password   = DESEncrypt.Encrypt(model.UserProfile.password, msalt),
                        createDate = DateTime.Now,
                        userNote   = model.UserProfile.userNote,
                        avatar     = model.UserProfile.avatar
                    };
                    db.UserProfile.Add(userProfile);

                    UserRole userRole = new UserRole
                    {
                        userId = user.userId,
                        roleId = model.roleId
                    };
                    db.UserRole.Add(userRole);
                    if (db.SaveChanges() > 0)
                    {
                        json.Data = new { success = true, msg = "添加成功!" };
                    }
                    else
                    {
                        json.Data = new { success = false, msg = "添加失败!" };
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
                scope.Complete();
            }
            return(json);
        }
Example #5
0
        public ActionResult AddCustomer(AddCustomerModel model)
        {
            JsonResult json = new JsonResult();

            if (string.IsNullOrEmpty(model.customerName))
            {
                return(Json(new { success = false, msg = "客户姓名不能为空" }, "text/json"));
            }
            if (string.IsNullOrEmpty(model.IdCard))
            {
                return(Json(new { success = false, msg = "身份证号码不能为空" }, "text/json"));
            }
            if (string.IsNullOrEmpty(model.telphone))
            {
                return(Json(new { success = false, msg = "座机电话不能为空" }, "text/json"));
            }
            if (string.IsNullOrEmpty(model.mobile))
            {
                return(Json(new { success = false, msg = "移动电话不能为空" }, "text/json"));
            }
            Customer mCustomer = db.Customer.Where(m => m.IdCard == model.IdCard).FirstOrDefault();

            if (mCustomer != null)
            {
                return(Json(new { success = false, msg = "该身份证号码已经存在,请更换身份证号" }, "text/json"));
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    Customer customer = new Customer()
                    {
                        customerName    = model.customerName,
                        IdCard          = model.IdCard,
                        domicilePlace   = model.domicilePlace,
                        sex             = model.sex,
                        birthday        = model.birthday,
                        expireOfId      = model.expireOfId,
                        mobile          = model.mobile,
                        telphone        = model.telphone,
                        educationLevel  = model.educationLevel,
                        occupation      = model.occupation,
                        workUnit        = model.workUnit,
                        incomeOfYear    = model.incomeOfYear,
                        healthStatus    = model.healthStatus,
                        bankAccount     = model.bankAccount,
                        accountName     = model.accountName,
                        badRecord       = model.badRecord,
                        debtValue       = model.debtValue,
                        houseRight      = model.houseRight,
                        houseEvaluation = model.houseEvaluation,
                        spouseName      = model.spouseName,
                        spouseIdCard    = model.spouseIdCard,
                        recentPhoto     = model.recentPhoto,
                        remarks         = model.remarks
                    };
                    db.Customer.Add(customer);
                    if (db.SaveChanges() > 0)
                    {
                        json.Data = new { success = true, msg = "添加成功!" };
                    }
                    else
                    {
                        json.Data = new { success = false, msg = "添加失败!" };
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    throw;
                }
                scope.Complete();
            }
            return(json);
        }