Example #1
0
 public async Task <MaintenanceListView> ListPage(MaintenanceListParm parm)
 {
     return(await WithConnection(async c =>
     {
         MaintenanceListView ret = new MaintenanceListView();
         string sql = "SELECT ml.*,ot.name as team_name,d.name,u2.user_name,u1.user_name as cname " +
                      " FROM maintenance_list ml " +
                      " left join org_tree ot on ot.id=ml.team " +
                      " left join dictionary_tree d on d.id=ml.status " +
                      " left join user u1 on u1.id=ml.created_by " +
                      " left join user u2 on u2.id=ml.updated_by " +
                      " where 1=1 ";
         string sqlwhere = "";
         if (!string.IsNullOrWhiteSpace(parm.Title))
         {
             sqlwhere += " and ml.title like '%" + parm.Title + "%' ";
         }
         if (parm.Status != null)
         {
             sqlwhere += " and ml.status=" + parm.Status;
         }
         sql = sql + sqlwhere + " order by " + parm.sort + " " + parm.order
               + " limit " + (parm.page - 1) * parm.rows + "," + parm.rows;
         var tmp = await c.QueryAsync <MaintenanceList>(sql);
         if (tmp.Count() > 0)
         {
             sql = "select count(*) FROM maintenance_list ml " + sqlwhere;
             ret.total = await c.QueryFirstOrDefaultAsync <int>(sql);
             ret.rows = tmp.ToList();
         }
         else
         {
             ret.rows = new List <MaintenanceList>();
             ret.total = 0;
         }
         return ret;
     }));
 }
Example #2
0
        public async Task <ApiResult> ListPage(MaintenanceListParm parm)
        {
            ApiResult ret = new ApiResult();

            try
            {
                MaintenanceListView mlv = await _repo.ListPage(parm);

                List <QueryItem> locations = await _importRepo.ListAllLocations();

                foreach (var item in mlv.rows)
                {
                    item.LocationName = locations.Where(a => a.LocationBy == item.Locationby && a.ID == item.Location).FirstOrDefault().Name;
                }
                ret.data = mlv;
            }
            catch (Exception ex)
            {
                ret.code = Code.Failure;
                ret.msg  = ex.Message;
            }
            return(ret);
        }