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>
相关推荐
Q_192849990621 分钟前
基于Spring Boot的九州美食城商户一体化系统
java·spring boot·后端
ZSYP-S1 小时前
Day 15:Spring 框架基础
java·开发语言·数据结构·后端·spring
Yuan_o_1 小时前
Linux 基本使用和程序部署
java·linux·运维·服务器·数据库·后端
程序员一诺2 小时前
【Python使用】嘿马python高级进阶全体系教程第10篇:静态Web服务器-返回固定页面数据,1. 开发自己的静态Web服务器【附代码文档】
后端·python
DT辰白3 小时前
如何解决基于 Redis 的网关鉴权导致的 RESTful API 拦截问题?
后端·微服务·架构
thatway19893 小时前
AI-SoC入门:15NPU介绍
后端
陶庵看雪3 小时前
Spring Boot注解总结大全【案例详解,一眼秒懂】
java·spring boot·后端
Q_19284999063 小时前
基于Spring Boot的图书管理系统
java·spring boot·后端
ss2734 小时前
基于Springboot + vue实现的汽车资讯网站
vue.js·spring boot·后端
一只IT攻城狮4 小时前
华为云语音交互SIS的使用案例(文字转语音-详细教程)
java·后端·华为云·音频·语音识别