ASP.NET MVC企业级程序设计(增删,int类型转时间取余)

目录

题目:

实现过程

控制器代码

DAL

BLL

Index

Jia


题目:

实现过程

控制器代码

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

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

        public ActionResult Index()
        {
            ViewBag.Show = BLL.PropertyInfoManager.Show();
            return View();
        }
        public ActionResult Jia()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Jia(string Title, string Duration, string Singer)
        {
            HotSong model = new HotSong();
            model.Title = Title;
            model.Duration =int.Parse(Duration);
       
            model.Singer = Singer;
            BLL.PropertyInfoManager.Add(model);

            return RedirectToAction("Index");
        }
        public ActionResult Delect(int id)
        {
            BLL.PropertyInfoManager.Delect(id);
            return RedirectToAction("Index"); 
            
            }
    }
}

DAL

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;
namespace MvcApplication1.DAL
{
    public class PropertyInfoServices
    {
        public static List<HotSong> Show() {
            CloudMusicDBEntities db = new CloudMusicDBEntities();
            return db.HotSongs.ToList();
        }
        public static HotSong FindModel(int id)
        {
            CloudMusicDBEntities db = new CloudMusicDBEntities();
            return db.HotSongs.SingleOrDefault(x => x.Id == id);
        }
        public static bool Delect(int id)
        {
            HotSong model = FindModel(id);
          CloudMusicDBEntities db = new CloudMusicDBEntities();
            db.Entry(model).State = System.Data.EntityState.Deleted;
            return db.SaveChanges() > 0;
        }
        public static bool Add(HotSong model)
        {
            CloudMusicDBEntities db = new CloudMusicDBEntities();
            db.Entry(model).State = System.Data.EntityState.Added;
           
            return db.SaveChanges() > 0;
        }
    }
}

BLL

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcApplication1.Models;

namespace MvcApplication1.BLL
{
    public class PropertyInfoManager
    {

        public static List<HotSong> Show()
            {
                return DAL.PropertyInfoServices.Show();
            }
           
            public static bool Delect(int id)
            {
                return DAL.PropertyInfoServices.Delect(id);
            }
            public static bool Add(HotSong model)
            {
                return DAL.PropertyInfoServices.Add(model);
            }
        
    }
}

Index

html 复制代码
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
       <a href="/Home/Jia">添加</a>
        <table border="1" style=" position:absolute;top:5%;right:70%">
            <tr>
                <th></th>
            <th>标题</th>
            <th>时长</th>
            <th>歌手</th>
            <th></th>
            </tr>
            @foreach (var item in @ViewBag.Show as List<MvcApplication1.Models.HotSong>)
            {
                <tr>
                    <td>@item.Id</td>
                     <td>@item.Title</td>
                    @{
                var a = item.Duration % 60;
                var b = item.Duration / 60;
                        }
                     <td>@b:@a </td>
                     <td>@item.Singer</td>
                     <td>@Html.ActionLink("删除", "Delect", new { id = @item.Id }, new {onclick="return confirm('确定删除吗?')" })</td>
                </tr>
            }
        </table>
    </div>
</body>
</html>

Jia

html 复制代码
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        <a href="/Home/Jia">添加</a>
        <table border="1" style=" position:absolute;top:5%;right:70%">
            <tr>
                <th></th>
                <th>标题</th>
                <th>时长</th>
                <th>歌手</th>
                <th></th>
            </tr>
            @foreach (var item in @ViewBag.Show as List<MvcApplication1.Models.HotSong>)
            {
                <tr>
                    <td>@item.Id</td>
                    <td>@item.Title</td>
                    @{
                        var a = item.Duration % 60;
                        var b = item.Duration / 60;
                    }
                    <td>@b:@a </td>
                    <td>@item.Singer</td>
                    <td>@Html.ActionLink("删除", "Delect", new { id = @item.Id }, new { onclick = "return confirm('确定删除吗?')" })</td>
                </tr>
            }
        </table>
    </div>
</body>
</html>
相关推荐
知其然亦知其所以然2 分钟前
深入Kafka:如何保证数据一致性与可靠性?
后端·面试·kafka
WHYBIGDATA27 分钟前
Scala中高级的函数编程
开发语言·后端·scala
吃青椒的小新32 分钟前
独一无二的设计模式——单例模式(Java实现)
java·后端·单例模式·设计模式
知识分享小能手32 分钟前
从新手到高手:Scala函数式编程完全指南,Scala 访问修饰符(6)
大数据·开发语言·后端·python·数据分析·scala·函数式编程
蝎子莱莱爱打怪1 小时前
maven卸载旧版本3.1.0 并安装新版本3.8.8
后端
肖哥弹架构2 小时前
使用MarshallingView实现自动化的XML响应生成
后端
AskHarries2 小时前
Spring Boot集成findbug快速入门Demo
java·spring boot·后端·findbug
笔触狂放2 小时前
【Django】网上蛋糕项目商城-首页
后端·python·django
未知百分百2 小时前
Django任意URL跳转漏洞(CVE-2018-14574)
后端·python·安全·web安全·网络安全·django·shell
小高学习java2 小时前
Java Stream API 常用操作技巧
java·后端·list