1 Star 0 Fork 0

SimonQ2016/APIForApp

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ConsigneeAddressController.cs 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
SimonQ2016 提交于 2016-10-24 13:24 +08:00 . e
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 ConsigneeAddressController : BaseApiController
{
/// <summary>
/// 获取收货地址列表,默认收货地址放在顶部,其他按照Id正序排列
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public IEnumerable<ConsigneeAddress> GetAddressByUserId(int id)
{
var list = from c in db.ConsigneeAddress where c.UserId == id && c.IsDelete!=1 orderby c.IsDefault descending,c.Id ascending select c;
return list;
}
/// <summary>
/// 根据id删除(逻辑删除)
/// </summary>
/// <returns></returns>
[HttpPost]
public bool Delete() {
bool result = false;
string addressId = HttpContext.Current.Request.Form["addressId"];
int id = Convert.ToInt32(addressId);
var address = db.ConsigneeAddress.FirstOrDefault((p) => p.Id == id);
if (address != null)
{
address.IsDelete = 1;
int r = db.SaveChanges();
if (r > 0)
{
result = true;
}
}
return result;
}
/// <summary>
/// 设置默认地址
/// </summary>
/// <returns></returns>
[HttpPost]
public bool DeFaultAddress() {
bool result = false;
int userId = Convert.ToInt32(HttpContext.Current.Request.Form["userId"]);
string addressId = HttpContext.Current.Request.Form["addressId"];
int id = Convert.ToInt32(addressId);
if (id > 0)
{
var list = from c in db.ConsigneeAddress where c.UserId== userId && c.IsDelete != 1 select c;
foreach (var item in list)
{
if (item.IsDefault == 1)
{
item.IsDefault = 0;
}
if (item.Id == id) {
item.IsDefault = 1;
}
}
int r = db.SaveChanges();
if (r > 0)
{
result = true;
}
}
return result;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/SimonQ2016/APIForApp.git
git@gitee.com:SimonQ2016/APIForApp.git
SimonQ2016
APIForApp
APIForApp
master

搜索帮助