91 lines
3.0 KiB
C#
91 lines
3.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Csvr;
|
|
using WX.CRM.IBLL.Res;
|
|
using WX.CRM.Model.Entity;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.Csvr
|
|
{
|
|
public class RelationCustomerController : BaseController
|
|
{
|
|
//
|
|
// GET: /RelationCustomer/
|
|
private ICSVR_RELATIONCUSTOMER _relation;
|
|
private IRES_CUSTOMER_Q _customer;
|
|
ValidationErrors errors = new ValidationErrors();
|
|
public RelationCustomerController(ICSVR_RELATIONCUSTOMER relation, IRES_CUSTOMER_Q customer)
|
|
{
|
|
this._relation = relation;
|
|
this._customer = customer;
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Add(string resid)
|
|
{
|
|
CSVR_RELATIONCUSTOMER relation = new CSVR_RELATIONCUSTOMER();
|
|
relation.map_RESID = resid;
|
|
return View(relation);
|
|
}
|
|
[HttpPost]
|
|
public ActionResult Add(CSVR_RELATIONCUSTOMER relation)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
if (relation.map_RESID.Trim() == relation.map_RELATIONRESID.Trim())
|
|
{
|
|
return JsonHandler.ManageMessage("不能关联自己", false);
|
|
}
|
|
else
|
|
{
|
|
var customer = _customer.getResCustomerByResId(relation.map_RELATIONRESID.Trim());
|
|
if (customer == null)
|
|
{
|
|
return JsonHandler.ManageMessage("关联客户编号不存在", false);
|
|
}
|
|
else
|
|
{
|
|
relation.map_CREATEUSER = UserId;
|
|
relation.map_CTIME = DateTime.Now;
|
|
bool result = this._relation.Create(ref errors, relation);
|
|
return JsonHandler.InsertMessage(errors, result);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string messages = string.Join("; ", ModelState.Values
|
|
.SelectMany(x => x.Errors)
|
|
.Select(x => x.ErrorMessage));
|
|
return JsonHandler.ManageMessage(messages, false);
|
|
}
|
|
}
|
|
[HttpPost]
|
|
public ActionResult checkResid(string resid)
|
|
{
|
|
try
|
|
{
|
|
var customer = _customer.getResCustomerByResId(resid.Trim());
|
|
if (customer == null)
|
|
{
|
|
return JsonHandler.ManageMessage("关联客户编号不存在", false);
|
|
}
|
|
else
|
|
{
|
|
return JsonHandler.ManageMessage("", true, customer.RESID);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
LogHelper.Error("RelationCustomerController_checkResid:" + ex.StackTrace + ";" + ex.Message);
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|