コード例 #1
0
        public Common.ClientResult.Result EditRoleUser(string ID, [FromBody] RoleUserModel data)
        {
            ValidationErrors validationErrors = new ValidationErrors();
            StringBuilder    sbError          = new StringBuilder();
            SysEntities      SysEntitiesO2O   = new SysEntities();
            int RoleID = Convert.ToInt32(ID);

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    JavaScriptSerializer ser       = new JavaScriptSerializer();
                    RoleUserModel        listModel = ser.Deserialize <RoleUserModel>(data.DataInfo);
                    if (listModel != null)
                    {
                        if (!string.IsNullOrEmpty(listModel.ReturnData[0].DepartID.ToString()))
                        {
                            var aa = SysEntitiesO2O.ORG_UserRole.Where(a => a.ORG_Role_ID == RoleID);

                            if (aa.Count() > 0)
                            {
                                foreach (var item in aa)
                                {
                                    SysEntitiesO2O.ORG_UserRole.Remove(item);
                                    SysEntitiesO2O.SaveChanges();
                                }
                            }
                            //插入
                            for (int i = 0; i < listModel.ReturnData.Count; i++)
                            {
                                ORG_UserRole RoleUser = new ORG_UserRole();
                                RoleUser.ORG_Role_ID = RoleID;
                                RoleUser.ORG_User_ID = Convert.ToInt32(listModel.ReturnData[i].UserID);
                                SysEntitiesO2O.ORG_UserRole.Add(RoleUser);
                                SysEntitiesO2O.SaveChanges();
                            }
                        }
                    }
                    scope.Complete();
                    Common.ClientResult.Result result = new Common.ClientResult.Result();
                    result.Code    = ClientCode.Succeed;
                    result.Message = "保存成功";
                    return(result);
                }
            }
            catch (Exception er)
            {
                Common.ClientResult.Result result = new Common.ClientResult.Result();
                result.Code    = ClientCode.Fail;
                result.Message = "保存失败";
                return(result);
            }
        }
コード例 #2
0
 /// <summary>
 /// 创建一个组织机构_人员角色
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个组织机构_人员角色</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, ORG_UserRole entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }