Beispiel #1
0
        /// <summary>
        /// 通过父类编号获取子类编号并序列化为json
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public JsonResult GetAreaChild(string ParentAId)
        {
            using (ResponseResult <List <AreaViewModel> > result = new ResponseResult <List <AreaViewModel> >())
            {
                //获取用户信息
                if (this.UserInfo.IsSuperAdmin)
                {
                    var areaChilds = areaRepository.GetAreaChilds(ParentAId);
                    result.Entity    = areaChilds;
                    result.IsSuccess = true;
                    return(new JsonResultEx(result));
                }

                //获得用户角色信息
                var roleList = this.adminUserRepository.GetRoles(UserId);
                //是否拥有管理员角色
                if (roleList.Any(role => role.RoleID == (int)RoleType.Admin))
                {
                    var areaChilds = areaRepository.GetAreaChilds(ParentAId);
                    result.Entity    = areaChilds;
                    result.IsSuccess = true;
                    return(new JsonResultEx(result));
                }

                //是否拥有经销商角色
                else if (roleList.Any(role => role.RoleID == (int)RoleType.Dealer))
                {
                    //获取经销商可管理的区域
                    var areaChilds = areaRepository.GetManageArea(ParentAId, UserId);
                    if (areaChilds == null || areaChilds.Count == 0)
                    {
                        return(new JsonResultEx(result));
                    }
                    else
                    {
                        result.IsSuccess = true;
                        result.Entity    = Mapper.Map <List <AreaViewModel> >(areaChilds);
                        return(new JsonResultEx(result));
                    }
                }
                else
                {
                    throw new UnauthorizedAccessException();
                }
            }
        }
        public JsonResult AddDemonstateFarm(DemonstateFarmDetailViewModel input)
        {
            CheckPermission();
            using (var result = new ResponseResult <object>())
            {
                var isAdmin = false;
                if (!this.UserInfo.IsSuperAdmin)
                {
                    //获取用户角色信息
                    var roles = adminUserRepository.GetRoles(UserId);

                    if (roles.Any(m => m.RoleID == (int)RoleType.Admin))
                    {
                        isAdmin = true;
                    }

                    if (!isAdmin)
                    {
                        //按经销商处理
                        var areaList       = _areaService.GetManageArea("-1", UserId);
                        var provinceIdList = areaList.Where(m => m.ParentAID == "0").Select(m => m.AID).ToArray();
                        var cityIdList     = areaList.Where(m => provinceIdList.Contains(m.ParentAID)).Select(m => m.AID).ToArray();
                        var regionIdList   = areaList.Where(m => cityIdList.Contains(m.ParentAID)).Select(m => m.AID).ToArray();

                        //判断权限
                        if (!provinceIdList.Contains(input.ProvinceAid) ||
                            !cityIdList.Contains(input.CityAid) ||
                            !regionIdList.Contains(input.RegionAid)
                            )
                        {
                            throw new CustomException("您没有该地区的添加权限!");
                        }
                    }
                }

                //同地区的同名农场不可重复添加
                var existSameFarm = _farmService.Count(m => m.Name == input.Name &&
                                                       m.ProvinceAid == input.ProvinceAid &&
                                                       m.CityAid == input.CityAid &&
                                                       m.RegionAid == input.RegionAid) > 0;
                if (existSameFarm)
                {
                    throw new CustomException("已存在相同的农场!");
                }

                var farm = new T_DEMONSTRATION_FARM()
                {
                    ProvinceAid   = input.ProvinceAid,
                    CityAid       = input.CityAid,
                    RegionAid     = input.RegionAid,
                    Name          = input.Name,
                    IsOpen        = input.IsOpen,
                    OpenStartDate = input.OpenStartDate,
                    OpenEndDate   = input.OpenEndDate,
                    PlantArea     = input.PlantArea,
                    Variety       = input.Variety,
                    SowTime       = input.SowTime,
                    PlantPoint    = input.PlantPoint,
                    CreateTime    = DateTime.Now
                };

                _farmService.Insert(farm);
                result.Message = "添加示范农场成功!";
                return(new JsonResultEx(result));
            }
        }