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

相关文章

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

Java controller接口出入参时间序列化转换操作方法(两种)

《Javacontroller接口出入参时间序列化转换操作方法(两种)》:本文主要介绍Javacontroller接口出入参时间序列化转换操作方法,本文给大家列举两种简单方法,感兴趣的朋友一起看... 目录方式一、使用注解方式二、统一配置场景:在controller编写的接口,在前后端交互过程中一般都会涉及

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Java中字符串转时间与时间转字符串的操作详解

《Java中字符串转时间与时间转字符串的操作详解》Java的java.time包提供了强大的日期和时间处理功能,通过DateTimeFormatter可以轻松地在日期时间对象和字符串之间进行转换,下面... 目录一、字符串转时间(一)使用预定义格式(二)自定义格式二、时间转字符串(一)使用预定义格式(二)自

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient

MySQL 中查询 VARCHAR 类型 JSON 数据的问题记录

《MySQL中查询VARCHAR类型JSON数据的问题记录》在数据库设计中,有时我们会将JSON数据存储在VARCHAR或TEXT类型字段中,本文将详细介绍如何在MySQL中有效查询存储为V... 目录一、问题背景二、mysql jsON 函数2.1 常用 JSON 函数三、查询示例3.1 基本查询3.2

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim