1 Star 0 Fork 0

SimonQ2016/APIForApp

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AreaController.cs 2.61 KB
一键复制 编辑 原始数据 按行查看 历史
coder2100 提交于 2016-11-02 15:42 +08:00 . t
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;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/SimonQ2016/APIForApp.git
git@gitee.com:SimonQ2016/APIForApp.git
SimonQ2016
APIForApp
APIForApp
master

搜索帮助