You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/BookingWeb/Controllers/TemplateController.cs

60 lines
1.8 KiB
C#

3 years ago
using BookingWeb.DB;
using BookingWeb.DB.Model;
using BookingWeb.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace BookingWeb.Controllers
{
public class TemplateController : BaseController
{
private BookingDB bookingDB = new BookingDB();
#region 模板
[HttpGet]
public ActionResult GetTemplates(string cate)
{
var list = bookingDB.Templates.Where(t => t.UID == CurrentUser.GID && t.CATE == cate);
return Json(list.AsListViewModelList(), JsonRequestBehavior.AllowGet);
}
public ActionResult SuggestTemplate(string cate, string keyword)
{
RespSuggest resp = new RespSuggest();
var list = bookingDB.Templates.Where(t => t.UID == CurrentUser.GID && t.CATE == cate);
if (!string.IsNullOrEmpty(keyword))
{
list = list.Where(t => t.NAME.IndexOf(keyword) > -1);
}
resp.value = list.Select(t => new { t.NAME, t.CONTENT });
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
public ActionResult SaveTemplate(TemplateSaveViewModel viewModel)
{
var temp = viewModel.AsModel();
temp.GID = Guid.NewGuid().ToString();
temp.UID = CurrentUser.GID;
temp.CREATE_TIME = DateTime.Now;
bookingDB.Templates.Add(temp);
bookingDB.SaveChanges();
RespCommon resp = new RespCommon();
resp.Success = true;
resp.Message = Resources.LangAll.MsgSaveSuccess;
return Json(resp, JsonRequestBehavior.AllowGet);
}
#endregion
}
}