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

2024-06-20 14:44

本文主要是介绍ASP.NET MVC企业级程序设计(增删,int类型转时间取余),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

题目: 

实现过程 

控制器代码

DAL

 BLL

Index 

Jia


题目: 

 

实现过程 

控制器代码

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

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

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 

@{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

@{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>

这篇关于ASP.NET MVC企业级程序设计(增删,int类型转时间取余)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1078425

相关文章

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

C++ 函数 strftime 和时间格式示例详解

《C++函数strftime和时间格式示例详解》strftime是C/C++标准库中用于格式化日期和时间的函数,定义在ctime头文件中,它将tm结构体中的时间信息转换为指定格式的字符串,是处理... 目录C++ 函数 strftipythonme 详解一、函数原型二、功能描述三、格式字符串说明四、返回值五

从基础到进阶详解Pandas时间数据处理指南

《从基础到进阶详解Pandas时间数据处理指南》Pandas构建了完整的时间数据处理生态,核心由四个基础类构成,Timestamp,DatetimeIndex,Period和Timedelta,下面我... 目录1. 时间数据类型与基础操作1.1 核心时间对象体系1.2 时间数据生成技巧2. 时间索引与数据

利用Python实现时间序列动量策略

《利用Python实现时间序列动量策略》时间序列动量策略作为量化交易领域中最为持久且被深入研究的策略类型之一,其核心理念相对简明:对于显示上升趋势的资产建立多头头寸,对于呈现下降趋势的资产建立空头头寸... 目录引言传统策略面临的风险管理挑战波动率调整机制:实现风险标准化策略实施的技术细节波动率调整的战略价

MybatisX快速生成增删改查的方法示例

《MybatisX快速生成增删改查的方法示例》MybatisX是基于IDEA的MyBatis/MyBatis-Plus开发插件,本文主要介绍了MybatisX快速生成增删改查的方法示例,文中通过示例代... 目录1 安装2 基本功能2.1 XML跳转2.2 代码生成2.2.1 生成.xml中的sql语句头2

Python日期和时间完全指南与实战

《Python日期和时间完全指南与实战》在软件开发领域,‌日期时间处理‌是贯穿系统设计全生命周期的重要基础能力,本文将深入解析Python日期时间的‌七大核心模块‌,通过‌企业级代码案例‌揭示最佳实践... 目录一、背景与核心价值二、核心模块详解与实战2.1 datetime模块四剑客2.2 时区处理黄金法

macOS Sequoia 15.5 发布: 改进邮件和屏幕使用时间功能

《macOSSequoia15.5发布:改进邮件和屏幕使用时间功能》经过常规Beta测试后,新的macOSSequoia15.5现已公开发布,但重要的新功能将被保留到WWDC和... MACOS Sequoia 15.5 正式发布!本次更新为 Mac 用户带来了一系列功能强化、错误修复和安全性提升,进一步增

Pandas进行周期与时间戳转换的方法

《Pandas进行周期与时间戳转换的方法》本教程将深入讲解如何在pandas中使用to_period()和to_timestamp()方法,完成时间戳与周期之间的转换,并结合实际应用场景展示这些方法的... 目录to_period() 时间戳转周期基本操作应用示例to_timestamp() 周期转时间戳基

JavaScript时间戳与时间的转化常用方法

《JavaScript时间戳与时间的转化常用方法》在JavaScript中,时间戳(Timestamp)通常指Unix时间戳,即从1970年1月1日00:00:00UTC到某个时间点经过的毫秒数,下面... 目录1. 获取当前时间戳2. 时间戳 → 时间对象3. 时间戳php → 格式化字符串4. 时间字符

使用easy connect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题

《使用easyconnect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题》:本文主要介绍使用easyconnect之后,maven无法... 目录使用easGWowCy connect之后,maven无法使用,原来需要配置-DJava.net.pr