Esempio n. 1
0
        public ActionResult getAllRoom(string sortOrder, string selectedBlock = "", string selectedType = "", string selectedRoomNum = "")
        {
            var roomsStatusChangedCount = 0;
            List <Helper.MySQlRoom> res = MysqlFetchingRoomData.getDataFromMySql();

            foreach (var item in res)
            {
                var room = _roomService.GetAll().Where(x => x.RoomNum == item.RoomNum).FirstOrDefault();
                if (room != null)
                {
                    room.IsNeedfix   = item.MantStatus == "M" ? true : false;
                    room.isneedclean = item.CleanStatus == "D" ? true : false;
                    if (room.IsNeedfix && !room.Isrequistedfix)
                    {
                        roomsStatusChangedCount++;
                    }
                    if (room.isneedclean && !room.Isrequisted)
                    {
                        roomsStatusChangedCount++;
                    }
                    _roomService.Edit(room);
                }
            }



            List <RoomDto> list1 = _roomService.GetAll();
            List <RoomDto> list2 = new List <RoomDto>();

            foreach (var item in list1)
            {
                item.TypeName  = _roomTypeService.getbyidGetById(item.RoomType_id).Name.ToString();
                item.blockName = _hotelBlockService.GetById(item.HotelBlock_id).BlockName.ToString();
                list2.Add(item);
            }

            var RF = new RoomFilter();

            RF.HotelBlocks = _hotelBlockService.GetAll().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text  = x.BlockName
            });
            RF.Types = _roomTypeService.GetRoomTypes().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var data = list2;

            roomsStatusChangedCount = data.Where(x => (x.isneedclean && !x.Isrequisted) || x.IsNeedfix && !x.Isrequistedfix).Count();
            System.Web.HttpContext.Current.Session["roomsStatusChangedCount"] = roomsStatusChangedCount;
            SignalHelper.SendRoomsStatusChangedCount(roomsStatusChangedCount);
            var selectedTypeValue = 0;
            var isInt             = int.TryParse(selectedBlock, out selectedTypeValue);

            if (!string.IsNullOrEmpty(selectedBlock) && isInt)
            {
                data = data.Where(f => f.HotelBlock_id == (int)int.Parse(selectedBlock)).ToList();
            }
            if (!string.IsNullOrEmpty(selectedRoomNum))
            {
                data = data.Where(f => f.RoomNum == selectedRoomNum).ToList();
            }
            selectedTypeValue = 0;
            isInt             = int.TryParse(selectedType, out selectedTypeValue);
            if (!string.IsNullOrEmpty(selectedType) && isInt)
            {
                data = data.Where(f => f.RoomType_id == (int)int.Parse(selectedType)).ToList();
            }
            ViewBag.RoomNumberSortParm      = !String.IsNullOrEmpty(sortOrder) ? "number_desc" : "number";
            ViewBag.RoomDirSortParm         = !String.IsNullOrEmpty(sortOrder) ? "dir_desc" : "dir";
            ViewBag.RoomBlockSortParm       = !String.IsNullOrEmpty(sortOrder) ? "block_desc" : "block";
            ViewBag.RoomTypeSortParm        = !String.IsNullOrEmpty(sortOrder) ? "type_desc" : "type";
            ViewBag.RoomIsBusySortParm      = !String.IsNullOrEmpty(sortOrder) ? "busy_desc" : "busy";
            ViewBag.RoomIsNeedFixSortParm   = !String.IsNullOrEmpty(sortOrder) ? "fix_desc" : "fix";
            ViewBag.RoomIsNeedCleanSortParm = !String.IsNullOrEmpty(sortOrder) ? "clean_desc" : "clean";
            ViewBag.RoomIsInServiceSortParm = !String.IsNullOrEmpty(sortOrder) ? "service_desc" : "service";
            switch (sortOrder)
            {
            case "number_desc":
                data = data.OrderByDescending(s => s.RoomNum).ToList();
                break;

            case "dir_desc":
                data = data.OrderByDescending(s => s.RoomDirection).ToList();
                break;

            case "block_desc":
                data = data.OrderByDescending(s => s.blockName).ToList();
                break;

            case "type_desc":
                data = data.OrderByDescending(s => s.TypeName).ToList();
                break;

            case "busy_desc":
                data = data.OrderByDescending(s => s.Isbusy).ToList();
                break;

            case "fix_desc":
                data = data.OrderByDescending(s => s.IsNeedfix).ToList();
                break;

            case "clean_desc":
                data = data.OrderByDescending(s => s.isneedclean).ToList();
                break;

            case "service_desc":
                data = data.OrderByDescending(s => s.IsInService).ToList();
                break;

            case "number":
                data = data.OrderBy(s => s.RoomNum).ToList();
                break;

            case "dir":
                data = data.OrderBy(s => s.RoomDirection).ToList();
                break;

            case "block":
                data = data.OrderBy(s => s.blockName).ToList();
                break;

            case "type":
                data = data.OrderBy(s => s.TypeName).ToList();
                break;

            case "busy":
                data = data.OrderBy(s => s.Isbusy).ToList();
                break;

            case "fix":
                data = data.OrderBy(s => s.IsNeedfix).ToList();
                break;

            case "clean":
                data = data.OrderBy(s => s.isneedclean).ToList();
                break;

            case "service":
                data = data.OrderBy(s => s.IsInService).ToList();
                break;
            }
            RF.Data = data.ToList();

            return(View(RF));
        }