public JsonResult GetReservations(int start, int limit, DateTime startDate, DateTime endDate, int type, string keyWord) { var data = new AjaxDataModel <List <ReservationModel> > { success = true, message = "无数据", total = 0, data = new List <ReservationModel>() }; try { startDate = startDate.Date; endDate = endDate.Date.AddSeconds(86399); var reservations = _reservationService.GetReservationsInSpan(startDate, endDate); var projects = _projectService.GetProjects(); var result = (from res in reservations join pro in projects on res.ProjectId equals pro.Id select new { Reservation = res, Project = pro }).ToList(); if (!string.IsNullOrWhiteSpace(keyWord)) { var keyWords = Common.SplitCondition(keyWord.Trim()); if (type == (int)EnmSSH.Area) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Area); var areas = _workContext.Areas().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join area in areas on node.NodeId equals area.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else if (type == (int)EnmSSH.Device) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Device); var devices = _workContext.Devices().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join device in devices on node.NodeId equals device.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else if (type == (int)EnmSSH.Room) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Room); var rooms = _workContext.Rooms().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join room in rooms on node.NodeId equals room.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else if (type == (int)EnmSSH.Station) { var nodes = _nodesInReservationService.GetNodesInReservationsInType(EnmSSH.Station); var stations = _workContext.Stations().FindAll(a => CommonHelper.ConditionContain(a.Current.Name, keyWords)); var matchs = from node in nodes join station in stations on node.NodeId equals station.Current.Id select node; var ids = (from node in matchs group node by node.ReservationId into g select g.Key).ToArray(); result = result.FindAll(a => ids.Contains(a.Reservation.Id)); } else { result = result.FindAll(a => CommonHelper.ConditionContain(a.Project.Name, keyWords)); } } if (result.Count > 0) { data.message = "200 Ok"; data.total = result.Count; var end = start + limit; if (end > result.Count) { end = result.Count; } var users = _userService.GetPagedUsers().ToDictionary(k => k.Id, v => v.Uid); for (int i = start; i < end; i++) { data.data.Add(new ReservationModel { index = i + 1, id = result[i].Reservation.Id, name = result[i].Reservation.Name, expStartDate = CommonHelper.DateTimeConverter(result[i].Reservation.ExpStartTime), startDate = CommonHelper.DateTimeConverter(result[i].Reservation.StartTime), endDate = CommonHelper.DateTimeConverter(result[i].Reservation.EndTime), projectId = result[i].Project.Id, projectName = result[i].Project.Name, creator = result[i].Reservation.Creator, user = users[result[i].Reservation.UserId], createdTime = CommonHelper.DateTimeConverter(result[i].Reservation.CreatedTime), comment = result[i].Reservation.Comment, enabled = result[i].Reservation.Enabled, statusId = ((int)result[i].Reservation.Status), status = Common.GetResStatusDisplay(result[i].Reservation.Status) }); } } } 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)); }
public JsonResult GetWpfObj(string node) { var data = new AjaxDataModel <GviewModel> { success = false, message = "No data", total = 0, data = null }; try { if (string.IsNullOrWhiteSpace(node)) { throw new ArgumentNullException("node"); } var nodeKey = Common.ParseNode(node); if (nodeKey.Key == EnmSSH.Area) { var current = _workContext.Areas().Find(a => a.Current.Id.Equals(nodeKey.Value)); if (current != null) { data.success = true; data.message = "200 Ok"; data.total = 1; data.data = new GviewModel(); data.data.currentId = current.Current.Id; data.data.currentType = (int)EnmAPISCObj.Area; data.data.currentName = current.Current.Name; if (current.HasParents) { var parent = current.Parents.Last(); data.data.parentId = parent.Id; data.data.parentType = (int)EnmAPISCObj.Area; data.data.parentName = parent.Name; } } } else if (nodeKey.Key == EnmSSH.Station) { var current = _workContext.Stations().Find(s => s.Current.Id.Equals(nodeKey.Value)); if (current != null) { data.success = true; data.message = "200 Ok"; data.total = 1; data.data = new GviewModel(); data.data.currentId = current.Current.Id; data.data.currentType = (int)EnmAPISCObj.Station; data.data.currentName = current.Current.Name; data.data.parentId = current.Current.AreaId; data.data.parentType = (int)EnmAPISCObj.Area; var parent = _workContext.Areas().Find(a => a.Current.Id.Equals(current.Current.AreaId)); if (parent != null) { data.data.parentName = parent.Current.Name; } } } else if (nodeKey.Key == EnmSSH.Room) { var current = _workContext.Rooms().Find(r => r.Current.Id.Equals(nodeKey.Value)); if (current != null) { data.success = true; data.message = "200 Ok"; data.total = 1; data.data = new GviewModel(); data.data.currentId = current.Current.Id; data.data.currentType = (int)EnmAPISCObj.Room; data.data.currentName = current.Current.Name; data.data.parentId = current.Current.StationId; data.data.parentType = (int)EnmAPISCObj.Station; data.data.parentName = current.Current.StationName; } } else if (nodeKey.Key == EnmSSH.Device) { var current = _workContext.Devices().Find(r => r.Current.Id.Equals(nodeKey.Value)); if (current != null) { data.success = true; data.message = "200 Ok"; data.total = 1; data.data = new GviewModel(); data.data.currentId = current.Current.Id; data.data.currentType = (int)EnmAPISCObj.Device; data.data.currentName = current.Current.Name; data.data.parentId = current.Current.RoomId; data.data.parentType = (int)EnmAPISCObj.Room; data.data.parentName = current.Current.RoomName; } } } catch (Exception exc) { data.success = false; data.message = exc.Message; } return(Json(data, JsonRequestBehavior.AllowGet)); }