示例#1
0
        public JsonResult GetProjects(int start, int limit, string name, DateTime startDate, DateTime endDate)
        {
            var data = new AjaxDataModel <List <ProjectModel> > {
                success = true,
                message = "无数据",
                total   = 0,
                data    = new List <ProjectModel>()
            };

            try {
                startDate = startDate.Date;
                endDate   = endDate.Date.AddSeconds(86399);

                var names    = Common.SplitCondition(name);
                var projects = names.Length > 0 ?
                               _projectService.GetPagedProjectsInNames(names, startDate, endDate, start / limit, limit) :
                               _projectService.GetPagedProjectsInSpan(startDate, endDate, start / limit, limit);

                if (projects.TotalCount > 0)
                {
                    data.message = "200 Ok";
                    data.total   = projects.TotalCount;
                    for (var i = 0; i < projects.Count; i++)
                    {
                        data.data.Add(new ProjectModel {
                            index       = start + i + 1,
                            id          = projects[i].Id,
                            name        = projects[i].Name,
                            start       = CommonHelper.DateConverter(projects[i].StartTime),
                            end         = CommonHelper.DateConverter(projects[i].EndTime),
                            responsible = projects[i].Responsible,
                            contact     = projects[i].ContactPhone,
                            company     = projects[i].Company,
                            creator     = projects[i].Creator,
                            createdtime = CommonHelper.DateTimeConverter(projects[i].CreatedTime),
                            comment     = projects[i].Comment,
                            enabled     = projects[i].Enabled
                        });
                    }
                }
            } catch (Exception exc) {
                _webLogger.Error(EnmEventType.Other, exc.Message, _workContext.User().Id, exc);
                data.success = false; data.message = exc.Message;
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }