public JsonResult CreateMealAdDD(int userid) { MealAd mealad = new MealAd(); MealAdViewModel mealadvm = Mapper.Map <MealAd, MealAdViewModel>(mealad); mealadvm = PopulateDropDown(mealadvm, mealad, userid); return(Json(mealadvm, JsonRequestBehavior.AllowGet)); }
public int AddAndReturnID(MealAd mealad) { // mealad.dc = DateTime.Now; //mealitem.Status = 1; // mealitem.Price =10.0M; unitOfWork.mealadrepository.Add(mealad); unitOfWork.Save(); int mealadid = mealad.MealAdID; // unitOfWork.Save(); foreach (var payment in mealad.MealAds_PaymentOptions) { payment.MealAdID = mealadid; unitOfWork.MealPaymentRepository.Add(payment); } unitOfWork.Save(); foreach (var deliverymethod in mealad.MealAds_DeliveryMethods) { deliverymethod.MealAdID = mealadid; unitOfWork.MealadDeliveryRepository.Add(deliverymethod); } //foreach (var schedules in mealad.MealAd_Schedules) //{ // schedules.MealAdID = mealadid; // unitOfWork.MealScheduleRepository.Add(schedules); //} unitOfWork.Save(); try { unitOfWork.mealadrepository.ExecWithStoreProcedureNoResults("PopulateActiveMealAd @MealAdID,@CRUD", new SqlParameter("MealAdID", SqlDbType.BigInt) { Value = mealad.MealAdID }, new SqlParameter("CRUD", SqlDbType.Char) { Value = "C" } ); } catch (Exception ex) { string msg = ex.Message; } unitOfWork.Dispose(); return(mealadid); }
public void Add(MealAd MealAd) { var fileName = ""; unitOfWork.mealadrepository.Add(MealAd); unitOfWork.Save(); unitOfWork.Dispose(); }
public ActionResult DeleteConfirmed(int id) { MealAd MealAd = db.MealAds.Find(id); db.MealAds.Remove(MealAd); db.SaveChanges(); eh.SendEmail("Delete"); //return RedirectToAction("Index"); return(RedirectToAction("Index", new { userID = WebSecurity.CurrentUserId })); }
// // GET: /MealAd/Create public ActionResult Create(int userid, int mealitemid = -1) { MealAd mealad = new MealAd(); MealAdViewModel mealadvm = Mapper.Map <MealAd, MealAdViewModel>(mealad); mealadvm = PopulateDropDown(mealadvm, mealad, userid); return(View(mealadvm)); }
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)); }
// // GET: /MealAd/Details/5 public ActionResult Details(int id = 0) { MealAd mealad = db.MealAds.Find(id); if (mealad == null) { mealad = new MealAd(); } MealAdViewModel mealadvm = Mapper.Map <MealAd, MealAdViewModel>(mealad); mealadvm.MealItemName = mealad.MealItem.MealItemName; mealadvm = PopulateDropDown(mealadvm, mealad, WebSecurity.CurrentUserId); return(View(mealadvm)); }
public bool Update(MealAd mt) { try { unitOfWork.mealadrepository.Update(mt); unitOfWork.Save(); unitOfWork.Dispose(); return(true); } catch (Exception e) { unitOfWork.Dispose(); return(false); } }
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)); }
// // GET: /MealAd/Create public ActionResult Create(int userid, int mealitemid = -1) { MealAd mealad = new MealAd(); MealAdViewModel mealadvm = Mapper.Map <MealAd, MealAdViewModel>(mealad); mealadvm = PopulateDropDown(mealadvm, mealad, userid); var list = new List <SelectListItem>(); for (var i = 2; i < 10; i++) { list.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() }); } ViewBag.list = list; return(View(mealadvm)); }
public ActionResult Edit(MealAdViewModel MealAdvm, FormCollection frmcoll) { if (ModelState.IsValid) { MealAd existingMealAd = db.MealAds.Find(MealAdvm.MealAdID); existingMealAd.MaxOrders = Convert.ToInt32(MealAdvm.MaxOrders); List <MealAd_Schedules> lstMealAd_Schedules = new List <MealAd_Schedules>(); foreach (var allergenic in existingMealAd.MealAd_Schedules) { lstMealAd_Schedules.Add(allergenic); } foreach (var allergenic in lstMealAd_Schedules) { //mealitem.MealItems_AllergenicFoods.Remove(allergenic); db.MealAd_Schedules.Remove(allergenic); db.Entry(allergenic).State = EntityState.Deleted; db.SaveChanges(); } //existingMealAd.MealAd_Schedules.Remove( //db.SaveChanges(); 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(0); existingMealAd.MealAd_Schedules.Add(meadadschedule); } //db.Entry(MealAd).State = EntityState.Modified; db.SaveChanges(); eh.SendEmail("Update"); return(RedirectToAction("Index", new { userID = WebSecurity.CurrentUserId })); } return(View(MealAdvm)); }
// // GET: /MealAd/Delete/5 public ActionResult Delete(int id = 0) { //MealAd MealAd = db.MealAds.Find(id); //if (MealAd == null) //{ // return HttpNotFound(); //} //return View(MealAd); MealAd existingMealAd = db.MealAds.Find(id); List <MealAd_Schedules> lstMealAd_Schedules = new List <MealAd_Schedules>(); foreach (var allergenic in existingMealAd.MealAd_Schedules) { lstMealAd_Schedules.Add(allergenic); } foreach (var allergenic in lstMealAd_Schedules) { //mealitem.MealItems_AllergenicFoods.Remove(allergenic); db.MealAd_Schedules.Remove(allergenic); db.Entry(allergenic).State = EntityState.Deleted; db.SaveChanges(); } List <MealAds_DeliveryMethods> lstMealAds_DeliveryMethods = new List <MealAds_DeliveryMethods>(); foreach (var allergenic in existingMealAd.MealAds_DeliveryMethods) { lstMealAds_DeliveryMethods.Add(allergenic); } foreach (var allergenic in lstMealAds_DeliveryMethods) { //mealitem.MealItems_AllergenicFoods.Remove(allergenic); db.MealAds_DeliveryMethods.Remove(allergenic); db.Entry(allergenic).State = EntityState.Deleted; db.SaveChanges(); } List <MealAds_PaymentOptions> lstMealAds_PaymentOptions = new List <MealAds_PaymentOptions>(); foreach (var allergenic in existingMealAd.MealAds_PaymentOptions) { lstMealAds_PaymentOptions.Add(allergenic); } foreach (var allergenic in lstMealAds_PaymentOptions) { //mealitem.MealItems_AllergenicFoods.Remove(allergenic); db.MealAds_PaymentOptions.Remove(allergenic); db.Entry(allergenic).State = EntityState.Deleted; db.SaveChanges(); } db.MealAds.Remove(existingMealAd); db.Entry(existingMealAd).State = EntityState.Deleted; db.SaveChanges(); eh.SendEmail("Delete"); return(RedirectToAction("Index", new { userID = WebSecurity.CurrentUserId })); }
private MealAdViewModel PopulateDropDown(MealAdViewModel mealadvm, MealAd mealad, int userid) { 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 void Update(MealAd mt) { throw new NotImplementedException(); }