示例#1
0
        public static string GetFullAddress(MealsToGo.Models.AddressList address)
        {
            List <string> fulladdress = new List <string>();

            if ((address.Address1 != null) && (address.Address1 != ""))
            {
                fulladdress.Add(address.Address1);
            }

            if ((address.Address2 != null) && (address.Address2 != ""))
            {
                fulladdress.Add(address.Address1);
            }

            if ((address.City != null) && (address.City != ""))
            {
                fulladdress.Add(address.City);
            }

            if ((address.Province != null) && (address.Province != ""))
            {
                fulladdress.Add(address.Province);
            }

            if ((address.Zip != null) && (address.Zip != ""))
            {
                fulladdress.Add(address.Zip);
            }

            if ((address.LKUPCountry.Country != null) && (address.LKUPCountry.Country != ""))
            {
                fulladdress.Add(address.LKUPCountry.Country);
            }

            return(string.Join(",", fulladdress.ToArray()));
        }
        public ActionResult ProceedToCheckOutFinalOrder(int DeliveryMode, DateTime DeliveryDateTime, int PaymentOptionID, string Address1, string Address2, string City, int CountryID, string Province, Int64? Telephone, string Zip)
        {
            if (DeliveryMode == 3)
            {
                var userDetail = dbmeals.UserDetails.Where(x => x.UserId == WebSecurity.CurrentUserId).FirstOrDefault();
                if (userDetail != null)
                {
                    AddressList objAddressList = userDetail.AddressList;// dbmeals.AddressLists.Where(x => x.UserId == WebSecurity.CurrentUserId).OrderByDescending(y => y.DateUpdated).FirstOrDefault();
                    bool isnew = false;
                    if (objAddressList == null)
                    {
                        objAddressList = new AddressList();
                        isnew = true;
                    }
                    objAddressList.UserId = WebSecurity.CurrentUserId;
                    objAddressList.Address1 = Address1;
                    objAddressList.Address2 = Address2;
                    objAddressList.City = City;
                    objAddressList.CountryID = CountryID;
                    objAddressList.Province = Province;
                    objAddressList.Telephone = (Telephone.HasValue ? Telephone.ToString() : string.Empty);
                    objAddressList.IsBillingAddress = 1;
                    objAddressList.DateUpdated = DateTime.Now;
                    if (isnew)
                    {
                        dbmeals.AddressLists.Add(objAddressList);
                        dbmeals.SaveChanges();
                    }
                }
            }
            Models.FunOrder order = new Models.FunOrder();
            order.Status = (PaymentOptionID == 1) ? 1 : 0;
            order.UserId = WebSecurity.CurrentUserId;
            order.DateCreated = DateTime.Now;
            order.DateUpdated = DateTime.Now;
            order.ActualPickUpTime = DeliveryDateTime;

            //delivery=1,pickup 2
            order.DeliveryMethodID = DeliveryMode;
            order.PaymentOptionID = PaymentOptionID;
            order.EstimatedPickupTime = DeliveryDateTime;
            List<TempOrderList> lstTempOrderList = dbmeals.TempOrderLists.Where(x => x.sessionId == Session.SessionID && x.userid == WebSecurity.CurrentUserId).ToList();
            foreach (TempOrderList TempOrderList in lstTempOrderList)
            {
                FunOrderDetail orderDetail = new FunOrderDetail();
                orderDetail.Quantity = TempOrderList.qty;
                orderDetail.Description = TempOrderList.itemName;
                orderDetail.Price = TempOrderList.lineitemcost;
                order.Total = TempOrderList.TotalCost;
                order.FunOrderDetails.Add(orderDetail);
                int mealid = Convert.ToInt32(TempOrderList.MealItemId);
                var activeMealAd = dbmeals.ActiveMealAds.Where(x => x.MealAdID == mealid).FirstOrDefault();
                if (activeMealAd != null)
                {
                    activeMealAd.Quantity = activeMealAd.Quantity - TempOrderList.qty;
                    dbmeals.SaveChanges();
                }
            }
            if (dbmeals.TempOrderLists.Where(x => x.sessionId == Session.SessionID && x.userid == WebSecurity.CurrentUserId) != null)
            {
                order.Total = dbmeals.TempOrderLists.Where(x => x.sessionId == Session.SessionID && x.userid == WebSecurity.CurrentUserId).Sum(y => (y == null) ? 0 : y.TotalCost);
            }
            dbmeals.FunOrders.Add(order);
            if (PaymentOptionID == 1)
            {
                foreach (TempOrderList tempData in dbmeals.TempOrderLists.Where(x => x.sessionId == Session.SessionID && x.userid == WebSecurity.CurrentUserId))
                {
                   // dbmeals.TempOrderLists.Remove(tempData);
                }
            }
            foreach (TempOrderList TempOrderList in lstTempOrderList)
            {
                int MealAdID = Convert.ToInt32(TempOrderList.MealItemId);
                var activeMealAd = dbmeals.ActiveMealAds.Where(x => x.MealAdID == MealAdID).FirstOrDefault();
                if (activeMealAd != null)
                {
                    activeMealAd.Quantity = activeMealAd.Quantity - TempOrderList.qty;
                    dbmeals.SaveChanges();
                }
            }
            dbmeals.SaveChanges();
            int orderid = order.OrderID;
            decimal totalAmount = lstTempOrderList.Sum(x => x.TotalCost);
            var data = new { OrderId = orderid, amount = totalAmount, isCashPayment = PaymentOptionID == 1 };

            return Json(data, JsonRequestBehavior.AllowGet);
        }