migrate to new git
This commit is contained in:
182
web/App_Code/api/FilesSetController.cs
Normal file
182
web/App_Code/api/FilesSetController.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using PagedList;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
// api/FilesSet
|
||||
//[ezAuthorize(Roles = "admin")]//群組:*
|
||||
[ezAuthorize]
|
||||
public class FilesSetController : ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
// GET api/<controller>
|
||||
public IEnumerable<Model.file> Get()
|
||||
{
|
||||
var list = _db.files.ToList();
|
||||
if (list == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return list;
|
||||
}
|
||||
|
||||
public IEnumerable<Model.file> Get(int page, int pageSize = 10,
|
||||
string sortBy="", bool sortDesc=false)
|
||||
{
|
||||
var list = _db.files.OrderBy(o=>o.num).ToPagedList(page, pageSize);
|
||||
if (list == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return list;
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
public Model.file Get(int id)
|
||||
{
|
||||
var item = _db.files.Where(q => q.num == id).FirstOrDefault();
|
||||
//if (item == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return item;
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
public void Post([FromBody] Model.file item)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT api/<controller>/5
|
||||
public void Put(int id, [FromBody] Model.file item)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.files.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//var prod2 = _db.actItem_files.AsEnumerable().Where(q => q.files_num == id).ToList(); //刪除品項的相關文件
|
||||
//if (prod2.Count > 0)
|
||||
//{
|
||||
// //查詢結果全部刪除
|
||||
// _db.actItem_files.RemoveRange(prod2);
|
||||
//}
|
||||
_db.actItem_files.RemoveRange(prod.actItem_files);
|
||||
|
||||
|
||||
_db.files.Remove(prod);
|
||||
_db.SaveChanges();//執行
|
||||
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
MyWeb.admin admin = new MyWeb.admin();//api裡不可以用MyWeb
|
||||
if (admin.isLoign())
|
||||
{
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Files, (int)Model.admin_log.Status.Delete, prod.subject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete]
|
||||
[Route("api/FilesSet/Delete/{nums}")]
|
||||
public void Delete(string nums)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
|
||||
var prod = _db.files.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
//刪除品項的相關文件
|
||||
var prod2 = _db.actItem_files.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.files_num))).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
_db.actItem_files.RemoveRange(prod2);
|
||||
}
|
||||
|
||||
_db.files.RemoveRange(prod);
|
||||
_db.SaveChanges();
|
||||
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
MyWeb.admin admin = new MyWeb.admin();//api裡不可以用MyWeb
|
||||
if (admin.isLoign())
|
||||
{
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Files, (int)Model.admin_log.Status.Delete, admin_log.LogViewBtn(prod.Select(x => x.subject).ToList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/FilesSet/count")]
|
||||
public int Count()
|
||||
{
|
||||
var count = _db.files.Count();
|
||||
return count;
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/FilesSet/GetList")]
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.files q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.files.AsEnumerable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject));
|
||||
|
||||
if (q.reg_time1.HasValue)
|
||||
qry = qry.Where(o => o.reg_time >= q.reg_time1.Value);
|
||||
if (q.reg_time2.HasValue)
|
||||
qry = qry.Where(o => o.reg_time < Convert.ToDateTime(q.reg_time2.Value).AddDays(1));
|
||||
|
||||
if (sortBy.Equals("subject"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.subject);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.subject);
|
||||
}
|
||||
else if (sortBy.Equals("start_date"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.reg_time);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.reg_time);
|
||||
}
|
||||
else if (sortBy.Equals("end_date"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.modify_time);
|
||||
else
|
||||
qry = qry.OrderBy(o => o.modify_time);
|
||||
}
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.subject,
|
||||
reg_time = x.reg_time,
|
||||
modify_time = x.modify_time,
|
||||
word = x.word,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
|
||||
};
|
||||
|
||||
|
||||
if (ret.list == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user