ASP.NET MVC企业级程序设计(查,删,展示详情,日期转换,¥字符串拼接)

题目: 

 

 

 

实现过程 

控制器代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index(string name)
         {
             if (name==null)
             {
                 ViewBag.list = BLL.PlayerManager.Show();
                 return View();
             }
             else
             {
                 ViewBag.list = BLL.PlayerManager.Find(name);
                 return View();
             }
           
        }
        public ActionResult Delect(int id) {
            BLL.PlayerManager.Delect(id);
            return RedirectToAction("Index");
        
        }
        public ActionResult Deile(int id)
        {
         var model=  DAL.PlayerServices.FindModel(id);
         ViewBag.goodname = model.goodname;
        ViewBag.price = model.price;
        ViewBag.launchtime = model.launchtime;
        ViewBag.description = model.description;
         return View();

        }
    }
}

DAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.DAL
{
    public class PlayerServices
    {
        public static List<good> Show() {

            ProductDBEntities db = new ProductDBEntities();
            return db.goods.ToList();
        
        
        }
        public static List<good> Find(string name)
        {

            ProductDBEntities db = new ProductDBEntities();
            return db.goods.Where(x => x.goodname.Contains(name)).ToList();


        }
        public static good FindModel(int id)
        {
            ProductDBEntities db = new ProductDBEntities();
            return db.goods.SingleOrDefault(x => x.goodid == id);
        }
        public static bool Delect(int id)
        {

            ProductDBEntities db = new ProductDBEntities();
            db.Entry(FindModel(id)).State = System.Data.EntityState.Deleted;

            return db.SaveChanges() > 0;
        }
        
    }
}

 BLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.BLL
{
    public class PlayerManager
    {
        public static List<good> Show()
        {

            return DAL.PlayerServices.Show();


        }
        public static List<good> Find(string name)
        {

            return DAL.PlayerServices.Find(name);


        }
      
        public static bool Delect(int id)
        {

            return DAL.PlayerServices.Delect(id);
        }
    }
}

Index 

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <form  action="/Home/Index">
            <label>关键词</label><input type="text" name="name"/><input type="submit"  value="查询">

        </form>
        <table border="1">
            <tr>
                <th>商品名称</th>
                  <th>价格</th>
                  <th>上架时间</th>
                  <th>操作</th>
                 
            </tr>
            @foreach (var item in @ViewBag.list as List<MvcApplication1.Models.good>)
            {
                <tr>
                   
                     <td>@item.goodname</td>
                     <td>@item.price</td>
                     <td>@item.launchtime.ToString("yyyy年MM月dd日")</td>
                    
                     <td>@Html.ActionLink("删除", "Delect", new { id = @item.goodid }, new { onclick="return confirm('确定删除吗?')"})
                         @Html.ActionLink("详情", "Deile", new { id = @item.goodid })

                     </td>
                </tr>
            }

        </table>
    </div>
</body>
</html>

Deile

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Deile</title>
</head>
<body>
    <div>
        <label>商品名称:</label>@ViewBag.goodname<br />
         <label>商品价格:</label>@ViewBag.price<br />
         <label>上架时间:</label>@ViewBag.launchtime<br />
         <label>商品详情:</label>@ViewBag.description<br />
        <a href="/Home/Index">返回首页</a>
    </div>
</body>
</html>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

W少年没有乌托邦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值