public void UpdateBill(Guid id, BillOfSale bill) { BillOfSale foundBill = dataContext.BillesOfSale.First(f => f.Id.Equals(id)); if (foundBill == null) { throw new ArgumentException($"Bill with {id} id doesn't exist"); } dataContext.BillesOfSale[dataContext.BillesOfSale.IndexOf(foundBill)] = bill; }
public void GetBillTest() { Car Car1 = new Car("Alfa Romeo", "Brera", "Italia Independent", 210, "Matte Grey", VehicleType.Coupe, FuelType.Diesel, Transmission.Manual); WarehouseItem wi1 = new WarehouseItem(Car1, 10000, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b")); BillOfSale b1 = new BillOfSale(wi1, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"), Convert.ToDateTime("5.11.2020")); dataRepository.AddBill(b1); Assert.IsTrue(dataRepository.GetBill(b1.Id) == b1); }
public BillOutPutView(BillOfSale output, string deliveryEmployeeName, string saleEmployeeName) { this.DeliveryEmployeeName = deliveryEmployeeName; this.SaleEmployeeName = saleEmployeeName; this.BillID = output.BillID; this.CartID = output.CartID; this.BuyDate = output.BuyDate; this.Status = output.Status; this.TotalPrice = output.TotalPrice; }
public void DeleteBill(BillOfSale bill) { if (dataContext.BillesOfSale.Contains(bill)) { dataContext.BillesOfSale.Remove(bill); } else { throw new ArgumentException($"There isn't bill with {bill.Id} id in warehouse"); } }
public void UpdateBillTest() { Assert.AreEqual(0, dataService.GetAllBills().Count()); dataService.AddCar("Skoda", "Fabia", "Style", 210, "Silver Metalic", VehicleType.Small_car, FuelType.Petrol, Transmission.Manual); dataService.AddWarehouseItem(dataService.GetAllCars().First(), 10000); dataService.AddBill(dataService.GetAllWarehouseItems().First()); BillOfSale b2 = new BillOfSale(dataService.GetAllWarehouseItems().First(), new Guid(), DateTime.Now); dataService.updateBill(dataService.GetAllBills().First().Id, b2); Assert.AreEqual(dataService.GetAllBills().First(), b2); }
public void AddBill(BillOfSale bill) { try { dataContext.BillesOfSale.Add(bill); } catch (ArgumentNullException e) { throw new ArgumentNullException($"Bill with Id {bill.Id} do not exist.", e); } catch (ArgumentException e) { throw new ArgumentException($"Bill with Id {bill.Id} already exists.", e); } }
public void UpdateBillTest() { Car Car1 = new Car("Alfa Romeo", "Brera", "Italia Independent", 210, "Matte Grey", VehicleType.Coupe, FuelType.Diesel, Transmission.Manual); WarehouseItem wi1 = new WarehouseItem(Car1, 10000, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b")); BillOfSale b1 = new BillOfSale(wi1, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"), Convert.ToDateTime("5.11.2020")); dataRepository.AddBill(b1); Car Car2 = new Car("Skoda", "Fabia", "Style", 210, "Silver Metalic", VehicleType.Small_car, FuelType.Petrol, Transmission.Manual); WarehouseItem wi2 = new WarehouseItem(Car2, 210000, Guid.Parse("2273ec6b-7c26-4bce-8ec0-00a2773d108a")); BillOfSale b2 = new BillOfSale(wi2, Guid.Parse("bef406e7-61b5-4a14-86b7-d20af86cb752"), Convert.ToDateTime("8.11.2020")); dataRepository.UpdateBill(b1.Id, b2); Assert.AreEqual(b2, dataRepository.GetAllBillesOfSale().First()); }
public void updateBill(Guid id, BillOfSale bill) { dataRepository.UpdateBill(id, bill); }
public void DeleteBill(BillOfSale bill) { dataRepository.DeleteBill(bill); }
public ContentResult ApproveOrder(ApproveOrderInput input) { try { UnitOfWork unitOfWork = new UnitOfWork(new Entity.QLBHDienThoaiEntities()); //===========check CartID has exist in bill Of Sale ====================== var cartExist = unitOfWork.BillOfSale.Query(x => x.CartID == input.OrderId).Any(); if (cartExist) { return(Content(Data.ToJson(new ResponseData("", false, "", "Đã tồn tại")))); } //=========== Begin Process ====================== //Tạo 1 Expression mục đích là Include thêm thông tin CartDetails,Customer vào Cart Expression <Func <Cart, object> >[] includes = new Expression <Func <Cart, object> > [1]; includes[0] = x => x.Customer; //lấy thông tin cart để approve var cart = unitOfWork.Cart .Include(includes) .FirstOrDefault(x => x.CartID == input.OrderId); if (cart != null) { //===========Add billOf Sale====================== var billOfSale = new BillOfSale { CartID = cart.CartID, BuyDate = DateTime.Now, EmployeeID = input.EmployeeId, EmployeeDeliveryID = input.EmployeeDeliveryId, Status = StatusBillKey.InProcess, TotalPrice = cart.TotalPrice }; unitOfWork.BillOfSale.Add(billOfSale); unitOfWork.Complete(); //===========Add detail====================== var cartDetails = unitOfWork.CartDetail .Query(x => x.CartID == cart.CartID); List <BillSaleDetail> billSaleDetails = new List <BillSaleDetail>(); // Lấy danh sách cart detail qua billDetail foreach (var item in cartDetails) { BillSaleDetail billSaleDetail = new BillSaleDetail { BillID = billOfSale.BillID, ProductID = item.ProductID, PromotionID = item.PromotionID, Amount = item.Amount, PriceProduct = item.PriceProduct }; billSaleDetails.Add(billSaleDetail); } unitOfWork.BillSaleDetail.AddRange(billSaleDetails); unitOfWork.Complete(); //=========== Change status Cart ====================== var cartData = unitOfWork.Cart.Get(input.OrderId); cartData.Status = StatusCartKey.Success; unitOfWork.Cart.Update(cartData); unitOfWork.Complete(); } return(Content(Data.ToJson(new ResponseData("", true, "", "Thành công")))); } catch (Exception e) { return(Content(Data.ToJson(new ResponseData("", false, e.Message, "Không Thành công")))); } }
public async Task <IActionResult> ConfirmStay(ConfirmStayViewModel model) { if (ModelState.IsValid) { // this guest is strangely initialized in the confirm stay view model Guest guest = model.Guest; await _unitOfWork.Guest.Add(guest); _unitOfWork.Save(); // double check total cost by making a calculation on backend too RoomType roomType = await _unitOfWork.RoomType.Get(model.RoomTypeId); var baseTotal = roomType.Price * model.Nights; BillOfSale bill = new BillOfSale(); await _unitOfWork.BillOfSale.Add(bill); _unitOfWork.Save(); var roomTypeStr = (string.Format("{0:0.00}", roomType.Price)); LineItemCharge roomCharge = new LineItemCharge { Name = $"{roomTypeStr} x {model.Nights} nights", Amount = baseTotal, BillOfSaleId = bill.Id }; await _unitOfWork.LineItemCharge.Add(roomCharge); _unitOfWork.Save(); decimal feePercent = .1m; var serviceFee = Decimal.Multiply(baseTotal, feePercent); LineItemCharge serviceCharge = new LineItemCharge { Name = "Service Fee", Amount = serviceFee, BillOfSaleId = bill.Id }; await _unitOfWork.LineItemCharge.Add(serviceCharge); _unitOfWork.Save(); Booking booking = new Booking { GuestId = guest.Id, RoomId = model.RoomId, RoomTypeId = model.RoomTypeId, CheckInDate = model.CheckInDate, CheckOutDate = model.CheckOutDate, Adults = model.Adults, Children = model.Children, Promo = model.Promo, Status = BookingStatus.Booked, BillOfSaleId = bill.Id }; await _unitOfWork.Booking.Add(booking); _unitOfWork.Save(); return(RedirectToAction("BookingSuccess", "Reservations", new { bookingId = booking.Id, guestId = guest.Id, roomTypeId = model.RoomTypeId, billOfSaleId = bill.Id })); } var roomTypeForError = await _unitOfWork.RoomType.Get(model.RoomTypeId); model.RoomType = roomTypeForError; return(View(model)); }