public ActionResult GetCartCount() { var hash = new Dictionary <string, object>(); string failureType = "error"; try { var count = 0; if (this.CurrentLoginUser == null) { //未ログインだったらセッションから取得 var cartList = Session[Constants.SSKEY_CART] as List <CBooking>; if (cartList != null) { count = cartList.Count(); } } else { //ログイン済だったらDBから取得 var wtBookingRepo = new CBookingRepository(); count = wtBookingRepo.GetCountByStatus(CBooking.PAYSTATUS_INIT, this.CurrentLoginUser.account_id); } hash.Add("Count", count); hash.Add("Result", "success"); } catch (Exception ex) { hash.Add("Result", failureType); hash.Add("Message", ex.Message); } return(Json(hash)); }
public ActionResult AddCart(CustomerItem currentItem, short quantity, short?fixed_qty, DateTime wed_date, string wed_time, bool is_reserve) { var hash = new Dictionary <string, object>(); string failureType = "error"; try { var cartList = Session[Constants.SSKEY_CART] as List <CBooking>; if (cartList != null) { //PKGの場合、既に同じアイテムがカートにあったらNG(異なるperiodでもNG) if (currentItem.is_pkg) { var exists = cartList.Any(m => m.item_cd == currentItem.item_cd); if (exists) { hash.Add("Result", "error"); hash.Add("Message", L("You've already selected same item.", "既に同じ商品がカートに入っています。")); return(Json(hash)); } } } //表示通貨判断 var is_japan = this.IsJpnClientOrJpnAccount(); var lang = this.CurrentRegionInfo.CurrentLanguage; var region_cd = this.CurrentRegionInfo.CurrentDestination; //Item詳細取得 var item = new CItemRepository() .FindItem( currentItem.item_cd, lang, wed_date); int account_id = this.CurrentLoginUser == null ? 0 : this.CurrentLoginUser.account_id; string c_num = this.CurrentLoginUser == null ? null : this.CurrentLoginUser.c_num; DateTime?wed_time_d = null; if (!String.IsNullOrEmpty(wed_time)) { wed_time_d = System.DateTime.ParseExact(wed_time, "HH:mm", null); } var booking = EditCBooking(item, account_id, c_num, quantity, wed_date, wed_time_d, is_reserve, currentItem); if (this.CurrentLoginUser != null) { //ログイン済の場合DB保存 var cBookingRepo = new CBookingRepository(); cBookingRepo.AddCart(booking); cartList = cBookingRepo.GetBookingList(CBooking.PAYSTATUS_INIT, this.CurrentLoginUser.account_id, IsJPN()); } else { //未ログインの場合、セッションの情報を更新 if (cartList == null) { cartList = new List <CBooking>(); } var exist_booking = cartList.Where(m => m.account_id == booking.account_id && m.area_cd == booking.area_cd && m.item_type == booking.item_type && m.alb_cover == booking.alb_cover && m.alb_mount == booking.alb_mount && m.alb_type == booking.alb_type && m.dvd_menucolor == booking.dvd_menucolor && m.item_cd == booking.item_cd && m.payment_status == CBooking.PAYSTATUS_INIT).FirstOrDefault(); if (exist_booking == null || (exist_booking.fixed_qty >= 1 || exist_booking.fixed_qty == null)) { booking.booking_id_for_session = cartList.Count() + 1; cartList.Add(booking); } else { //同じItemがカートに入っていたらquantityを更新(ただしfixed_qtyが数量固定のものは別レコードとしてカートに追加) var total = exist_booking.quantity + booking.quantity; exist_booking.quantity = (short)total; } } Session[Constants.SSKEY_CART] = cartList; var total_quantity = (short)cartList.Count(); this.CurrentSelectItem.wed_date = wed_date; hash.Add("Result", "success"); hash.Add("Count", total_quantity); } catch (Exception ex) { //ex = Common.GetMostInnerException(ex); hash.Add("Result", failureType); hash.Add("Message", ex.Message); } return(Json(hash)); }