zoukankan      html  css  js  c++  java
  • API

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using WebApplication_API_MoNiMonth01.Dals;
    using WebApplication_API_MoNiMonth01.Models;

    namespace WebApplication_API_MoNiMonth01.Controllers
    {
    public class SaleController : ApiController
    {
    //实例化上下文对象
    MyContext myContext = new MyContext();
    FileHelp fileHelp = new FileHelp();

    /// <summary>
    /// 获取商品 或者每个店铺的商品
    /// </summary>
    /// <param name="SId"></param>
    /// <returns></returns>
    [HttpGet]
    public List<GoodsInfo> GetGoodsInfos(string GId="",int SId=0)
    {
    var list = myContext.GoodsInfos.Include("StoresInfoSId").Where(s=>s.StoresInfoSId.State==0).ToList();
    if (!string.IsNullOrEmpty(GId))
    {
    list = list.Where(s => s.GId.Contains(GId)).ToList();
    }
    if (SId!=0)
    {
    list = list.Where(s => s.SId == SId).ToList();
    }
    return list;
    }
    /// <summary>
    /// 收藏宝贝
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    public int AddGoodsCollectInfo(GoodsCollectInfo model)
    {
    myContext.GoodsCollectInfos.Add(model);
    int i = myContext.SaveChanges();
    var list = myContext.GoodsInfos.Find(model.GId);
    list.CGNum = list.CGNum + 1;
    i += myContext.SaveChanges();
    return i;
    }


    /// <summary>
    /// 宝贝收藏显示
    /// </summary>
    /// <param name="UId"></param>
    /// <returns></returns>
    [HttpGet]
    public List<GoodsCollectInfo> GetGoodsCollectInfos(int UId = 0)
    {
    var list = myContext.GoodsCollectInfos.Include("GoodsInfoGId").Include("UsersInfoUId").Where(s=>s.CGState==0).ToList();
    if (UId != 0)
    {
    list = list.Where(s=>s.UId==UId).ToList();
    }
    return list;
    }
    /// <summary>
    /// 收藏店铺
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public int AddStroesCollectInfo(StroesCollectInfo model)
    {
    myContext.StroesCollectInfos.Add(model);
    int i = myContext.SaveChanges();
    var list = myContext.StoresInfos.Find(model.SId);
    list.CSNum = list.CSNum + 1;
    i += myContext.SaveChanges();
    return i;
    }
    /// <summary>
    /// 店铺收藏显示
    /// </summary>
    /// <param name="UId"></param>
    /// <returns></returns>
    [HttpGet]
    public List<StroesCollectInfo> GetStroesCollectInfos(int UId = 0)
    {
    var list = myContext.StroesCollectInfos.Include("StoresInfoSId").Include("UsersInfoUId").Where(s=>s.CState==0).ToList();
    if (UId != 0)
    {
    list = list.Where(s => s.UId == UId).ToList();
    }
    return list;
    }
    /// <summary>
    /// 判断商品收藏表是否存在此商品
    /// </summary>
    /// <param name="UId"></param>
    /// <param name="SId"></param>
    /// <returns></returns>
    [HttpGet]
    public int DecideGoodsCollect(int UId, string GId)
    {
    var list = myContext.GoodsCollectInfos.Include("GoodsInfoGId").Include("UsersInfoUId").Where(s => s.UId == UId && s.GId == GId).ToList();
    if (list != null && list.Count > 0)
    {
    return 0;
    }
    else
    {
    return 1;
    }
    }
    /// <summary>
    /// 判断店铺收藏表是否存在此店铺
    /// </summary>
    /// <param name="UId"></param>
    /// <param name="SId"></param>
    /// <returns></returns>
    [HttpGet]
    public int DecideStoreCollect(int UId,int SId)
    {
    var list = myContext.StroesCollectInfos.Include("StoresInfoSId").Include("UsersInfoUId").Where(s => s.UId == UId && s.SId == SId).ToList();
    if (list!=null&&list.Count>0)
    {
    return 0;
    }
    else
    {
    return 1;
    }
    }

    /// <summary>
    /// 获取用户的订单或某个订单的详情
    /// </summary>
    /// <param name="UId"></param>
    /// <param name="OId"></param>
    /// <returns></returns>
    [HttpGet]
    public List<OrdersInfo> GetOrdersInfos(int UId = 0, int OId = 0)
    {
    var list = myContext.OrdersInfos.Include("GoodsInfoGId").Include("UsersInfoUId").Where(s => s.OState != 3).ToList();
    if (UId != 0)
    {
    list = list.Where(s => s.UId == UId).ToList();
    }
    if (OId != 0)
    {
    list = list.Where(s => s.OId == OId).ToList();
    }
    return list;
    }
    /// <summary>
    /// 登录
    /// </summary>
    /// <param name="ACount"></param>
    /// <param name="Pwd"></param>
    /// <returns></returns>
    [HttpGet]
    public UsersInfo Login(string ACount = "", string Pwd = "")
    {
    var list = myContext.UsersInfos.Where(s => s.ACount == ACount && s.Pwd == Pwd).ToList();
    if (list != null || list.Count > 0)
    {
    return list.FirstOrDefault();
    }
    else
    {
    return null;
    }
    }
    ///上传文件 控制器端

    [HttpPost]
    public FileResult UpLoad()
    {
    return fileHelp.UpLoad();
    }
    /// <summary>
    /// 退单
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public int SaleReturn(int UId=0, int OId=0, string SaleCase="", string SImg="")
    {
    int Count = 0;
    SqlParameter[] sda = new SqlParameter[]
    {
    new SqlParameter{ParameterName="@UId",SqlDbType=SqlDbType.Int,SqlValue=UId},
    new SqlParameter{ParameterName="@OId",SqlDbType=SqlDbType.Int,SqlValue=OId},
    new SqlParameter{ParameterName="@SaleCase",SqlDbType=SqlDbType.NVarChar,SqlValue=SaleCase},
    new SqlParameter{ParameterName="@SImg",SqlDbType=SqlDbType.NVarChar,SqlValue=SImg},
    new SqlParameter{ParameterName="@Count",SqlDbType=SqlDbType.Int,Direction=ParameterDirection.Output}
    };
    var list = DBhelper.GetList<SaleInfo>("Proc_SaleReturn", sda);
    Count = Convert.ToInt32(sda[4].Value);
    return Count;
    }

    }
    }

  • 相关阅读:
    BZOJ4802 欧拉函数 数论
    BZOJ3561 DZY Loves Math VI 数论 快速幂 莫比乌斯反演
    BZOJ3560 DZY Loves Math V 数论 快速幂
    BZOJ2142 礼物 扩展lucas 快速幂 数论
    BZOJ1951 [Sdoi2010]古代猪文 中国剩余定理 快速幂 数论
    BZOJ1500 [NOI2005]维修数列 splay
    HDU1814 Peaceful Commission 2-sat
    BZOJ2209 [Jsoi2011]括号序列 splay
    BZOJ1503 [NOI2004]郁闷的出纳员 splay
    BZOJ1208 [HNOI2004]宠物收养所 splay
  • 原文地址:https://www.cnblogs.com/zhang0405/p/13275703.html
Copyright © 2011-2022 走看看