代码拉取完成,页面将自动刷新
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
public class AreaController : BaseApiController
{
public IEnumerable<Area> GetAreaByParentId(int id)
{
var list = from a in db.Area where a.ParentId == id select a;
//
return list;
}
[HttpPost]
public bool EditAddress()
{
bool result = false;
string name = HttpContext.Current.Request.Form["name"];
string tel = HttpContext.Current.Request.Form["tel"];
string area = HttpContext.Current.Request.Form["area"];
string address = HttpContext.Current.Request.Form["address"];
int userId = Convert.ToInt32(HttpContext.Current.Request.Form["userId"]);
int isAdd = Convert.ToInt32(HttpContext.Current.Request.Form["isAdd"]);
int addressId = Convert.ToInt32(HttpContext.Current.Request.Form["addressId"]);
if (isAdd == 1)
{
//新建
result = Insert(name, tel, area, address, userId);
}
else
{
//更新
result=Update(name, tel, area, address, userId, addressId);
}
return result;
}
private bool Insert(string name, string tel, string area, string address, int userId)
{
bool result = false;
ConsigneeAddress ca = new ConsigneeAddress() { UserId = userId, ConsigneeName = name, ConsigneeTel = tel, ConsigneeArea = area, AddressDetail = address };
db.ConsigneeAddress.Add(ca);
int n = db.SaveChanges();
if (n > 0)
{
result = true;
}
return result;
}
private bool Update(string name, string tel, string area, string address, int userId,int addressId)
{
try
{
var ca = db.ConsigneeAddress.FirstOrDefault((p) => p.Id == addressId);
if (ca != null)
{
ca.ConsigneeName = name;
ca.ConsigneeTel = tel;
ca.ConsigneeArea = area;
ca.AddressDetail = address;
db.SaveChanges();
return true;
}
else
return false;
}
catch (Exception e)
{
return false;
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。