using Dapper; using dccdc.Models; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace dccdc.DAL { public class InfectionOpenCrowdDal { public List GetAllDataList() { string sql = "Select * From infection_open_crowd Order By create_time"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).ToList(); } } public object saveData(InfectionOpenCrowdModel model) { string sql = string.Empty; if (model.id == 0) { sql = @"Insert Into infection_open_crowd(sort,name,isQuestion,isOpen,create_by,create_time) Values (@sort,@name,@isQuestion,@isOpen,@create_by,@create_time)"; } else { sql = @"Update infection_open_crowd Set sort=@sort,name=@name,isQuestion=@isQuestion,isOpen=@isOpen Where id=@id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int c = conn.Execute(sql, model); if (c > 0) { return new { State = 1, Message = "保存成功!" }; } else { return new { State = 0, Message = "操作失败,请联系管理员!" }; } } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public object deleteData(string id) { string sql = string.Format("Delete From infection_open_crowd Where id = {0}", id); using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int c = conn.Execute(sql); if (c > 0) { return new { State = 1, Message = "删除成功!" }; } else { return new { State = 0, Message = "操作失败,请联系管理员!" }; } } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } public List GetOpenDataList() { string sql = "Select * From infection_open_crowd where isOpen=1 Order By sort"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).ToList(); } } public List GetAllIDNameIsQuestion() { string sql = "Select id,name,isQuestion From Infection_open_crowd Where isOpen = 1"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).ToList(); } } public InfectionOpenCrowdModel findById(int crowd_id) { string sql = "Select * From Infection_open_crowd Where id = "+crowd_id; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.QueryFirst(sql); } } } }