public ActionResult Create(int id) { Model_UserWorkshopPlanCreate model = new Model_UserWorkshopPlanCreate() { WorkshopID = id }; return(PartialView(model)); }
public ActionResult Create(Model_UserWorkshopPlanCreate model) { if (ModelState.IsValid) { var _User = db.Tbl_User.Where(x => x.User_Guid == model.UserGuid && x.User_IsDelete == false).SingleOrDefault(); if (db.Tbl_UserWorkshopPlan.Where(x => x.UWP_UserID == _User.User_ID && x.UWP_WPID == model.WorkshopID && x.UWP_IsDelete == false).FirstOrDefault() != null) { TempData["TosterState"] = "info"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "کارگاه مورد نظر قبلا خریداری شده است"; return(RedirectToAction("Details", "Workshop", new { area = "Dashboard", id = model.WorkshopID })); } ; var _WorkshopPlan = db.Tbl_WorkshopPlan.Where(x => x.WP_ID == model.WorkshopID).SingleOrDefault(); if (_WorkshopPlan != null) { bool smsResult = true; Tbl_Payment _Payment = Purchase(_User, _WorkshopPlan.WP_Cost, ProductType.Workshop, out bool walletResult, ref smsResult); if (_Payment != null) { db.Tbl_Payment.Add(_Payment); Tbl_Wallet _Wallet = db.Tbl_Wallet.Where(x => x.Wallet_UserID == _Payment.Payment_UserID).SingleOrDefault(); _Wallet.Wallet_Credit = _Payment.Payment_RemaingWallet - _Payment.Payment_Cost; _Wallet.Wallet_ModifiedDate = DateTime.Now; db.Entry(_Wallet).State = EntityState.Modified; Tbl_UserWorkshopPlan _UserWorkshopPlan = new Tbl_UserWorkshopPlan { UWP_Guid = Guid.NewGuid(), UWP_UserID = new Rep_User().Get_UserIDWithGUID(model.UserGuid), UWP_WPID = model.WorkshopID, Tbl_Payment = _Payment, UWP_IsActive = true, UWP_CreationDate = DateTime.Now, UWP_ModifiedDate = DateTime.Now }; db.Tbl_UserWorkshopPlan.Add(_UserWorkshopPlan); _WorkshopPlan.WP_Capacity -= 1; db.Entry(_WorkshopPlan).State = EntityState.Modified; if (Convert.ToBoolean(db.SaveChanges() > 0)) { //if (_WorkshopPlan.WP_Capacity <= 0) //{ // TempData["TosterState"] = "warning"; // TempData["TosterType"] = TosterType.Maseage; // TempData["TosterMassage"] = "ظرفیت کارگاه مورد نظر پر شده است"; // return RedirectToAction("Details", "Workshop", new { area = "Dashboard", id = model.WorkshopID }); //} if (!walletResult && !smsResult) { TempData["TosterState"] = "warning"; TempData["TosterType"] = TosterType.WithTitel; TempData["TosterTitel"] = "خطا در ارسال پیامک"; TempData["TosterMassage"] = "کمبود موجودی کیف پول کاربر"; } else if (!walletResult) { TempData["TosterState"] = "warning"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "کمبود موجودی کیف پول کاربر"; } else if (!smsResult) { TempData["TosterState"] = "warning"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "خطا در ارسال پیامک"; } else { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام شد"; } return(RedirectToAction("Details", "Workshop", new { area = "Dashboard", id = model.WorkshopID })); } TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام نشد"; return(RedirectToAction("Details", "Workshop", new { area = "Dashboard", id = model.WorkshopID })); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام نشد"; return(RedirectToAction("Details", "Workshop", new { area = "Dashboard", id = model.WorkshopID })); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }