134 lines
3.7 KiB
C#
134 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using New_College.Common.HttpContextUser;
|
|
using New_College.IRepository.UnitOfWork;
|
|
using New_College.IServices;
|
|
using New_College.Model;
|
|
using New_College.Model.Models;
|
|
using New_College.Model.ViewModels;
|
|
|
|
namespace New_College.Api.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class SysRegionController : ControllerBase
|
|
{
|
|
private readonly IUser _user;
|
|
IMapper _mapper;
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
private readonly ISysRegionServices _regionRepository;
|
|
|
|
/// <summary>
|
|
/// 省市区操作类
|
|
/// </summary>
|
|
public SysRegionController(ISysRegionServices sysRegionRepository, IUnitOfWork unitOf, IMapper mapper)
|
|
{
|
|
this._regionRepository = sysRegionRepository;
|
|
this._unitOfWork = unitOf;
|
|
this._mapper = mapper;
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 根据ID获取
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<MessageModel<SysRegion>> GetSingle(int id)
|
|
{
|
|
try
|
|
{
|
|
var regions = (await this._regionRepository.QueryById(id));
|
|
|
|
return new MessageModel<SysRegion>()
|
|
{
|
|
msg = "success",
|
|
success = true,
|
|
//url = "",
|
|
response = regions
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
return new MessageModel<SysRegion>()
|
|
{
|
|
success = false,
|
|
msg = "Error",
|
|
status = 500
|
|
};
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 根据level和parentId获取省市区列表信息
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<MessageModel<List<SysRegionView>>> GetListByParentId(string Id)
|
|
{
|
|
try
|
|
{
|
|
var regionlist = (await _regionRepository.GetListByParentId(Id));
|
|
return new MessageModel<List<SysRegionView>>()
|
|
{
|
|
msg = "success",
|
|
success = true,
|
|
response = _mapper.Map<List<SysRegionView>>(regionlist.ToList())
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new MessageModel<List<SysRegionView>>()
|
|
{
|
|
msg = "error",
|
|
success = false
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取省市区
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<MessageModel<List<SysRegionResult>>> GetRegionList([FromQuery] SysRegionQuery query)
|
|
{
|
|
try
|
|
{
|
|
var regionlist = (await _regionRepository.GetRegionList(query));
|
|
return new MessageModel<List<SysRegionResult>>()
|
|
{
|
|
msg = "success",
|
|
success = true,
|
|
response = _mapper.Map<List<SysRegionResult>>(regionlist.ToList())
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new MessageModel<List<SysRegionResult>>()
|
|
{
|
|
msg = "error",
|
|
success = false
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|