private MealAdViewModel PopulateDropDown(MealAdViewModel mealadvm, MealAd mealad, int userid) { ThreeSixtyTwoEntities db = new ThreeSixtyTwoEntities(); IMealAdService _service = new MealAdService(); if (mealadvm == null) mealadvm = new MealAdViewModel(); var MealItems = from b in db.MealItems where b.UserId == userid select b; IEnumerable<MealItem> MealItemsList = MealItems.ToList(); mealadvm.MealItemsDD.MealItemsDDList = MealItemsList.Select(x => new SelectListItem { Value = x.MealItemId.ToString(), Text = x.MealItemName, Selected = (mealad != null && mealad.MealItemID == x.MealItemId) }); var AvailTypeMethod = from b in db.AvailabilityTypes select b; IEnumerable<AvailabilityType> AvailTypeList = AvailTypeMethod.ToList(); mealadvm.AvailabilityTypeDD.AvailabilityTypeDDList = AvailTypeList.Select(x => new SelectListItem { Value = x.AvaiilabilityTypeID.ToString(), Text = x.Descriptions, Selected = (mealad != null && mealad.AvailabilityTypeID == x.AvaiilabilityTypeID) }); mealadvm.DeliveryMethods = _service.GetDeliveryMethodDDList().Select(x => new DeliveryMethodViewModel { DeliveryMethod = x.DeliveryMethod, DeliveryMethodID = x.DeliveryMethodID, Selected = (mealad != null && mealad.MealAds_DeliveryMethods.Where(y => y.DeliveryMethodID == x.DeliveryMethodID).Count() > 0) }).ToList(); mealadvm.PaymentMethods = _service.PaymentMethodDDList().Select(x => new PaymentMethodViewModel { PaymentMethodID = x.PaymentOptionID, PaymentMethod = x.PaymentOption1, Selected = (mealad != null && mealad.MealAds_PaymentOptions.Where(y => y.PaymentOptionID == x.PaymentOptionID).Count() > 0) }).ToList(); MealAdSchedule mealads = new MealAdSchedule(); mealadvm.MealAdSchedules = new List<MealAdSchedule>(); if (mealad != null && mealad.MealAd_Schedules != null && mealad.MealAd_Schedules.Count > 0) { foreach (var data in mealad.MealAd_Schedules) { mealadvm.MealAdSchedules.Add(new MealAdSchedule() { LastOrderDateTime = data.LastOrderDateTime, PickUpEndDateTime = data.PickUpEndDateTime, PickUpStartDateTime = data.PickUpStartDateTime }); } } else { mealadvm.MealAdSchedules.Add(mealads); } return mealadvm; }
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); }
public JsonResult MyMealAd(int userid) { ThreeSixtyTwoEntities db = new ThreeSixtyTwoEntities(); IMealAdService _service = new MealAdService(); IEnumerable<MealAd> mealad = _service.FindByUser(userid); ViewBag.AddressPresent = false; ViewBag.PrivacySettingConfirmed = false; ViewBag.SellerTermsandSettingAccepted = false; //if (mealad.Count() == 0) //{ // ViewBag.MealItemCount = db.MealItems.Where(x => x.UserId == userid).Count(); // ViewBag.AddressPresent = db.UserDetails.Any(x => x.UserId == userid && x.AddressID != null); // ViewBag.PrivacySettingConfirmed = db.UserSettings.Where(x => x.UserID == userid).All(x => x.Verified == 1); // var useragreed = db.UserAgreementsAcceptanceDetails.Where(x => x.UserID == userid).FirstOrDefault(); // if (useragreed != null) // ViewBag.SellerTermsandSettingAccepted = true; // if (!((ViewBag.MealItemCount != 0) && (ViewBag.AddressPresent) && (ViewBag.PrivacySettingConfirmed) && (ViewBag.SellerTermsandSettingAccepted))) // { // Session["ReadyToAdvertise"] = "0"; // } //} IEnumerable<MealAdViewModel> mealadvm = Mapper.Map<IEnumerable<MealAd>, IEnumerable<MealAdViewModel>>(mealad); foreach (var item in mealad) { if (item.MealItem != null) mealadvm.Where(x => x.MealAdID == item.MealAdID).FirstOrDefault().MealItemName = item.MealItem.MealItemName; } return Json(mealadvm, JsonRequestBehavior.AllowGet); }