Exemplo n.º 1
0
        public ApiResult GetAll(ClassTypeEnums?ClassType = 0, TableTypeEnums?TableType = 0, DateTime?BeginDate = null, DateTime?EndDate = null, int pageindex = 1, int pagesize = 10)
        {
            ApiResult result  = new ApiResult();
            string    message = string.Empty;

            try
            {
                using (FLDbContext db = new FLDbContext())
                {
                    BaseUtils bu = new BaseUtils();
                    BeginDate = bu.InitDate(BeginDate, true);
                    EndDate   = bu.InitDate(EndDate, false);
                    int total = db.BaseDateFlow.Where(t => t.BeginDate > DbFunctions.CreateDateTime(t.BeginDate.Year, t.BeginDate.Month, t.BeginDate.Day, BeginDate.Value.Hour, BeginDate.Value.Minute, BeginDate.Value.Second) &&
                                                      t.EndDate < DbFunctions.CreateDateTime(t.EndDate.Year, t.EndDate.Month, t.EndDate.Day, EndDate.Value.Hour, EndDate.Value.Minute, EndDate.Value.Second) &&
                                                      (ClassType == 0 || t.ClassType == ClassType) &&
                                                      (TableType == 0 || t.TableType == TableType)).Count();
                    List <BaseDateFlow> bdfList = db.BaseDateFlow.Where(t => t.BeginDate > DbFunctions.CreateDateTime(t.BeginDate.Year, t.BeginDate.Month, t.BeginDate.Day, BeginDate.Value.Hour, BeginDate.Value.Minute, BeginDate.Value.Second) &&
                                                                        t.EndDate < DbFunctions.CreateDateTime(t.EndDate.Year, t.EndDate.Month, t.EndDate.Day, EndDate.Value.Hour, EndDate.Value.Minute, EndDate.Value.Second) &&
                                                                        (ClassType == 0 || t.ClassType == ClassType) &&
                                                                        (TableType == 0 || t.TableType == TableType)).OrderBy(t => t.TableType).ThenBy(t => t.FlowID).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
                    List <object> returnlist = new List <object>();
                    foreach (BaseDateFlow bdf in bdfList)
                    {
                        returnlist.Add(new
                        {
                            bdf.ID,
                            bdf.Name,
                            TableType  = Enum.GetName(typeof(TableTypeEnums), bdf.TableType),
                            ClassType  = Enum.GetName(typeof(ClassTypeEnums), bdf.ClassType),
                            BeginDate  = bdf.BeginDate.ToString("HH:mm"),
                            EndDate    = bdf.EndDate.ToString("HH:mm"),
                            RemindDate = bdf.RemindDate.ToString("HH:mm"),
                        });
                    }

                    result = ApiResult.NewSuccessJson(new
                    {
                        Total = total,
                        List  = returnlist
                    });
                }
            }
            catch
            {
                result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员");
            }
            if (!string.IsNullOrEmpty(message))
            {
                result = ApiResult.NewErrorJson(message);
            }
            return(result);
        }