private static PaginationResult <ActiveCustomer> ParseCustomerList(string houseId, IDataReader reader)
        {
            var result = new PaginationResult <ActiveCustomer>()
            {
                Data = new List <ActiveCustomer>()
            };
            var allRooms = RoomService.GetRooms(houseId);

            while (reader.Read())
            {
                var item = new ActiveCustomer
                {
                    Id           = reader["Id"].ToString(),
                    Address      = reader["Address"]?.ToString() ?? "",
                    Country      = reader["Country"]?.ToString() ?? "",
                    Email        = reader["Email"]?.ToString() ?? "",
                    Name         = reader["Name"].ToString(),
                    Phone        = reader["Phone"]?.ToString() ?? "",
                    PassportOrId = reader["passportOrId"].ToString(),
                    OrderId      = reader["OrderId"].ToString(),
                    CheckinDate  = DateTime.Parse(reader["CheckinDate"].ToString()),
                    CheckoutDate = DateTime.Parse(reader["CheckoutDate"].ToString()),
                    Rooms        = new List <Room>()
                };

                result.Data.Add(item);
            }
            reader.NextResult();
            reader.Read();
            var total = int.Parse(reader["Total"].ToString());

            result.Total = total;

            reader.NextResult();
            var roomMap = new Dictionary <string, List <string> >();

            while (reader.Read())
            {
                var orderId = reader["OrderId"].ToString();
                var roomId  = reader["RoomId"].ToString();
                if (!roomMap.ContainsKey(orderId))
                {
                    roomMap.Add(orderId, new List <string>());
                }
                roomMap[orderId].Add(roomId);
            }

            foreach (var item in result.Data)
            {
                foreach (var roomId in roomMap[item.OrderId])
                {
                    var room = allRooms.Single(r => r.Id.Equals(roomId));
                    item.Rooms.Add(room);
                }
            }

            return(result);
        }
Exemple #2
0
        private static BookingOrder Parse(IDataReader reader)
        {
            var ps = new PaymentRecordService();

            reader.Read();
            var order = new BookingOrder
            {
                Id           = reader["Id"].ToString(),
                CheckinDate  = DateTime.Parse(reader["CheckinDate"].ToString()),
                CheckOutDate = DateTime.Parse(reader["CheckoutDate"].ToString()),
                Note         = reader["Note"]?.ToString() ?? string.Empty,
                Status       = reader["Status"].ToString(),
                TotalGuest   = int.Parse(reader["TotalGuest"].ToString()),
                StayLength   = reader["StayLength"].ToString(),
                HouseId      = reader["HouseId"].ToString(),
                PaymentCycle = new PaymentCycle(reader["PaymentCycle"].ToString())
            };

            order.Deposit = new Deposit
            {
                OrderId = order.Id,
                Id      = reader["DepositId"].ToString(),
                Amount  = reader["DepositAmount"].ToString(),
                Unit    = reader["DepositUnit"].ToString(),
                Date    = DateTime.Parse(reader["DepositDate"].ToString())
            };

            reader.NextResult();
            order.Customers = new List <Customer>();
            while (reader.Read())
            {
                var customer = CustomerService.GetById(reader["CustomerId"].ToString());
                order.Customers.Add(customer);
            }

            reader.NextResult();
            order.Rooms = new List <Room>();
            while (reader.Read())
            {
                var room = RoomService.GetById(reader["RoomId"].ToString());
                order.Rooms.Add(room);
            }

            order.Discounts = ps.GetByOrderId(order.Id, "Order-Discount");
            order.Payments  = ps.GetByOrderId(order.Id, "Order-Payment");

            return(order);
        }
        public static List <ActiveCustomer> GetCustomerCheckoutByDate(string houseId, DateTime date)
        {
            return(SqlHelper.ExecuteReader(ConfigManager.ConnectionString, CommandType.StoredProcedure,
                                           SP_CUSTOMER_SELECT_CHECKOUT_BY_DATE,
                                           new[]
            {
                new SqlParameter("@houseId", houseId),
                new SqlParameter("@date", date)
            }, reader =>
            {
                var list = new List <ActiveCustomer>();
                var allRooms = RoomService.GetRooms(houseId);
                while (reader.Read())
                {
                    var item = new ActiveCustomer
                    {
                        Id = reader["Id"].ToString(),
                        Address = reader["Address"]?.ToString() ?? "",
                        Country = reader["Country"]?.ToString() ?? "",
                        Email = reader["Email"]?.ToString() ?? "",
                        Name = reader["Name"].ToString(),
                        Phone = reader["Phone"]?.ToString() ?? "",
                        PassportOrId = reader["passportOrId"].ToString(),
                        Rooms = new List <Room>(),
                        OrderId = reader["OrderId"].ToString(),
                        CheckinDate = DateTime.Parse(reader["CheckinDate"].ToString()),
                        CheckoutDate = DateTime.Parse(reader["CheckoutDate"].ToString())
                    };
                    var roomId = reader["RoomId"].ToString();
                    var activeItem = list.FirstOrDefault(c => c.Id == item.Id);
                    if (activeItem == null)
                    {
                        item.Rooms.Add(allRooms.Single(r => r.Id == roomId));
                        list.Add(item);
                    }
                    else
                    {
                        activeItem.Rooms.Add(allRooms.Single(r => r.Id == roomId));
                    }
                }

                return list;
            }));
        }
Exemple #4
0
        public static List <BookingOrder> GetOrdersInRange(string houseId, DateTime startDate, DateTime endDate)
        {
            return(SqlHelper.ExecuteReader(SP_ORDER_SELECT_IN_RANGE,
                                           new[]
            {
                new SqlParameter("@houseId", houseId),
                new SqlParameter("@startDate", startDate),
                new SqlParameter("@endDate", endDate),
            }, reader =>
            {
                var result = new List <BookingOrder>();
                while (reader.Read())
                {
                    var order = new BookingOrder
                    {
                        Id = reader["Id"].ToString(),
                        CheckinDate = DateTime.Parse(reader["CheckinDate"].ToString()),
                        CheckOutDate = DateTime.Parse(reader["CheckoutDate"].ToString()),
                        Note = reader["Note"]?.ToString() ?? string.Empty,
                        Status = reader["Status"].ToString(),
                        TotalGuest = int.Parse(reader["TotalGuest"].ToString()),
                        StayLength = reader["StayLength"].ToString(),
                        HouseId = reader["HouseId"].ToString(),
                        Rooms = new List <Room>()
                    };
                    result.Add(order);
                }
                reader.NextResult();

                var mapping = result.ToDictionary(o => o.Id, o => o);
                var rooms = RoomService.GetRooms(houseId);
                var roomMapping = rooms.ToDictionary(r => r.Id, r => r);
                while (reader.Read())
                {
                    var order = mapping[reader["OrderId"].ToString()];
                    order.Rooms.Add(roomMapping[reader["RoomId"].ToString()]);
                }

                return result;
            }));
        }
Exemple #5
0
        public static Dashboard GetDashboard(string houseId, DateTime startDate, DateTime endDate)
        {
            var dashboard = new Dashboard
            {
                Houses = HouseService.GetHouses(houseId).Select(h => new HouseOverviewModel(h)).ToList()
            };

            foreach (var h in dashboard.Houses)
            {
                h.Rooms = RoomService.GetRoomsWithStatuses(h.Id);
                var notAvailableRoomCount = h.Rooms.Count(r => r.Status != "Available");
                if (h.Rooms.Count > 0)
                {
                    h.RoomCoverRating = notAvailableRoomCount * 100 / h.Rooms.Count;
                }
                h.TotalGuest            = CustomerService.CountByHouse(h.Id);
                h.CustomersCheckoutList = CustomerService.GetCustomerCheckoutByDate(h.Id, DateTime.Now);

                h.RoomsState = new List <RoomStateRange>();
                var orders = OrderService.GetOrdersInRange(h.Id, startDate, endDate);

                var days = endDate.Subtract(startDate).Days;

                foreach (var room in h.Rooms)
                {
                    var item = new RoomStateRange()
                    {
                        StartDate   = startDate,
                        EndDate     = endDate,
                        RoomId      = room.Id,
                        RoomNumber  = room.RoomNumber,
                        States      = new List <RoomState>(),
                        PercentItem = 100.0f / days
                    };
                    for (var i = 0; i < days; i++)
                    {
                        item.States.Add(new RoomState
                        {
                            Availability = "Available",
                            Date         = startDate.AddDays(i),
                            RoomId       = item.RoomId
                        });
                    }
                    h.RoomsState.Add(item);
                }

                foreach (var order in orders)
                {
                    var dstart = DateTime.Compare(order.CheckinDate, startDate) < 0 ? startDate : order.CheckinDate;
                    var dend   = DateTime.Compare(order.CheckOutDate, endDate) < 0 ? order.CheckOutDate : endDate;
                    days = dend.Subtract(dstart).Days;
                    foreach (var room in order.Rooms)
                    {
                        var item = h.RoomsState.Find(r => r.RoomId.Equals(room.Id));
                        for (var i = 0; i < days; i++)
                        {
                            var date          = dstart.AddDays(i);
                            var roomStateItem = item.States.Find(s => s.Date.Subtract(date).Days == 0);
                            roomStateItem.Availability = order.Status == "Active" ? "Busy" : "Reserved";
                            roomStateItem.OrderId      = order.Id;
                        }
                    }
                }
            }

            return(dashboard);
        }