4 changed files with 125 additions and 0 deletions
@ -0,0 +1,41 @@ |
|||
using PetaPoco; |
|||
using System.Web.Mvc; |
|||
using System.Collections.Generic; |
|||
|
|||
using Pingchuan.BeijingSafeguard.BLL; |
|||
using Pingchuan.BeijingSafeguard.Model; |
|||
|
|||
namespace Pingchuan.BeijingSafeguard.App.Controllers |
|||
{ |
|||
public class PointController : BaseController |
|||
{ |
|||
[HttpPost] |
|||
public JsonResult Add(Point point) |
|||
{ |
|||
int id = PointBLL.Add(point); |
|||
return Json(id); |
|||
} |
|||
|
|||
[HttpPost] |
|||
public JsonResult Update(Point point) |
|||
{ |
|||
int count = PointBLL.Update(point); |
|||
return Json(count); |
|||
} |
|||
|
|||
[HttpPost] |
|||
public JsonResult Delete(int id) |
|||
{ |
|||
int count = PointBLL.Delete(id); |
|||
return Json(count); |
|||
} |
|||
|
|||
[HttpPost] |
|||
public JsonResult Query() |
|||
{ |
|||
User user = GetLoginUser(); |
|||
List<Point> points = PointBLL.Query(user.Id); |
|||
return Json(points); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
using Pingchuan.BeijingSafeguard.DAL; |
|||
using Pingchuan.BeijingSafeguard.Model; |
|||
|
|||
namespace Pingchuan.BeijingSafeguard.BLL |
|||
{ |
|||
public class PointBLL |
|||
{ |
|||
public static int Add(Point point) |
|||
{ |
|||
return PointDAL.Add(point); |
|||
} |
|||
|
|||
public static int Update(Point point) |
|||
{ |
|||
return PointDAL.Update(point); |
|||
} |
|||
|
|||
public static int Delete(int id) |
|||
{ |
|||
return PointDAL.Delete(id); |
|||
} |
|||
|
|||
public static List<Point> Query(int userId) |
|||
{ |
|||
return PointDAL.Query(userId); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Pingchuan.BeijingSafeguard.Model; |
|||
|
|||
namespace Pingchuan.BeijingSafeguard.DAL |
|||
{ |
|||
public class PointDAL : BaseDAL |
|||
{ |
|||
public static int Add(Point point) |
|||
{ |
|||
object id = db.Insert(point); |
|||
return int.Parse(id.ToString()); |
|||
} |
|||
|
|||
public static int Update(Point point) |
|||
{ |
|||
return db.Update(point); |
|||
} |
|||
|
|||
public static int Delete(int id) |
|||
{ |
|||
return db.Delete<Point>(id); |
|||
} |
|||
|
|||
public static List<Point> Query(int userId) |
|||
{ |
|||
string sql = $@"select * points where user_id = @0"; |
|||
return db.Fetch<Point>(sql, userId); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using PetaPoco; |
|||
|
|||
namespace Pingchuan.BeijingSafeguard.Model |
|||
{ |
|||
[TableName("points")] |
|||
[PrimaryKey("id", AutoIncrement = true)] |
|||
public class Point |
|||
{ |
|||
[Column("id")] |
|||
public int Id { get; set; } |
|||
|
|||
[Column("user_id")] |
|||
public int UserId { get; set; } |
|||
|
|||
[Column("title")] |
|||
public string Title { get; set; } |
|||
|
|||
[Column("icon")] |
|||
public string Icon { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue