using Competition.Common.Util;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace CompetitionAPI.Controllers
{
///
/// 联系人信息
///
[Route("api/[controller]")]
[ApiController]
public class ContactInfoController : BaseHandlerController
{
public ContactInfoController(IHttpContextAccessor IHttpContextAccessor, IConfiguration iconfiguration)
{
Configuration = iconfiguration;
context = IHttpContextAccessor.HttpContext!;
CrossDomain();
}
Competition.Mysql.BLL.app_contact_info bll = new Competition.Mysql.BLL.app_contact_info();
Competition.Mysql.BLL.app_client_collect bll_client_collect = new Competition.Mysql.BLL.app_client_collect();
//[Authorize]
[HttpPost]
[Route("Add")]
public JsonResult Add()
{
try
{
JsonResult ret;
var data = GetValue("data");
if (string.IsNullOrEmpty(data))
{
ret = GetResult(false, "data不能为空");
return ret;
}
Competition.Mysql.Model.app_contact_info model = new Competition.Mysql.Model.app_contact_info();
try
{
model = JsonConvert.DeserializeObject(data)!;
}
catch (Exception ex)
{
ret = GetResult(false, "data转换错误:" + ex.Message);
return ret;
}
if (model != null)
{
var client = bll_client_collect.GetModel(model.client_id);
if (null == client)
{
ret = GetResult(false, "客户收资材料不能为空:client_id:" + model.client_id);
return ret;
}
if (string.IsNullOrWhiteSpace(model.contact_man))
{
return GetResult(false, "联系人不能为空");
}
if (string.IsNullOrWhiteSpace(model.contact_mobile))
{
return GetResult(false, "联系方式不能为空");
}
if (string.IsNullOrWhiteSpace(model.contact_type))
{
return GetResult(false, "联系类型不能为空");
}
model.id = Tool.GetId();
model.create_time = DateTime.Now;
if (bll.Add(model))
{
return GetResult(true, model, "");
}
else
{
return GetResult(false, "添加失败");
}
}
else
{
return GetResult(false, "请求参数不能为空");
}
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
return GetResult(false, "发生错误,请联系管理员");
}
}
//[Authorize]
[HttpPost]
[Route("Delete")]
public JsonResult Delete()
{
JsonResult ret;
var id = GetValue("id");
if (string.IsNullOrEmpty(id))
{
ret = GetResult(false, "id不能为空");
return ret;
}
var model = bll.GetModel(id);
if (null == model)
{
ret = GetResult(false, "联系信息不存在,id:" + id);
return ret;
}
if (bll.Delete(id))
{
return GetResult(true);
}
else
{
return GetResult(false, "删除失败");
}
}
//[Authorize]
///
/// 查询所有联系人信息
///
[Route("QueryByClient")]
public JsonResult QueryByClient()
{
JsonResult ret;
var client_id = GetValue("client_id");
if (string.IsNullOrEmpty(client_id))
{
ret = GetResult(false, "client_id不能为空");
return ret;
}
var list = bll.GetModelList("client_id='" + client_id + "'");
var result = GetResult(true, list);
return result;
}
//[Authorize]
///
/// 查询所有联系人信息
///
[Route("All")]
public JsonResult QueryALL()
{
var list = bll.GetModelList("");
var result = GetResult(true, list);
return result;
}
}
}