コード例 #1
0
        public ActionResult Create(MealAdViewModel MealAdvm)
        {
            if (ModelState.IsValid)
            {
                MealAd mealad = Mapper.Map <MealAdViewModel, MealAd>(MealAdvm);

                foreach (var payment in MealAdvm.PaymentMethods)
                {
                    if (payment.Selected)
                    {
                        MealAds_PaymentOptions paymentoptions = new MealAds_PaymentOptions();
                        paymentoptions.PaymentOptionID = payment.PaymentMethodID;
                        mealad.MealAds_PaymentOptions.Add(paymentoptions);
                    }
                }

                foreach (var delivery in MealAdvm.DeliveryMethods)
                {
                    if (delivery.Selected)
                    {
                        MealAds_DeliveryMethods deliverymthd = new MealAds_DeliveryMethods();
                        deliverymthd.DeliveryMethodID = delivery.DeliveryMethodID;
                        mealad.MealAds_DeliveryMethods.Add(deliverymthd);
                    }
                }
                int orderingoptionnum = 0;
                var availabilityType  = db.AvailabilityTypes.Where(x => x.AvaiilabilityTypeID == mealad.AvailabilityTypeID).FirstOrDefault();
                if (availabilityType != null)
                {
                    string orderingoption = availabilityType.AvailabilityType1;
                    orderingoptionnum = Convert.ToInt32(orderingoption);
                }
                foreach (var schedules in MealAdvm.MealAdSchedules)
                {
                    MealAd_Schedules meadadschedule = new MealAd_Schedules();
                    meadadschedule.PickUpStartDateTime = schedules.PickUpStartDateTime;
                    meadadschedule.PickUpEndDateTime   = schedules.PickUpEndDateTime;
                    meadadschedule.LastOrderDateTime   = schedules.PickUpEndDateTime.AddHours(-orderingoptionnum);
                    mealad.MealAd_Schedules.Add(meadadschedule);
                    break;
                }

                mealad.MealAdID = _service.AddAndReturnID(mealad);

                eh.SendEmail("Insert");

                return(RedirectToAction("Details", "MealAd", new { id = mealad.MealAdID }));
            }

            return(View(MealAdvm));
        }
コード例 #2
0
        public JsonResult CreateMealAd(MealAdViewModel MealAdvm)
        {
            IMealAdService        _service = new MealAdService();
            ThreeSixtyTwoEntities db       = new ThreeSixtyTwoEntities();
            MealAd mealad = Mapper.Map <MealAdViewModel, MealAd>(MealAdvm);

            foreach (var payment in MealAdvm.PaymentMethods)
            {
                if (payment.Selected)
                {
                    MealAds_PaymentOptions paymentoptions = new MealAds_PaymentOptions();
                    paymentoptions.PaymentOptionID = payment.PaymentMethodID;
                    mealad.MealAds_PaymentOptions.Add(paymentoptions);
                }
            }

            foreach (var delivery in MealAdvm.DeliveryMethods)
            {
                if (delivery.Selected)
                {
                    MealAds_DeliveryMethods deliverymthd = new MealAds_DeliveryMethods();
                    deliverymthd.DeliveryMethodID = delivery.DeliveryMethodID;
                    mealad.MealAds_DeliveryMethods.Add(deliverymthd);
                }
            }
            int orderingoptionnum = 0;
            var availabilityType  = db.AvailabilityTypes.Where(x => x.AvaiilabilityTypeID == mealad.AvailabilityTypeID).FirstOrDefault();

            if (availabilityType != null)
            {
                string orderingoption = availabilityType.AvailabilityType1;
                orderingoptionnum = Convert.ToInt32(orderingoption);
            }
            foreach (var schedules in MealAdvm.MealAdSchedules)
            {
                MealAd_Schedules meadadschedule = new MealAd_Schedules();
                meadadschedule.PickUpStartDateTime = schedules.PickUpStartDateTime;
                meadadschedule.PickUpEndDateTime   = schedules.PickUpEndDateTime;
                meadadschedule.LastOrderDateTime   = schedules.PickUpEndDateTime.AddHours(-orderingoptionnum);
                mealad.MealAd_Schedules.Add(meadadschedule);
            }

            mealad.MealAdID = _service.AddAndReturnID(mealad);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }