Пример #1
0
        public static Task <Bill> Book(Employee employee, Bill bill, List <Booking> bookings)
        {
            bill.Patron   = bill.Patron.GetManaged();
            bill.Employee = employee;

            if (
                bookings.Count() !=
                bookings.ToList().Distinct(new EqualityBooking(Booking.StatusEnum.Booked)).Count()
                )
            {
                throw new Exception("Có booking trùng nhau");
            }

            foreach (var booking in bookings)
            {
                booking.EmployeeBooking = employee;
                booking.Room            = booking.Room.GetManaged();
                if (!booking.Room.IsActive)
                {
                    throw new Exception("Phòng " + booking.Room.Id + " đã ngừng hoạt động");
                }

                if (booking.BookCheckInTime >= booking.BookCheckOutTime || booking.BookCheckInTime < DateTimeOffset.Now)
                {
                    throw new Exception("Ngày check-in, check-out dự kiến không hợp lệ");
                }

                if (!booking.Room.IsEmptyRoom(booking.BookCheckInTime, booking.BookCheckOutTime))
                {
                    throw new Exception("Phòng đã được đặt hoặc đang được sử dụng");
                }
            }

            return(BillDataAccess.Book(bill, bookings));
        }
Пример #2
0
        public void Mutation_DeleteServicesDetail_InvalidBooking_Status()
        {
            Database.WriteAsync(realm =>
            {
                realm.Add(new Booking
                {
                    Id               = 200,
                    Status           = (int)Booking.StatusEnum.CheckedOut,
                    EmployeeBooking  = EmployeeDataAccess.Get("admin"),
                    EmployeeCheckIn  = EmployeeDataAccess.Get("admin"),
                    EmployeeCheckOut = EmployeeDataAccess.Get("admin"),
                    Bill             = BillDataAccess.Get(1),
                    Room             = RoomDataAccess.Get(1)
                });
                realm.Add(new ServicesDetail
                {
                    Id      = 11,
                    Booking = BookingBusiness.Get(1),
                    Service = ServiceBusiness.Get(200),
                    Number  = 10
                });
            }).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Phòng đã check-out. Không thể cập nhật/xóa chi tiết dịch vụ",
                @"/_GraphQL/ServicesDetail/mutation.deleteServicesDetail.gql",
                new { id = 11 },
                p => p.PermissionCleaning = true
                );
        }
Пример #3
0
        /// <summary>
        /// 删除账单
        /// </summary>
        /// <param name="goods">通过goods.id</param>
        public bool deleteBill(Goods goods, out string errorMessage)
        {
            string procedureName = "账单_删除_ById";

            SqlParameter[] thisParams = new SqlParameter[1];
            thisParams[0] = new SqlParameter("@id", goods.id);
            return(BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out errorMessage));
        }
Пример #4
0
        /// <summary>
        /// 删除商品类别
        /// </summary>
        /// <param name="goods">通过goodsType.id</param>
        public bool deleteGoodsType(GoodsType goodsType, out string errorMessage)
        {
            string procedureName = "商品类别_删除_ById";

            SqlParameter[] thisParams = new SqlParameter[1];
            thisParams[0] = new SqlParameter("@id", goodsType.goodsTypeCode);
            return(BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out errorMessage));
        }
Пример #5
0
        /// <summary>
        /// 查询商品品类
        /// </summary>
        /// <returns></returns>
        public DataTable searchGoodsType()
        {
            DataTable type_dt       = new DataTable();
            string    procedureName = "商品类别_查询";

            BillDataAccess.ExecuteStoredProcedure(procedureName, out type_dt);
            return(type_dt);
        }
Пример #6
0
        /// <summary>
        /// 查询所有账单
        /// </summary>
        /// <returns></returns>
        public DataTable searchAllBillDesc()
        {
            DataTable bill_dt       = new DataTable();
            string    procedureName = "账单_查询_All";

            BillDataAccess.ExecuteStoredProcedure(procedureName, out bill_dt);
            return(bill_dt);
        }
Пример #7
0
        /// <summary>
        /// 修改商品类别
        /// </summary>
        /// <param name="goods"></param>
        public bool updateGoodsType(GoodsType goodsType, out string errorMessage)
        {
            string procedureName = "商品类别_修改";

            SqlParameter[] thisParams = new SqlParameter[2];
            thisParams[0] = new SqlParameter("@类别代码", goodsType.goodsTypeCode);
            thisParams[1] = new SqlParameter("@商品类别", goodsType.goodsTypeName);
            return(BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out errorMessage));
        }
Пример #8
0
        /// <summary>
        /// 增加商品类别并查询记录
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        public DataTable addGoodsType(GoodsType goodsType, out string errorMessage)
        {
            DataTable goodsType_dt  = new DataTable();
            string    procedureName = "商品类别_增加";

            SqlParameter[] thisParams = new SqlParameter[2];
            thisParams[0] = new SqlParameter("@类别代码", goodsType.goodsTypeCode);
            thisParams[1] = new SqlParameter("@商品类别", goodsType.goodsTypeName);
            BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out goodsType_dt, out errorMessage);
            return(goodsType_dt);
        }
Пример #9
0
 public Entity Get(string codebill)
 {
     if (codebill == null || codebill.Equals("0"))
     {
         BillDataAccess dataAccess = new BillDataAccess(_settings.ConnectionString);
         return(dataAccess.getBills());
     }
     else
     {
         BillDataAccess dataAccess = new BillDataAccess(_settings.ConnectionString);
         return(dataAccess.searchBill(codebill));
     }
 }
Пример #10
0
        /// <summary>
        /// 修改账单
        /// </summary>
        /// <param name="goods"></param>
        public bool updateBills(Goods goods, out string errorMessage)
        {
            string procedureName = "账单_修改";

            SqlParameter[] thisParams = new SqlParameter[7];
            thisParams[0] = new SqlParameter("@商品名称", goods.goodsName);
            thisParams[1] = new SqlParameter("@商场", goods.mall);
            thisParams[2] = new SqlParameter("@商品类别", goods.goodsType);
            thisParams[3] = new SqlParameter("@备注", goods.goodsMark);
            thisParams[4] = new SqlParameter("@商品价格", goods.goodsPrice);
            thisParams[5] = new SqlParameter("@购买时间", goods.createDate);
            thisParams[6] = new SqlParameter("@id", goods.id);
            return(BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out errorMessage));
        }
Пример #11
0
        /// <summary>
        /// 增加记录并按倒序查询记录
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        public DataTable addBills(Goods goods, out string errorMessage)
        {
            DataTable bill_dt       = new DataTable();
            string    procedureName = "账单_增加";

            SqlParameter[] thisParams = new SqlParameter[6];
            thisParams[0] = new SqlParameter("@商品名称", goods.goodsName);
            thisParams[1] = new SqlParameter("@商场", goods.mall);
            thisParams[2] = new SqlParameter("@商品类别", goods.goodsType);
            thisParams[3] = new SqlParameter("@备注", goods.goodsMark);
            thisParams[4] = new SqlParameter("@商品价格", goods.goodsPrice);
            thisParams[5] = new SqlParameter("@购买时间", goods.createDate);
            BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out bill_dt, out errorMessage);
            return(bill_dt);
        }
Пример #12
0
        /// <summary>
        /// 根据条件查询账单
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        public DataTable searchBillByCondition(Goods goods)
        {
            DataTable bill_dt       = new DataTable();
            string    procedureName = "账单_查询";
            string    errorMessage;

            SqlParameter[] thisParams = new SqlParameter[8];
            thisParams[0] = new SqlParameter("@商品名称", goods.goodsName);
            thisParams[1] = new SqlParameter("@商场", goods.mall);
            thisParams[2] = new SqlParameter("@商品类别", goods.goodsType);
            thisParams[3] = new SqlParameter("@备注", goods.goodsMark);
            thisParams[4] = new SqlParameter("@商品价格min", goods.goodsPriceMin);
            thisParams[5] = new SqlParameter("@商品价格max", goods.goodsPriceMax);
            thisParams[6] = new SqlParameter("@购买时间begin", goods.createDateBegin);
            thisParams[7] = new SqlParameter("@购买时间end", goods.createDateEnd);
            BillDataAccess.ExecuteStoredProcedure(procedureName, ref thisParams, out bill_dt, out errorMessage);
            return(bill_dt);
        }
Пример #13
0
 public void Mutation_RequestCheckOut()
 {
     Database.WriteAsync(realm => realm.Add(new Booking
     {
         Id               = 30,
         Status           = (int)Booking.StatusEnum.CheckedIn,
         EmployeeBooking  = EmployeeDataAccess.Get("admin"),
         EmployeeCheckIn  = EmployeeDataAccess.Get("admin"),
         EmployeeCheckOut = EmployeeDataAccess.Get("admin"),
         Bill             = BillDataAccess.Get(1),
         Room             = RoomDataAccess.Get(1)
     })).Wait();
     SchemaHelper.Execute(
         @"/_GraphQL/Booking/mutation.requestCheckOut.gql",
         @"/_GraphQL/Booking/mutation.requestCheckOut.schema.json",
         new { id = 30 },
         p => p.PermissionManageRentingRoom = true
         );
 }
Пример #14
0
 public void Mutation_CheckOut_InvalidBookingStatus()
 {
     Database.WriteAsync(realm => realm.Add(new Booking
     {
         Id               = 21,
         Status           = (int)Booking.StatusEnum.CheckedIn,
         EmployeeBooking  = EmployeeDataAccess.Get("admin"),
         EmployeeCheckIn  = EmployeeDataAccess.Get("admin"),
         EmployeeCheckOut = EmployeeDataAccess.Get("admin"),
         Bill             = BillDataAccess.Get(1),
         Room             = RoomDataAccess.Get(1)
     })).Wait();
     SchemaHelper.ExecuteAndExpectError(
         "Booking chưa thực hiện yêu cầu check-out",
         @"/_GraphQL/Booking/mutation.checkOut.gql",
         new { id = 21 },
         p => p.PermissionManageRentingRoom = true
         );
 }
Пример #15
0
        public static Task <Bill> PayTheBill(Employee employee, int billId)
        {
            var billInDatabase = Get(billId);

            if (billInDatabase == null)
            {
                throw new Exception("Mã bill không tồn tại");
            }

            foreach (var booking in billInDatabase.Bookings)
            {
                if (booking.Status != (int)Booking.StatusEnum.CheckedOut)
                {
                    throw new Exception("Có phòng chưa Check-out, không thể thanh toán");
                }
            }

            return(BillDataAccess.PayTheBill(employee, billInDatabase));
        }
Пример #16
0
        public void Mutation_RequestCheckOut_InvalidBookingStatus()
        {
            Database.WriteAsync(realm => realm.Add(new Booking
            {
                Id               = 31,
                Status           = (int)Booking.StatusEnum.CheckedOut,
                EmployeeBooking  = EmployeeDataAccess.Get("admin"),
                EmployeeCheckIn  = EmployeeDataAccess.Get("admin"),
                EmployeeCheckOut = EmployeeDataAccess.Get("admin"),
                Bill             = BillDataAccess.Get(1),
                Room             = RoomDataAccess.Get(1)
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Không thể yêu cầu trả phòng",
                @"/_GraphQL/Booking/mutation.requestCheckOut.gql",
                new { id = 31 },
                p => p.PermissionManageRentingRoom = true
                );
        }
Пример #17
0
        public void Mutation_CheckIn_InvalidBookingStatus()
        {
            Database.WriteAsync(realm => realm.Add(new Booking
            {
                Id               = 11,
                Status           = (int)Booking.StatusEnum.CheckedIn,
                EmployeeBooking  = EmployeeDataAccess.Get("admin"),
                EmployeeCheckIn  = null,
                EmployeeCheckOut = null,
                Bill             = BillDataAccess.Get(1),
                Room             = RoomDataAccess.Get(1)
            })).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Phòng đã được check-in, không thể check-in lại",
                @"/_GraphQL/Booking/mutation.checkIn.gql",
                new { id = 11 },
                p => p.PermissionManageRentingRoom = true
                );
        }
Пример #18
0
        public static void Cancel(int bookingId)
        {
            var bookingInDatabase = Get(bookingId);

            if (bookingInDatabase == null)
            {
                throw new Exception("Mã Booking không tồn tại");
            }

            if (bookingInDatabase.Status != (int)Booking.StatusEnum.Booked)
            {
                throw new Exception("Không thể hủy đặt phòng. Booking đã hoặc đang được sử dụng.");
            }

            if (bookingInDatabase.Bill.Bookings.Count() == 1)
            {
                BillDataAccess.Delete(bookingInDatabase.Bill);
            }

            BookingDataAccess.Delete(bookingInDatabase);
        }
Пример #19
0
        public void Mutation_CheckOut_InvalidEmployee()
        {
            Database.WriteAsync(realm =>
            {
                realm.Add(new Employee
                {
                    Id           = "nhanvien_1",
                    Address      = "Địa chỉ",
                    IsActive     = true,
                    Birthdate    = DateTimeOffset.Now,
                    Email        = "*****@*****.**",
                    Gender       = true,
                    Name         = "Quản trị viên",
                    IdentityCard = "123456789",
                    Password     = CryptoHelper.Encrypt("12345678"),
                    PhoneNumber  = "+84 0123456789",
                    Position     = PositionBusiness.Get(1),
                    StartingDate = DateTimeOffset.Now
                });
                realm.Add(new Booking
                {
                    Id               = 22,
                    Status           = (int)Booking.StatusEnum.RequestedCheckOut,
                    EmployeeBooking  = EmployeeDataAccess.Get("admin"),
                    EmployeeCheckIn  = EmployeeDataAccess.Get("admin"),
                    EmployeeCheckOut = EmployeeDataAccess.Get("nhanvien_1"),
                    Bill             = BillDataAccess.Get(1),
                    Room             = RoomDataAccess.Get(1)
                });
            }).Wait();

            SchemaHelper.ExecuteAndExpectError(
                "Nhân viên không được phép check-out",
                @"/_GraphQL/Booking/mutation.checkOut.gql",
                new { id = 22 },
                p => p.PermissionManageRentingRoom = true
                );
        }
Пример #20
0
 public static Bill Get(int billId) => BillDataAccess.Get(billId);
Пример #21
0
 public static IEnumerable <Bill> Get() => BillDataAccess.Get();
Пример #22
0
 // GET: Bill
 public ActionResult Index()
 {
     ViewData["BillsList"] = BillDataAccess.getListBillByStoreID(1);
     return(View("Management"));
 }
Пример #23
0
 public BillBusinessAccess()
 {
     myDataBase     = DatabaseFactory.CreateDatabase(C_ConnectionString);
     billDataAccess = new BillDataAccess(myDataBase);
 }
Пример #24
0
        public IActionResult Post([FromBody] Bill value)
        {
            BillDataAccess dataAccess = new BillDataAccess(_settings.ConnectionString);

            return(Json(dataAccess.addBill(value)));
        }