Exemplo n.º 1
0
        public Common.ClientResult.Result EditGroupUser(string ID, [FromBody] GroupUserModel data)
        {
            ValidationErrors validationErrors = new ValidationErrors();
            StringBuilder    sbError          = new StringBuilder();
            SysEntities      SysEntitiesO2O   = new SysEntities();
            int GroupID = Convert.ToInt32(ID);

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    JavaScriptSerializer ser       = new JavaScriptSerializer();
                    GroupUserModel       listModel = ser.Deserialize <GroupUserModel>(data.DataInfo);
                    if (listModel != null)
                    {
                        if (!string.IsNullOrEmpty(listModel.ReturnData[0].DepartID.ToString()))
                        {
                            var aa = SysEntitiesO2O.ORG_GroupUser.Where(a => a.ORG_Group_ID == GroupID);
                            //List<ORG_GroupUser> customer = from c in SysEntitiesO2O.ORG_GroupUser
                            //                where c.ID == GroupID
                            //                select c;
                            if (aa.Count() > 0)
                            {
                                foreach (var item in aa)
                                {
                                    SysEntitiesO2O.ORG_GroupUser.Remove(item);
                                    SysEntitiesO2O.SaveChanges();
                                }
                            }
                            //插入
                            for (int i = 0; i < listModel.ReturnData.Count; i++)
                            {
                                ORG_GroupUser GroupUser = new ORG_GroupUser();
                                GroupUser.ORG_Group_ID = GroupID;
                                GroupUser.ORG_User_ID  = Convert.ToInt32(listModel.ReturnData[i].UserID);
                                SysEntitiesO2O.ORG_GroupUser.Add(GroupUser);
                                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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 创建一个ORG_GroupUser
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个ORG_GroupUser</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, ORG_GroupUser entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }