public static ViewHotelOrderVM returnHotel(Order order) { ViewHotelOrderVM ovm = new ViewHotelOrderVM(); DataLayer dl = new DataLayer(); ovm.invoice = order.InvoiceNumber; ovm.creditCardNumber = order.CreditCard; HotelOrder hotelorder = (from x in dl.hotelOrders where x.InvoiceID == ovm.invoice select x).ToList <HotelOrder>().FirstOrDefault(); ovm.hotelName = hotelorder.HotelName; ovm.startDate = hotelorder.StartDate; ovm.endDate = hotelorder.EndDate; ovm.orderDate = order.OrderDate; ovm.status = order.Status; ovm.email = order.CustomerEmail; Customer cust = (from x in dl.customers where x.Email == ovm.email select x).ToList <Customer>().FirstOrDefault(); ovm.customerName = cust.FullName; ovm.customerId = cust.ID; List <HotelOrderDetails> hod = (from x in dl.hotelOrderDetails where x.Invoice == ovm.invoice select x).ToList <HotelOrderDetails>(); ovm.totalPrice = order.TotalPayment; //ovm.rooms = null; ovm.numberOfRooms = hod.Count; List <RoomVM> rooms = new List <RoomVM>(); for (int i = 0; i < hod.Count; ++i) { RoomVM r = new RoomVM() { roomComposition = hod[i].RoomComposition, roomPrice = hod[i].PaymentForRoom, roomDescription = hod[i].RoomType }; rooms.Add(r); } ovm.rooms = rooms; return(ovm); }
public async Task <HotelOrder> CreateHotelOrder(int productId, string userId, Category OrderCategory) { try { var hotelToBeBooked = await _context.Products.FirstOrDefaultAsync(p => p.Id == productId); if (hotelToBeBooked == null) { return(null); } if (OrderCategory.OrderCategoryVms.Count == 0) { return(null); } HotelOrder hotelOrder = new HotelOrder(); hotelOrder.ProductId = hotelToBeBooked.Id; hotelOrder.UserId = userId; hotelOrder.OrderCategories = new List <OrderCategory>(); foreach (var item in OrderCategory.OrderCategoryVms) { hotelOrder.OrderCategories.Add(new OrderCategory { Quantity = item.Quantity, Price = item.Price, Category = item.Category }); hotelOrder.TotalAmount = (item.Quantity) * item.Price + hotelToBeBooked.ConvinienceFee; } _context.HotelOrders.Add(hotelOrder); await _context.SaveChangesAsync(); if (await _context.SaveChangesAsync() > 0) { return(hotelOrder); } return(null); } catch (Exception ex) { _logger.LogError(ex.InnerException.ToString()); return(null); } }
public JsonResult SetFillorder(string method) { //string HotelID = HCRequest.GetString("hotelid"); //string RoomID = HCRequest.GetString("roomid"); //string RatePlanID = HCRequest.GetString("rateplanid"); //string yinDate = HCRequest.GetString("indate"); //string youtDate = HCRequest.GetString("outdate"); //string yRoomNum = HCRequest.GetString("roomnum"); //string UserName = HCRequest.GetString("username"); //string LinkTel = HCRequest.GetString("linktel"); string userweixinID = HCRequest.GetString("userweixinid"); string weixinid = HCRequest.GetString("weixinid"); string giftCouponid = HCRequest.GetString("giftcoupon"); //string couponid = HCRequest.GetString("coupon"); //string sumprice = HCRequest.GetString("sumprice"); //string netPrice = HCRequest.GetString("netPrice"); //string numPrice = HCRequest.GetString("RealPrice"); string UserName = HCRequest.GetString("username"); UserName = UserName.Remove(UserName.Length - 1, 1); HotelOrder hotelorder = new HotelOrder() { HotelID = Convert.ToInt32(HCRequest.GetString("hotelid")), RoomID = HCRequest.GetString("roomid"), RatePlanID = HCRequest.GetString("rateplanid"), YinDate = Convert.ToDateTime(HCRequest.GetString("indate")), YoutDate = Convert.ToDateTime(HCRequest.GetString("outdate")), YRoomNum = Convert.ToInt32(HCRequest.GetString("roomnum")), UserName = UserName, LinkTel = HCRequest.GetString("linktel"), UserWeiXinID = userweixinID, CouponID = HCRequest.GetString("couponid"), sSumPrice = Convert.ToInt32(HCRequest.GetString("sumprice")), NetPrice = Convert.ToInt32(HCRequest.GetString("netPrice")), RealPrice = Convert.ToInt32(HCRequest.GetString("RealPrice")), PayType = HCRequest.GetString("paytype"), memberid = HCRequest.GetString("memberid") }; string message = string.Empty; if (WeiXinPublic.ConvertHelper.ToInt(giftCouponid) > 0) { if (!hotel3g.Models.CouPon.GetCouPon(weixinid, userweixinID, giftCouponid, ref message)) { giftCouponid = "0"; } } UserGuarantee uguarantee = null; if (HCRequest.GetString("bankType") != "0") { int temp = 0; string cvv = HCRequest.GetString("bankCVV"); if (!int.TryParse(cvv, out temp)) { cvv = temp.ToString(); } ; string validTime = HCRequest.GetString("validTime"); if (int.TryParse(validTime, out temp)) { DateTime dt = new DateTime(Convert.ToInt32(("20" + validTime.Substring(2, 2))), Convert.ToInt32(validTime.Substring(0, 2)), 1); dt = dt.AddMonths(1).AddDays(-1); validTime = dt.ToString(); } else { validTime = ""; } uguarantee = new UserGuarantee() { HotelId = HCRequest.GetString("hotelid"), BankType = HCRequest.GetString("bankType"), BankCardNo = HCRequest.GetString("bankCardNo"), BankCVV = cvv, ValidTime = validTime, Cardholder = HCRequest.GetString("cardholder"), IdentityCard = HCRequest.GetString("identityCard"), IdentityType = HCRequest.GetString("identityType") }; } string lastTime = HCRequest.GetString("lastTime"); string ishourroom = HCRequest.GetString("ishourroom"); string WeiXinID = HCRequest.GetString("weixinid"); string res = "", did = ""; hotel3g.Models.HotelHelper.OrderSave(hotelorder, uguarantee, ishourroom, lastTime, WeiXinID, out res, out did); //插入会员折扣 优惠券 信息 if (!string.IsNullOrEmpty(did) && res.Equals("true")) { string[] UseCoupon = HCRequest.GetString("UseCoupon").Split('@'); string[] MemberRate = HCRequest.GetString("MemberRate").Split('@'); try { decimal erro; if (decimal.TryParse(MemberRate[1], out erro)) { hotel3g.Repository.PreferentialInformationItemClass InformationItem = new Repository.PreferentialInformationItemClass(); InformationItem.Coupon = string.IsNullOrEmpty(UseCoupon[1]) ? 0 : int.Parse(UseCoupon[1]); InformationItem.CouponId = string.IsNullOrEmpty(UseCoupon[0]) ? 0 : int.Parse(UseCoupon[0]); InformationItem.GradeName = MemberRate[0]; InformationItem.GradeRate = string.IsNullOrEmpty(MemberRate[1]) ? 0 : decimal.Parse(MemberRate[1]); InformationItem.OrderNo = did.Trim(); int Count = hotel3g.Repository.MemberHelper.InsertPreferentialInformation(InformationItem); } } catch { } } return(Json(new { ok = res, message = did, giftid = giftCouponid })); }
public ActionResult SubmitOrder(HotelCheckoutVM hc) { DataLayer dl = new DataLayer(); DateTime today = DateTime.Today; string date = today.ToString("dd/MM/yyyy").Replace("/", "."); double totalFee = Convert.ToDouble(hc.totalFee.ToString().Substring(1, hc.totalFee.Length - 1)); bool sameCustomer = false; List <HotelOrderDetails> hotelOrderDetailsList = new List <HotelOrderDetails>(); // first check if customer already exists in table List <Customer> customerFromDB = (from u in dl.customers where u.Email.ToLower() == hc.email.ToLower() select u).ToList <Customer>(); if (customerFromDB.Count != 0) // if customer already exists { // check if the input is the same as the customer data if (customerFromDB[0].FullName != hc.customerName || customerFromDB[0].ID != hc.id) { TempData["error"] = "This email address already exist in our records with different name and/or different id!"; return(View("HotelCheckout", hc)); } else if (customerFromDB[0].Location != hc.address || customerFromDB[0].PhoneNumber != hc.phone) { // update: delete this row and later add new customer row dl.customers.Remove(customerFromDB[0]); dl.SaveChanges(); } // else: same row - no need to update else { sameCustomer = true; } } string[] destination = hc.destination.Split(','); string destCountry = destination[1]; if (destination[1][0] == ' ') { destCountry = destination[1].Substring(1, destination[1].Length - 1); } Order order = new Order() { CreditCard = hc.creditCard, CustomerEmail = hc.email, OrderDate = date, Status = 0, TotalPayment = totalFee, Type = "Hotel", OrderDestination = destCountry, }; dl.orders.Add(order); // adding in memory and not to DB // dl.SaveChanges(); int INVOICE = order.InvoiceNumber; HotelOrder hotelOrder = new HotelOrder() { InvoiceID = INVOICE, StartDate = hc.startDate, EndDate = hc.endDate, HotelName = hc.hotelName, NumOfRooms = hc.numberOfRooms, Reviewed = 0, }; dl.hotelOrders.Add(hotelOrder); // adding in memory and not to DB // for (int i = 0; i < hc.numberOfRooms; ++i) { HotelOrderDetails hotelOrderDetails = new HotelOrderDetails() { RoomType = hc.room[i].roomDescription, PaymentForRoom = hc.room[i].roomPrice, RoomComposition = hc.room[i].roomComposition, Invoice = INVOICE }; //hotelOrderDetailsList.Add(hotelOrderDetails); dl.hotelOrderDetails.Add(hotelOrderDetails); // adding in memory and not to DB // } if (!sameCustomer) { Customer customer = new Customer() { Email = hc.email, FullName = hc.customerName, Location = hc.location, ID = hc.id, PhoneNumber = hc.phone }; dl.customers.Add(customer); // adding in memory and not to DB // } dl.SaveChanges(); // create object to sent to recipt view return(RedirectToAction("ViewOrderReceipt", "Support", new { invoice = INVOICE })); }