示例#1
0
        /// <summary>
        /// 删除公司
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool DeleteCorporation(DeleteCorporationRQ request)
        {
            //删除所选公司包括子公司
            //删除公司下的所有部门包括子部门
            //解除部门与用户的关系
            var deleteCorpIds = request.DeleteCorpIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                                .Select(p => p.ToInt()).ToList();

            using (var db = new WebFrameworksDB())
            {
                var deleteCorps = db.Corporation.Where(p => deleteCorpIds.Contains(p.Id)).ToList();
                if (deleteCorps.HasValue())
                {
                    db.Corporation.RemoveRange(deleteCorps);
                }

                var deleteDeptIds = new List <int>();
                var deleteDepts   = db.Department.Where(p => deleteCorpIds.Contains(p.CorporationId)).ToList();
                if (deleteDepts.HasValue())
                {
                    deleteDeptIds = deleteDepts.Select(p => p.Id).ToList();
                    db.Department.RemoveRange(deleteDepts);
                }

                var deleteUserDepts = db.UserDepartment.Where(p => deleteDeptIds.Contains(p.DepartmentId)).ToList();
                if (deleteUserDepts.HasValue())
                {
                    db.UserDepartment.RemoveRange(deleteUserDepts);
                }

                //事务提交
                if (db.SaveChanges() > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#2
0
        /// <summary>
        /// 删除公司
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public WebFxsResult <bool> DeleteCorporation(DeleteCorporationRQ request)
        {
            //删除所选公司包括子公司
            //删除公司下的所有部门包括子部门
            //解除部门与用户的关系
            var result = new WebFxsResult <bool>
            {
                ReturnCode = ReturnCodeType.Error,
                Content    = false
            };

            var rs = repository.DeleteCorporation(request);

            if (rs == true)
            {
                result.ReturnCode = ReturnCodeType.Success;
                result.Content    = true;
            }

            return(result);
        }
        public ActionResult Delete(DeleteCorporationRQ request)
        {
            var flag = false;
            var msg  = string.Empty;

            using (var factory = new ChannelFactory <IWebFxsCorporationService>("*"))
            {
                var client = factory.CreateChannel();
                var rs     = client.DeleteCorporation(request);
                if (rs.ReturnCode == ReturnCodeType.Success)
                {
                    flag = true;
                    msg  = "删除成功!";
                }
                else
                {
                    msg = "删除失败!";
                }
            }

            return(Json(new { success = flag, msg = msg }, JsonRequestBehavior.AllowGet));
        }